diff --git a/package-lock.json b/package-lock.json index a683d4e8..a1bbd800 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@mcschema/core": "^0.12.10", + "@mcschema/core": "^0.12.11", "@mcschema/java-1.15": "^0.2.2", "@mcschema/java-1.16": "^0.6.5", "@mcschema/java-1.17": "^0.2.24", @@ -316,9 +316,9 @@ } }, "node_modules/@mcschema/core": { - "version": "0.12.10", - "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.10.tgz", - "integrity": "sha512-uPP6iiVaml5MUBbcu5tnl3atadAwdQOpXBZdpoDMjLX+7nUUUAjiynHpbwXVeqTgO473j4QI2EQv2NqPH+wCSw==" + "version": "0.12.11", + "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.11.tgz", + "integrity": "sha512-YNB9aUr7szseHfMxL/XJaAObMOZ94sXBmgu+miqdNHUSWgVMKLYBv1LJ2r5p8EY3EtULjq8YXxRxC8NYUJCEig==" }, "node_modules/@mcschema/java-1.15": { "version": "0.2.2", @@ -2913,9 +2913,9 @@ } }, "@mcschema/core": { - "version": "0.12.10", - "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.10.tgz", - "integrity": "sha512-uPP6iiVaml5MUBbcu5tnl3atadAwdQOpXBZdpoDMjLX+7nUUUAjiynHpbwXVeqTgO473j4QI2EQv2NqPH+wCSw==" + "version": "0.12.11", + "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.11.tgz", + "integrity": "sha512-YNB9aUr7szseHfMxL/XJaAObMOZ94sXBmgu+miqdNHUSWgVMKLYBv1LJ2r5p8EY3EtULjq8YXxRxC8NYUJCEig==" }, "@mcschema/java-1.15": { "version": "0.2.2", diff --git a/package.json b/package.json index 1f815197..cab9b26a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "author": "Misode", "license": "MIT", "dependencies": { - "@mcschema/core": "^0.12.10", + "@mcschema/core": "^0.12.11", "@mcschema/java-1.15": "^0.2.2", "@mcschema/java-1.16": "^0.6.5", "@mcschema/java-1.17": "^0.2.24", diff --git a/src/app/Utils.ts b/src/app/Utils.ts index c901b540..ec900265 100644 --- a/src/app/Utils.ts +++ b/src/app/Utils.ts @@ -140,17 +140,3 @@ export function deepEqual(a: any, b: any) { } return a !== a && b !== b } - -export function unwrapLists(value: any): any { - if (Array.isArray(value)) { - return value.map(v => unwrapLists(v.node)) - } else if (typeof value === 'object' && value !== null) { - const res: Record = {} - Object.entries(value).map(([k, v]) => { - res[k] = unwrapLists(v) - }) - return res - } else { - return value - } -} diff --git a/src/app/previews/BiomeSource.ts b/src/app/previews/BiomeSource.ts index c2f010db..9e4eac60 100644 --- a/src/app/previews/BiomeSource.ts +++ b/src/app/previews/BiomeSource.ts @@ -1,8 +1,9 @@ +import { DataModel } from '@mcschema/core' import type { BiomeSource, Climate, NoiseOctaves } from 'deepslate' import { FixedBiome, MultiNoise, NoiseGeneratorSettings, NoiseSampler, NormalNoise, Random } from 'deepslate' import { fetchPreset } from '../DataFetcher' import type { VersionId } from '../Schemas' -import { clamp, deepClone, deepEqual, square, stringToColor, unwrapLists } from '../Utils' +import { clamp, deepClone, deepEqual, square, stringToColor } from '../Utils' type BiomeColors = Record type BiomeSourceOptions = { @@ -90,7 +91,7 @@ async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise< state = options.version === '1.18' ? await OverworldPreset18() : state break } - state = unwrapLists(state) + state = DataModel.unwrapLists(state) if (options.version === '1.18') { return MultiNoise.fromJson(state) } else { diff --git a/src/app/previews/Decorator.ts b/src/app/previews/Decorator.ts index 476f6b22..77a709ee 100644 --- a/src/app/previews/Decorator.ts +++ b/src/app/previews/Decorator.ts @@ -1,6 +1,7 @@ +import { DataModel } from '@mcschema/core' import { PerlinNoise, Random } from 'deepslate' import type { VersionId } from '../Schemas' -import { clamp, stringToColor, unwrapLists } from '../Utils' +import { clamp, stringToColor } from '../Utils' type BlockPos = [number, number, number] type Placement = [BlockPos, number] @@ -49,7 +50,7 @@ export function decorator(state: any, img: ImageData, options: DecoratorOptions) for (let x = 0; x < options.size[0] / 16; x += 1) { for (let z = 0; z < options.size[2] / 16; z += 1) { - getPlacements([x * 16, 0, z * 16], unwrapLists(state), ctx) + getPlacements([x * 16, 0, z * 16], DataModel.unwrapLists(state), ctx) } } diff --git a/src/app/previews/NoiseSettings.ts b/src/app/previews/NoiseSettings.ts index b35d6d65..9fb94522 100644 --- a/src/app/previews/NoiseSettings.ts +++ b/src/app/previews/NoiseSettings.ts @@ -1,8 +1,9 @@ +import { DataModel } from '@mcschema/core' import type { BlockPos, BlockState } from 'deepslate' import { Chunk, ChunkPos, FixedBiome, NoiseChunkGenerator, NoiseGeneratorSettings } from 'deepslate' import type { VersionId } from '../Schemas' import { checkVersion } from '../Schemas' -import { deepClone, deepEqual, unwrapLists } from '../Utils' +import { deepClone, deepEqual } from '../Utils' import { NoiseChunkGenerator as OldNoiseChunkGenerator } from './noise/NoiseChunkGenerator' export type NoiseSettingsOptions = { @@ -70,7 +71,7 @@ export function noiseSettings(state: any, img: ImageData, options: NoiseSettings } function getCached(state: unknown, options: NoiseSettingsOptions) { - const settings = NoiseGeneratorSettings.fromJson(unwrapLists(state)) + const settings = NoiseGeneratorSettings.fromJson(DataModel.unwrapLists(state)) // Temporary fix for slides settings.noise.bottomSlide.target *= 128 settings.noise.topSlide.target *= 128 diff --git a/src/app/schema/renderHtml.tsx b/src/app/schema/renderHtml.tsx index 79b8249e..63aeeabb 100644 --- a/src/app/schema/renderHtml.tsx +++ b/src/app/schema/renderHtml.tsx @@ -65,12 +65,12 @@ const renderHtml: RenderHook = { return [prefix, suffix, body] } const choiceContextPath = config?.choiceContext ? new Path([], [config.choiceContext]) : config?.context ? new Path([], [config.context]) : path - const set = (value: string) => { - const c = choices.find(c => c.type === value) ?? choice + const set = (type: string) => { + const c = choices.find(c => c.type === type) ?? choice const newValue = c.change - ? c.change(value, { wrapLists: true }) - : DataModel.wrapLists(config.choiceContext === 'feature' ? c.node.default()?.config?.feature : c.node.default()) - path.model.set(path, newValue) + ? c.change(DataModel.unwrapLists(value)) + : config.choiceContext === 'feature' ? c.node.default()?.config?.feature : c.node.default() + path.model.set(path, DataModel.wrapLists(newValue)) } const inject =