mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 15:47:08 +00:00
Support 1.18 (experimental) snapshots (#158)
* Half support 1.18-experimental-snapshot-1 * Fetch 1.18 presets and improve rendering of lists * Noise preview with deepslate * Biome preview with deepslate * Generalize canvas logic in one hook * Simplify useCanvas * Use mcschema for 1.18 * Improve noise settings preview controls * Fix build * Update deepslate and improve preview caching * Cleanup, remove old preview code * Couple seed between model and preview * Limit output to improve performance + copy feedback For the vanilla overworld dimension (200K lines), it took 2+ seconds to write the output to the textarea Now capped at 10K chars * Add surface_relative_threshold to decorator preview * Improve fixed list errors
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { DataModel } from '@mcschema/core'
|
||||
import { Path } from '@mcschema/core'
|
||||
import { getCurrentUrl } from 'preact-router'
|
||||
import { useEffect, useErrorBoundary, useState } from 'preact/hooks'
|
||||
import { useEffect, useErrorBoundary, useRef, useState } from 'preact/hooks'
|
||||
import config from '../../config.json'
|
||||
import { Analytics } from '../Analytics'
|
||||
import { Ad, Btn, BtnInput, BtnMenu, ErrorPanel, HasPreview, Octicon, PreviewPanel, SourcePanel, Tree } from '../components'
|
||||
@@ -13,7 +14,7 @@ import { getGenerator } from '../Utils'
|
||||
|
||||
type GeneratorProps = {
|
||||
lang: string,
|
||||
changeTitle: (title: string, versions?: string[]) => unknown,
|
||||
changeTitle: (title: string, versions?: VersionId[]) => unknown,
|
||||
version: VersionId,
|
||||
onChangeVersion: (version: VersionId) => unknown,
|
||||
default?: true,
|
||||
@@ -110,6 +111,13 @@ export function Generator({ lang, changeTitle, version, onChangeVersion }: Gener
|
||||
const loadPreset = (id: string) => {
|
||||
Analytics.generatorEvent('load-preset', id)
|
||||
fetchPreset(version, gen.path ?? gen.id, id).then(preset => {
|
||||
const seed = model?.get(new Path(['generator', 'seed']))
|
||||
if (preset?.generator?.seed !== undefined && seed !== undefined) {
|
||||
preset.generator.seed = seed
|
||||
if (preset.generator.biome_source?.seed !== undefined) {
|
||||
preset.generator.biome_source.seed = seed
|
||||
}
|
||||
}
|
||||
model?.reset(preset, false)
|
||||
})
|
||||
}
|
||||
@@ -140,6 +148,16 @@ export function Generator({ lang, changeTitle, version, onChangeVersion }: Gener
|
||||
setImport(0)
|
||||
}
|
||||
|
||||
const [copyActive, setCopyActive] = useState(false)
|
||||
const copyTimeout = useRef<number | undefined>(undefined)
|
||||
const copySuccess = () => {
|
||||
setCopyActive(true)
|
||||
if (copyTimeout.current !== undefined) clearTimeout(copyTimeout.current)
|
||||
copyTimeout.current = setTimeout(() => {
|
||||
setCopyActive(false)
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
const [previewShown, setPreviewShown] = useState(false)
|
||||
const hasPreview = HasPreview.includes(gen.id)
|
||||
if (previewShown && !hasPreview) setPreviewShown(false)
|
||||
@@ -185,8 +203,8 @@ export function Generator({ lang, changeTitle, version, onChangeVersion }: Gener
|
||||
<div class={`popup-action action-download${sourceShown ? ' shown' : ''}`} onClick={downloadSource}>
|
||||
{Octicon.download}
|
||||
</div>
|
||||
<div class={`popup-action action-copy${sourceShown ? ' shown' : ''}`} onClick={copySource}>
|
||||
{Octicon.clippy}
|
||||
<div class={`popup-action action-copy${sourceShown ? ' shown' : ''}${copyActive ? ' active' : ''}`} onClick={copySource}>
|
||||
{copyActive ? Octicon.check : Octicon.clippy}
|
||||
</div>
|
||||
<div class={'popup-action action-code shown'} onClick={toggleSource}>
|
||||
{sourceShown ? Octicon.chevron_right : Octicon.code}
|
||||
@@ -196,7 +214,7 @@ export function Generator({ lang, changeTitle, version, onChangeVersion }: Gener
|
||||
<PreviewPanel {...{lang, model, version, id: gen.id}} shown={previewShown} onError={setError} />
|
||||
</div>
|
||||
<div class={`popup-source${sourceShown ? ' shown' : ''}`}>
|
||||
<SourcePanel {...{lang, model, blockStates, doCopy, doDownload, doImport}} name={gen.schema ?? 'data'} onError={setError} />
|
||||
<SourcePanel {...{lang, model, blockStates, doCopy, doDownload, doImport}} name={gen.schema ?? 'data'} copySuccess={copySuccess} onError={setError} />
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user