mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-25 08:06:51 +00:00
Add vanilla preset searcher and loader
This commit is contained in:
@@ -59,6 +59,7 @@ export const App = {
|
||||
language: new LocalStorageProperty('language', 'en')
|
||||
.watch(Tracker.dimLanguage),
|
||||
model: new Property<typeof config.models[0] | null>(null),
|
||||
collections: new Property<CollectionRegistry | null>(null),
|
||||
jsonOutput: new Property(''),
|
||||
errorsVisible: new Property(false),
|
||||
treeMinimized: new Property(false),
|
||||
@@ -109,6 +110,7 @@ App.mobilePanel.watchRun((value) => {
|
||||
async function updateSchemas(version: string) {
|
||||
BlockStateRegistry = {}
|
||||
const collections = Versions[version].getCollections()
|
||||
App.collections.set(collections)
|
||||
await fetchData(collections, version)
|
||||
const schemas = Versions[version].getSchemas(collections)
|
||||
config.models
|
||||
|
||||
@@ -7,6 +7,7 @@ const CACHE_FORMAT = 1
|
||||
type VersionConfig = {
|
||||
id: string,
|
||||
mcdata_ref: string,
|
||||
vanilla_datapack_data_ref?: string,
|
||||
vanilla_datapack_summary_ref?: string
|
||||
}
|
||||
|
||||
@@ -136,3 +137,12 @@ const fetchDynamicRegistries = async (target: CollectionRegistry, version: Versi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchPreset = async (version: VersionConfig, registry: string, id: string) => {
|
||||
try {
|
||||
const res = await fetch(`${vanillaDatapackUrl}/${version.vanilla_datapack_data_ref}/data/minecraft/${registry}/${id}.json`)
|
||||
return await res.json()
|
||||
} catch (e) {
|
||||
console.warn(`Error occurred while fetching ${registry} preset ${id}:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export const Octicon = {
|
||||
archive: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.75 2.5a.25.25 0 00-.25.25v1.5c0 .138.112.25.25.25h12.5a.25.25 0 00.25-.25v-1.5a.25.25 0 00-.25-.25H1.75zM0 2.75C0 1.784.784 1 1.75 1h12.5c.966 0 1.75.784 1.75 1.75v1.5A1.75 1.75 0 0114.25 6H1.75A1.75 1.75 0 010 4.25v-1.5zM1.75 7a.75.75 0 01.75.75v5.5c0 .138.112.25.25.25h10.5a.25.25 0 00.25-.25v-5.5a.75.75 0 111.5 0v5.5A1.75 1.75 0 0113.25 15H2.75A1.75 1.75 0 011 13.25v-5.5A.75.75 0 011.75 7zm4.5 1a.75.75 0 000 1.5h3.5a.75.75 0 100-1.5h-3.5z"></path></svg>',
|
||||
arrow_both: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M3.72 3.72a.75.75 0 011.06 1.06L2.56 7h10.88l-2.22-2.22a.75.75 0 011.06-1.06l3.5 3.5a.75.75 0 010 1.06l-3.5 3.5a.75.75 0 11-1.06-1.06l2.22-2.22H2.56l2.22 2.22a.75.75 0 11-1.06 1.06l-3.5-3.5a.75.75 0 010-1.06l3.5-3.5z"></path></svg>',
|
||||
arrow_left: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"></path></svg>',
|
||||
arrow_right: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8.22 2.97a.75.75 0 011.06 0l4.25 4.25a.75.75 0 010 1.06l-4.25 4.25a.75.75 0 01-1.06-1.06l2.97-2.97H3.75a.75.75 0 010-1.5h7.44L8.22 4.03a.75.75 0 010-1.06z"></path></svg>',
|
||||
@@ -25,6 +26,7 @@ export const Octicon = {
|
||||
play: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM8 0a8 8 0 100 16A8 8 0 008 0zM6.379 5.227A.25.25 0 006 5.442v5.117a.25.25 0 00.379.214l4.264-2.559a.25.25 0 000-.428L6.379 5.227z"></path></svg>',
|
||||
plus: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8 2a.75.75 0 01.75.75v4.5h4.5a.75.75 0 010 1.5h-4.5v4.5a.75.75 0 01-1.5 0v-4.5h-4.5a.75.75 0 010-1.5h4.5v-4.5A.75.75 0 018 2z"></path></svg>',
|
||||
plus_circle: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM8 0a8 8 0 100 16A8 8 0 008 0zm.75 4.75a.75.75 0 00-1.5 0v2.5h-2.5a.75.75 0 000 1.5h2.5v2.5a.75.75 0 001.5 0v-2.5h2.5a.75.75 0 000-1.5h-2.5v-2.5z"></path></svg>',
|
||||
search: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"></path></svg>',
|
||||
square: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4 5.75C4 4.784 4.784 4 5.75 4h4.5c.966 0 1.75.784 1.75 1.75v4.5A1.75 1.75 0 0110.25 12h-4.5A1.75 1.75 0 014 10.25v-4.5zm1.75-.25a.25.25 0 00-.25.25v4.5c0 .138.112.25.25.25h4.5a.25.25 0 00.25-.25v-4.5a.25.25 0 00-.25-.25h-4.5z"></path></svg>',
|
||||
square_fill: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M5.75 4A1.75 1.75 0 004 5.75v4.5c0 .966.784 1.75 1.75 1.75h4.5A1.75 1.75 0 0012 10.25v-4.5A1.75 1.75 0 0010.25 4h-4.5z"></path></svg>',
|
||||
sun: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8 10.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zM8 12a4 4 0 100-8 4 4 0 000 8zM8 0a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0V.75A.75.75 0 018 0zm0 13a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0v-1.5A.75.75 0 018 13zM2.343 2.343a.75.75 0 011.061 0l1.06 1.061a.75.75 0 01-1.06 1.06l-1.06-1.06a.75.75 0 010-1.06zm9.193 9.193a.75.75 0 011.06 0l1.061 1.06a.75.75 0 01-1.06 1.061l-1.061-1.06a.75.75 0 010-1.061zM16 8a.75.75 0 01-.75.75h-1.5a.75.75 0 010-1.5h1.5A.75.75 0 0116 8zM3 8a.75.75 0 01-.75.75H.75a.75.75 0 010-1.5h1.5A.75.75 0 013 8zm10.657-5.657a.75.75 0 010 1.061l-1.061 1.06a.75.75 0 11-1.06-1.06l1.06-1.06a.75.75 0 011.06 0zm-9.193 9.193a.75.75 0 010 1.06l-1.06 1.061a.75.75 0 11-1.061-1.06l1.06-1.061a.75.75 0 011.061 0z"></path></svg>',
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Octicon } from '../Octicon';
|
||||
import { renderHtml } from '../../hooks/renderHtml';
|
||||
import config from '../../../config.json'
|
||||
import { BiomeNoisePreview } from '../../preview/BiomeNoisePreview';
|
||||
import { fetchPreset } from '../../DataFetcher'
|
||||
|
||||
export const TreePanel = (view: View, model: DataModel) => {
|
||||
const getContent = () => {
|
||||
@@ -48,6 +49,31 @@ export const TreePanel = (view: View, model: DataModel) => {
|
||||
view.mount(el, getContent(), false)
|
||||
}, 'tree-panel')
|
||||
})
|
||||
const m = App.model.get()
|
||||
const registry = (m?.category ? m?.category + '/' : '') + m?.schema
|
||||
let presetList: Element
|
||||
const presetListId = view.register(el => presetList = el)
|
||||
const getPresets = (query?: string) => {
|
||||
const terms = (query ?? '').trim().split(' ')
|
||||
const results = (App.collections.get()?.get(registry) ?? [])
|
||||
.map(r => r.slice(10))
|
||||
.filter(e => terms.every(t => e.includes(t)))
|
||||
return results.map(r => `<div class="btn" data-id="${view.onClick(async () => {
|
||||
App.schemasLoaded.set(false)
|
||||
const preset = await fetchPreset(config.versions.find(v => v.id === App.version.get())!, m?.path!, r)
|
||||
model.reset(preset)
|
||||
App.schemasLoaded.set(true)
|
||||
})}">${r}</div>`).join('')
|
||||
}
|
||||
const presetControl = view.register(el => {
|
||||
App.version.watchRun(v => {
|
||||
const enabled = (m?.path && checkVersion(v, '1.16'))
|
||||
el.classList.toggle('disabled', !enabled || (App.collections.get()?.get(registry) ?? []).length === 0)
|
||||
if (enabled) {
|
||||
view.mount(presetList, getPresets(), false)
|
||||
}
|
||||
}, 'tree-panel')
|
||||
})
|
||||
return `<div class="panel tree-panel">
|
||||
<div class="panel-controls">
|
||||
<div class="btn" data-id="${view.onClick(() => {
|
||||
@@ -55,6 +81,22 @@ export const TreePanel = (view: View, model: DataModel) => {
|
||||
})}">
|
||||
${Octicon.fold}<span data-i18n="minimize"></span>
|
||||
</div>
|
||||
<div class="panel-menu no-relative" data-id="${presetControl}">
|
||||
<div class="btn" data-id="${view.onClick(el => {
|
||||
toggleMenu(el)
|
||||
el.parentElement?.querySelector('input')?.select()
|
||||
})}">
|
||||
${Octicon.archive}<span data-i18n="presets"></span>
|
||||
</div>
|
||||
<div class="panel-menu-list btn-group">
|
||||
<div class="btn input large-input">
|
||||
${Octicon.search}<input data-id="${view.on('keyup', el => {
|
||||
view.mount(presetList, getPresets((el as HTMLInputElement).value), false)
|
||||
})}">
|
||||
</div>
|
||||
<div class="result-list" data-id="${presetListId}"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-menu">
|
||||
<div class="btn" data-id="${view.onClick(toggleMenu)}">
|
||||
${Octicon.tag}
|
||||
|
||||
Reference in New Issue
Block a user