mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-27 08:48:46 +00:00
Switch to vite and preact
This commit is contained in:
70
src/app/components/PreviewPanel.tsx
Normal file
70
src/app/components/PreviewPanel.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
import type { DataModel } from '@mcschema/core'
|
||||
import { Path } from '@mcschema/core'
|
||||
import type { FunctionalComponent } from 'preact'
|
||||
import { useState } from 'preact/hooks'
|
||||
import { useModel } from '../hooks'
|
||||
import type { VersionId } from '../Schemas'
|
||||
import { BiomeSourcePreview, DecoratorPreview, NoiseSettingsPreview } from './previews'
|
||||
|
||||
export const HasPreview = ['dimension', 'worldgen/noise-settings', 'worldgen/feature']
|
||||
|
||||
export const Previews: {
|
||||
id: string,
|
||||
generator: string,
|
||||
path: Path,
|
||||
predicate: (model: DataModel) => boolean,
|
||||
preview: FunctionalComponent<{
|
||||
lang: string,
|
||||
model: DataModel,
|
||||
data: any,
|
||||
version: VersionId,
|
||||
shown: boolean,
|
||||
}>,
|
||||
}[] = [
|
||||
{
|
||||
id: 'biome-noise',
|
||||
generator: 'dimension',
|
||||
path: new Path(['generator', 'biome_source']),
|
||||
predicate: model => model.get(new Path(['generator', 'type'])).endsWith('noise'),
|
||||
preview: BiomeSourcePreview,
|
||||
},
|
||||
{
|
||||
id: 'noise-settings',
|
||||
generator: 'worldgen/noise-settings',
|
||||
path: new Path(['noise']),
|
||||
predicate: () => true,
|
||||
preview: NoiseSettingsPreview,
|
||||
},
|
||||
{
|
||||
id: 'decorator',
|
||||
generator: 'worldgen/feature',
|
||||
path: new Path([]),
|
||||
predicate: () => true,
|
||||
preview: DecoratorPreview,
|
||||
},
|
||||
]
|
||||
|
||||
type PreviewProps = {
|
||||
lang: string,
|
||||
model: DataModel | null,
|
||||
version: VersionId,
|
||||
id: string,
|
||||
shown: boolean,
|
||||
}
|
||||
export function PreviewPanel({ lang, model, version, id, shown }: PreviewProps) {
|
||||
const [, setCount] = useState(0)
|
||||
|
||||
useModel(model, () => {
|
||||
setCount(count => count + 1)
|
||||
})
|
||||
|
||||
return <>
|
||||
{Previews.filter(p => p.generator === id).map(p => {
|
||||
const data = model?.get(p.path)
|
||||
if (!model || data === undefined || !p.predicate(model)) {
|
||||
return <></>
|
||||
}
|
||||
return p.preview({ lang, model: model!, data, version, shown })
|
||||
})}
|
||||
</>
|
||||
}
|
||||
Reference in New Issue
Block a user