Fix #176 switching between choices

This commit is contained in:
Misode
2021-10-06 00:02:06 +02:00
parent d883459dba
commit 0ff7de3aea
7 changed files with 22 additions and 33 deletions

14
package-lock.json generated
View File

@@ -9,7 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@mcschema/core": "^0.12.10", "@mcschema/core": "^0.12.11",
"@mcschema/java-1.15": "^0.2.2", "@mcschema/java-1.15": "^0.2.2",
"@mcschema/java-1.16": "^0.6.5", "@mcschema/java-1.16": "^0.6.5",
"@mcschema/java-1.17": "^0.2.24", "@mcschema/java-1.17": "^0.2.24",
@@ -316,9 +316,9 @@
} }
}, },
"node_modules/@mcschema/core": { "node_modules/@mcschema/core": {
"version": "0.12.10", "version": "0.12.11",
"resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.10.tgz", "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.11.tgz",
"integrity": "sha512-uPP6iiVaml5MUBbcu5tnl3atadAwdQOpXBZdpoDMjLX+7nUUUAjiynHpbwXVeqTgO473j4QI2EQv2NqPH+wCSw==" "integrity": "sha512-YNB9aUr7szseHfMxL/XJaAObMOZ94sXBmgu+miqdNHUSWgVMKLYBv1LJ2r5p8EY3EtULjq8YXxRxC8NYUJCEig=="
}, },
"node_modules/@mcschema/java-1.15": { "node_modules/@mcschema/java-1.15": {
"version": "0.2.2", "version": "0.2.2",
@@ -2913,9 +2913,9 @@
} }
}, },
"@mcschema/core": { "@mcschema/core": {
"version": "0.12.10", "version": "0.12.11",
"resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.10.tgz", "resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.12.11.tgz",
"integrity": "sha512-uPP6iiVaml5MUBbcu5tnl3atadAwdQOpXBZdpoDMjLX+7nUUUAjiynHpbwXVeqTgO473j4QI2EQv2NqPH+wCSw==" "integrity": "sha512-YNB9aUr7szseHfMxL/XJaAObMOZ94sXBmgu+miqdNHUSWgVMKLYBv1LJ2r5p8EY3EtULjq8YXxRxC8NYUJCEig=="
}, },
"@mcschema/java-1.15": { "@mcschema/java-1.15": {
"version": "0.2.2", "version": "0.2.2",

View File

@@ -14,7 +14,7 @@
"author": "Misode", "author": "Misode",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@mcschema/core": "^0.12.10", "@mcschema/core": "^0.12.11",
"@mcschema/java-1.15": "^0.2.2", "@mcschema/java-1.15": "^0.2.2",
"@mcschema/java-1.16": "^0.6.5", "@mcschema/java-1.16": "^0.6.5",
"@mcschema/java-1.17": "^0.2.24", "@mcschema/java-1.17": "^0.2.24",

View File

@@ -140,17 +140,3 @@ export function deepEqual(a: any, b: any) {
} }
return a !== a && b !== b 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<string, any> = {}
Object.entries(value).map(([k, v]) => {
res[k] = unwrapLists(v)
})
return res
} else {
return value
}
}

View File

@@ -1,8 +1,9 @@
import { DataModel } from '@mcschema/core'
import type { BiomeSource, Climate, NoiseOctaves } from 'deepslate' import type { BiomeSource, Climate, NoiseOctaves } from 'deepslate'
import { FixedBiome, MultiNoise, NoiseGeneratorSettings, NoiseSampler, NormalNoise, Random } from 'deepslate' import { FixedBiome, MultiNoise, NoiseGeneratorSettings, NoiseSampler, NormalNoise, Random } from 'deepslate'
import { fetchPreset } from '../DataFetcher' import { fetchPreset } from '../DataFetcher'
import type { VersionId } from '../Schemas' 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<string, number[]> type BiomeColors = Record<string, number[]>
type BiomeSourceOptions = { type BiomeSourceOptions = {
@@ -90,7 +91,7 @@ async function getBiomeSource(state: any, options: BiomeSourceOptions): Promise<
state = options.version === '1.18' ? await OverworldPreset18() : state state = options.version === '1.18' ? await OverworldPreset18() : state
break break
} }
state = unwrapLists(state) state = DataModel.unwrapLists(state)
if (options.version === '1.18') { if (options.version === '1.18') {
return MultiNoise.fromJson(state) return MultiNoise.fromJson(state)
} else { } else {

View File

@@ -1,6 +1,7 @@
import { DataModel } from '@mcschema/core'
import { PerlinNoise, Random } from 'deepslate' import { PerlinNoise, Random } from 'deepslate'
import type { VersionId } from '../Schemas' import type { VersionId } from '../Schemas'
import { clamp, stringToColor, unwrapLists } from '../Utils' import { clamp, stringToColor } from '../Utils'
type BlockPos = [number, number, number] type BlockPos = [number, number, number]
type Placement = [BlockPos, 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 x = 0; x < options.size[0] / 16; x += 1) {
for (let z = 0; z < options.size[2] / 16; z += 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)
} }
} }

View File

@@ -1,8 +1,9 @@
import { DataModel } from '@mcschema/core'
import type { BlockPos, BlockState } from 'deepslate' import type { BlockPos, BlockState } from 'deepslate'
import { Chunk, ChunkPos, FixedBiome, NoiseChunkGenerator, NoiseGeneratorSettings } from 'deepslate' import { Chunk, ChunkPos, FixedBiome, NoiseChunkGenerator, NoiseGeneratorSettings } from 'deepslate'
import type { VersionId } from '../Schemas' import type { VersionId } from '../Schemas'
import { checkVersion } from '../Schemas' import { checkVersion } from '../Schemas'
import { deepClone, deepEqual, unwrapLists } from '../Utils' import { deepClone, deepEqual } from '../Utils'
import { NoiseChunkGenerator as OldNoiseChunkGenerator } from './noise/NoiseChunkGenerator' import { NoiseChunkGenerator as OldNoiseChunkGenerator } from './noise/NoiseChunkGenerator'
export type NoiseSettingsOptions = { export type NoiseSettingsOptions = {
@@ -70,7 +71,7 @@ export function noiseSettings(state: any, img: ImageData, options: NoiseSettings
} }
function getCached(state: unknown, options: NoiseSettingsOptions) { function getCached(state: unknown, options: NoiseSettingsOptions) {
const settings = NoiseGeneratorSettings.fromJson(unwrapLists(state)) const settings = NoiseGeneratorSettings.fromJson(DataModel.unwrapLists(state))
// Temporary fix for slides // Temporary fix for slides
settings.noise.bottomSlide.target *= 128 settings.noise.bottomSlide.target *= 128
settings.noise.topSlide.target *= 128 settings.noise.topSlide.target *= 128

View File

@@ -65,12 +65,12 @@ const renderHtml: RenderHook = {
return [prefix, suffix, body] return [prefix, suffix, body]
} }
const choiceContextPath = config?.choiceContext ? new Path([], [config.choiceContext]) : config?.context ? new Path([], [config.context]) : path const choiceContextPath = config?.choiceContext ? new Path([], [config.choiceContext]) : config?.context ? new Path([], [config.context]) : path
const set = (value: string) => { const set = (type: string) => {
const c = choices.find(c => c.type === value) ?? choice const c = choices.find(c => c.type === type) ?? choice
const newValue = c.change const newValue = c.change
? c.change(value, { wrapLists: true }) ? c.change(DataModel.unwrapLists(value))
: DataModel.wrapLists(config.choiceContext === 'feature' ? c.node.default()?.config?.feature : c.node.default()) : config.choiceContext === 'feature' ? c.node.default()?.config?.feature : c.node.default()
path.model.set(path, newValue) path.model.set(path, DataModel.wrapLists(newValue))
} }
const inject = <select value={choice.type} onChange={(e) => set((e.target as HTMLSelectElement).value)}> const inject = <select value={choice.type} onChange={(e) => set((e.target as HTMLSelectElement).value)}>
{choices.map(c => <option value={c.type}> {choices.map(c => <option value={c.type}>