mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 15:47:08 +00:00
Fix #418 noise settings preview freezes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import * as deepslate19 from 'deepslate/worldgen'
|
||||
import { clamp, computeIfAbsent, computeIfAbsentAsync, deepClone, deepEqual, isObject, square } from '../../Utils.js'
|
||||
import type { VersionId } from '../../services/index.js'
|
||||
import { checkVersion, fetchAllPresets, fetchPreset } from '../../services/index.js'
|
||||
import { clamp, computeIfAbsent, computeIfAbsentAsync, deepClone, deepEqual, isObject, square } from '../../Utils.js'
|
||||
|
||||
export type ProjectData = Record<string, Record<string, unknown>>
|
||||
|
||||
@@ -99,6 +99,9 @@ export class Deepslate {
|
||||
const newCacheState = [settings, `${seed}`, biomeState]
|
||||
if (!deepEqual(this.cacheState, newCacheState)) {
|
||||
const noiseSettings = this.createNoiseSettings(settings)
|
||||
if (noiseSettings.noise.xzSize === 0 || noiseSettings.noise.ySize === 0) {
|
||||
throw new Error('size_horizontal or size_vertical cannot be zero')
|
||||
}
|
||||
const biomeSource = await this.createBiomeSource(noiseSettings, biomeState, seed)
|
||||
const chunkGenerator = this.isVersion('1.19')
|
||||
? new this.d.NoiseChunkGenerator(biomeSource, noiseSettings)
|
||||
|
||||
@@ -3,18 +3,18 @@ import { clampedMap } from 'deepslate'
|
||||
import type { mat3 } from 'gl-matrix'
|
||||
import { vec2 } from 'gl-matrix'
|
||||
import { useCallback, useMemo, useRef, useState } from 'preact/hooks'
|
||||
import { Store } from '../../Store.js'
|
||||
import { iterateWorld2D, randomSeed } from '../../Utils.js'
|
||||
import { getProjectData, useLocale, useProject } from '../../contexts/index.js'
|
||||
import { useAsync } from '../../hooks/index.js'
|
||||
import { CachedCollections } from '../../services/index.js'
|
||||
import { Store } from '../../Store.js'
|
||||
import { iterateWorld2D, randomSeed } from '../../Utils.js'
|
||||
import { Btn, BtnInput, BtnMenu } from '../index.js'
|
||||
import { Btn, BtnInput, BtnMenu, ErrorPanel } from '../index.js'
|
||||
import type { ColormapType } from './Colormap.js'
|
||||
import { getColormap } from './Colormap.js'
|
||||
import { ColormapSelector } from './ColormapSelector.jsx'
|
||||
import { DEEPSLATE } from './Deepslate.js'
|
||||
import type { PreviewProps } from './index.js'
|
||||
import { InteractiveCanvas2D } from './InteractiveCanvas2D.jsx'
|
||||
import type { PreviewProps } from './index.js'
|
||||
|
||||
export const NoiseSettingsPreview = ({ data, shown, version }: PreviewProps) => {
|
||||
const { locale } = useLocale()
|
||||
@@ -24,7 +24,7 @@ export const NoiseSettingsPreview = ({ data, shown, version }: PreviewProps) =>
|
||||
const [layer, setLayer] = useState('terrain')
|
||||
const state = JSON.stringify(data)
|
||||
|
||||
const { value } = useAsync(async () => {
|
||||
const { value, error } = useAsync(async () => {
|
||||
const unwrapped = DataModel.unwrapLists(data)
|
||||
await DEEPSLATE.loadVersion(version, getProjectData(project))
|
||||
const biomeSource = { type: 'fixed', biome }
|
||||
@@ -88,6 +88,10 @@ export const NoiseSettingsPreview = ({ data, shown, version }: PreviewProps) =>
|
||||
|
||||
const allBiomes = useMemo(() => CachedCollections?.get('worldgen/biome') ?? [], [version])
|
||||
|
||||
if (error) {
|
||||
return <ErrorPanel error={error} prefix="Failed to initialize preview: " />
|
||||
}
|
||||
|
||||
return <>
|
||||
<div class="controls preview-controls">
|
||||
{focused.map(s => <Btn label={s} class="no-pointer" /> )}
|
||||
|
||||
Reference in New Issue
Block a user