diff --git a/src/app/App.ts b/src/app/App.ts index 06fa3b70..8414a696 100644 --- a/src/app/App.ts +++ b/src/app/App.ts @@ -59,6 +59,7 @@ export const App = { language: new LocalStorageProperty('language', 'en') .watch(Tracker.dimLanguage), model: new Property(null), + collections: new Property(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 diff --git a/src/app/DataFetcher.ts b/src/app/DataFetcher.ts index ad8f4a4a..5d73231c 100644 --- a/src/app/DataFetcher.ts +++ b/src/app/DataFetcher.ts @@ -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) + } +} diff --git a/src/app/components/Octicon.ts b/src/app/components/Octicon.ts index 8100f9e3..e296fe38 100644 --- a/src/app/components/Octicon.ts +++ b/src/app/components/Octicon.ts @@ -1,4 +1,5 @@ export const Octicon = { + archive: '', arrow_both: '', arrow_left: '', arrow_right: '', @@ -25,6 +26,7 @@ export const Octicon = { play: '', plus: '', plus_circle: '', + search: '', square: '', square_fill: '', sun: '', diff --git a/src/app/components/panels/TreePanel.ts b/src/app/components/panels/TreePanel.ts index e01315d5..b80dd648 100644 --- a/src/app/components/panels/TreePanel.ts +++ b/src/app/components/panels/TreePanel.ts @@ -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 => `
${r}
`).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 `
${Octicon.fold}
+
+
+ ${Octicon.archive} +
+
+
+ ${Octicon.search} +
+
+
+
${Octicon.tag} diff --git a/src/config.json b/src/config.json index 383f6905..20c8061f 100644 --- a/src/config.json +++ b/src/config.json @@ -49,11 +49,13 @@ { "id": "1.16", "mcdata_ref": "1.16.4", + "vanilla_datapack_data_ref": "1.16.4-data", "vanilla_datapack_summary_ref": "1.16.4-summary" }, { "id": "1.17", "mcdata_ref": "master", + "vanilla_datapack_data_ref": "data", "vanilla_datapack_summary_ref": "summary" } ], @@ -61,33 +63,39 @@ { "id": "loot-table", "name": "Loot Table", + "path": "loot_tables", "schema": "loot_table" }, { "id": "predicate", "name": "Predicate", + "path": "predicates", "schema": "predicate" }, { "id": "item-modifier", "name": "Item Modifier", + "path": "item_modifiers", "schema": "item_modifier", "minVersion": "1.17" }, { "id": "advancement", "name": "Advancement", + "path": "advancements", "schema": "advancement" }, { "id": "dimension", "name": "Dimension", + "path": "dimension", "schema": "dimension", "minVersion": "1.16" }, { "id": "dimension-type", "name": "Dimension Type", + "path": "dimension_type", "schema": "dimension_type", "minVersion": "1.16" }, @@ -106,6 +114,7 @@ { "id": "worldgen/biome", "name": "Biome", + "path": "worldgen/biome", "category": "worldgen", "schema": "biome", "minVersion": "1.16" @@ -113,6 +122,7 @@ { "id": "worldgen/carver", "name": "Carver", + "path": "worldgen/configured_carver", "category": "worldgen", "schema": "configured_carver", "minVersion": "1.16" @@ -120,6 +130,7 @@ { "id": "worldgen/feature", "name": "Feature", + "path": "worldgen/configured_feature", "category": "worldgen", "schema": "configured_feature", "minVersion": "1.16" @@ -127,6 +138,7 @@ { "id": "worldgen/noise-settings", "name": "Noise Settings", + "path": "worldgen/noise_settings", "category": "worldgen", "schema": "noise_settings", "minVersion": "1.16" @@ -134,6 +146,7 @@ { "id": "worldgen/structure-feature", "name": "Structure Feature", + "path": "worldgen/configured_structure_feature", "category": "worldgen", "schema": "configured_structure_feature", "minVersion": "1.16" @@ -141,6 +154,7 @@ { "id": "worldgen/surface-builder", "name": "Surface Builder", + "path": "worldgen/configured_surface_builder", "category": "worldgen", "schema": "configured_surface_builder", "minVersion": "1.16" @@ -148,6 +162,7 @@ { "id": "worldgen/processor-list", "name": "Processor List", + "path": "worldgen/processor_list", "category": "worldgen", "schema": "processor_list", "minVersion": "1.16" @@ -155,6 +170,7 @@ { "id": "worldgen/template-pool", "name": "Template Pool", + "path": "worldgen/template_pool", "category": "worldgen", "schema": "template_pool", "minVersion": "1.16" diff --git a/src/locales/en.json b/src/locales/en.json index 0d7cca55..2401c3d8 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -20,6 +20,7 @@ "title.generator": "%0% Generator", "title.home": "Data Pack Generators", "title.suffix": "%0% Minecraft 1.15, 1.16, 1.17", + "presets": "Presets", "preview": "Visualize", "preview.show_density": "Show Density", "preview.scale": "Scale", diff --git a/src/styles/global.css b/src/styles/global.css index d2199739..e7575b7f 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -184,7 +184,7 @@ nav > .toggle span { .tree { display: flow-root; - padding: 16px 16px 50vh; + padding: 44px 16px 50vh; height: 100%; overflow: auto; } @@ -231,7 +231,7 @@ nav > .toggle span { margin-right: 5px; } -.panel-menu { +.panel-menu:not(.no-relative) { position: relative; } @@ -336,6 +336,7 @@ nav > .toggle span { border-bottom-left-radius: 0px; } +.panel-menu .result-list .btn:first-child, .btn-group .btn:not(:first-child) { border-top-right-radius: 0px; border-top-left-radius: 0px; @@ -356,11 +357,37 @@ nav > .toggle span { width: 100px; } +.btn.btn.large-input { + padding: 5px; + padding-left: 11px; +} + +.btn.large-input input { + width: 100%; + height: 100%; + margin-right: 0; +} + .btn a { color: var(--btn-text); text-decoration: none; } +.panel-menu .result-list { + display: block; + width: 380px; + height: unset; + overflow-y: auto; + overflow-x: hidden; + + max-height: 240px; +} + +.panel-menu.disabled { + display: none; + margin-right: 0; +} + .errors { position: fixed; display: flex; @@ -588,10 +615,6 @@ nav > .toggle span { height: calc(100vh - 98px); } - .tree { - padding-top: 44px; - } - .tree-panel + .gutter { display: none; }