From 44b97e357f2d45e908351d8156de72f87bd44aac Mon Sep 17 00:00:00 2001 From: Misode Date: Fri, 10 May 2024 23:15:41 +0200 Subject: [PATCH] 24w19a --- package-lock.json | 28 +++++++++---------- package.json | 4 +-- src/app/Utils.ts | 12 ++++++++ .../components/generator/ProjectCreation.tsx | 2 +- src/app/components/generator/ProjectPanel.tsx | 20 ++++++------- .../components/generator/SchemaGenerator.tsx | 6 ++-- src/app/contexts/Project.tsx | 16 ++++++----- src/config.json | 12 ++++---- 8 files changed, 57 insertions(+), 43 deletions(-) diff --git a/package-lock.json b/package-lock.json index 956ecc513..3464ca415 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,8 +22,8 @@ "@mcschema/java-1.20": "^0.0.20", "@mcschema/java-1.20.2": "^0.0.9", "@mcschema/java-1.20.3": "^0.0.10", - "@mcschema/java-1.20.5": "^0.0.28", - "@mcschema/java-1.21": "^0.0.9", + "@mcschema/java-1.20.5": "^0.0.29", + "@mcschema/java-1.21": "^0.0.10", "@mcschema/locales": "^0.1.98", "@zip.js/zip.js": "^2.4.5", "brace": "^0.11.1", @@ -669,17 +669,17 @@ } }, "node_modules/@mcschema/java-1.20.5": { - "version": "0.0.28", - "resolved": "https://registry.npmjs.org/@mcschema/java-1.20.5/-/java-1.20.5-0.0.28.tgz", - "integrity": "sha512-kVJZAW36y4DYDkkqCe6pqDiZdaysD5Z5C/Oa9+zh7Q+xJSd/ESGswVqB5ZcVDx+w6Uf0QoXXpNRrM2KABGTUhw==", + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@mcschema/java-1.20.5/-/java-1.20.5-0.0.29.tgz", + "integrity": "sha512-EoxVq41MDZFVYe7rqvSJiZftzYrLYYtGmz7fmeszAnqZafSyB9ckTGZCYBG6nZqRPV1u8yY5WAzHXCdcwCA9aw==", "dependencies": { "@mcschema/core": "^0.13.0" } }, "node_modules/@mcschema/java-1.21": { - "version": "0.0.9", - "resolved": "https://registry.npmjs.org/@mcschema/java-1.21/-/java-1.21-0.0.9.tgz", - "integrity": "sha512-uG7N5+4zNZFbI/BpHIDUB2inzMMxOSBw2NJdUCbo7sRzcI8VE8+z9uJSgLcojnHqLuHggSLPJ6orbAT43mqsiA==", + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/@mcschema/java-1.21/-/java-1.21-0.0.10.tgz", + "integrity": "sha512-iPnAMkvD5BujJ13mXoxFMka4F+5aRpVyc56wgK8/R3erhVKIyiRjIuDCVhrk15tJKZlBnLsZHm8zVEpSvdAklA==", "dependencies": { "@mcschema/core": "^0.13.0" } @@ -4786,17 +4786,17 @@ } }, "@mcschema/java-1.20.5": { - "version": "0.0.28", - "resolved": "https://registry.npmjs.org/@mcschema/java-1.20.5/-/java-1.20.5-0.0.28.tgz", - "integrity": "sha512-kVJZAW36y4DYDkkqCe6pqDiZdaysD5Z5C/Oa9+zh7Q+xJSd/ESGswVqB5ZcVDx+w6Uf0QoXXpNRrM2KABGTUhw==", + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@mcschema/java-1.20.5/-/java-1.20.5-0.0.29.tgz", + "integrity": "sha512-EoxVq41MDZFVYe7rqvSJiZftzYrLYYtGmz7fmeszAnqZafSyB9ckTGZCYBG6nZqRPV1u8yY5WAzHXCdcwCA9aw==", "requires": { "@mcschema/core": "^0.13.0" } }, "@mcschema/java-1.21": { - "version": "0.0.9", - "resolved": "https://registry.npmjs.org/@mcschema/java-1.21/-/java-1.21-0.0.9.tgz", - "integrity": "sha512-uG7N5+4zNZFbI/BpHIDUB2inzMMxOSBw2NJdUCbo7sRzcI8VE8+z9uJSgLcojnHqLuHggSLPJ6orbAT43mqsiA==", + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/@mcschema/java-1.21/-/java-1.21-0.0.10.tgz", + "integrity": "sha512-iPnAMkvD5BujJ13mXoxFMka4F+5aRpVyc56wgK8/R3erhVKIyiRjIuDCVhrk15tJKZlBnLsZHm8zVEpSvdAklA==", "requires": { "@mcschema/core": "^0.13.0" } diff --git a/package.json b/package.json index 3932f3dab..2e1139676 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,8 @@ "@mcschema/java-1.20": "^0.0.20", "@mcschema/java-1.20.2": "^0.0.9", "@mcschema/java-1.20.3": "^0.0.10", - "@mcschema/java-1.20.5": "^0.0.28", - "@mcschema/java-1.21": "^0.0.9", + "@mcschema/java-1.20.5": "^0.0.29", + "@mcschema/java-1.21": "^0.0.10", "@mcschema/locales": "^0.1.98", "@zip.js/zip.js": "^2.4.5", "brace": "^0.11.1", diff --git a/src/app/Utils.ts b/src/app/Utils.ts index 089b70392..1a5ae9ad2 100644 --- a/src/app/Utils.ts +++ b/src/app/Utils.ts @@ -8,7 +8,10 @@ import { quat, vec2 } from 'gl-matrix' import yaml from 'js-yaml' import { route } from 'preact-router' import rfdc from 'rfdc' +import type { ConfigGenerator } from './Config.js' import config from './Config.js' +import type { VersionId } from './services/index.js' +import { checkVersion } from './services/index.js' export function isPromise(obj: any): obj is Promise { return typeof (obj as any)?.then === 'function' @@ -581,3 +584,12 @@ export function parseGitPatch(patch: string) { } return result } + +const legacyTags = new Set(['tag/item', 'tag/block', 'tag/fluid', 'tag/entity_type', 'tag/game_event']) +export function genPath(gen: ConfigGenerator, version: VersionId) { + const path = gen.path ?? gen.id + if (!checkVersion(version, '1.21') && legacyTags.has(gen.id)) { + return path + 's' + } + return path +} diff --git a/src/app/components/generator/ProjectCreation.tsx b/src/app/components/generator/ProjectCreation.tsx index 5434e5bf4..6c28f6828 100644 --- a/src/app/components/generator/ProjectCreation.tsx +++ b/src/app/components/generator/ProjectCreation.tsx @@ -45,7 +45,7 @@ export function ProjectCreation({ onClose }: Props) { readZip(file).then(async (entries) => { const project: Partial = { files: [] } await Promise.all(entries.map(async (entry) => { - const file = disectFilePath(entry[0]) + const file = disectFilePath(entry[0], version) if (file) { try { const data = await parseSource(entry[1], 'json') diff --git a/src/app/components/generator/ProjectPanel.tsx b/src/app/components/generator/ProjectPanel.tsx index 317a6637f..55f8a00df 100644 --- a/src/app/components/generator/ProjectPanel.tsx +++ b/src/app/components/generator/ProjectPanel.tsx @@ -2,12 +2,12 @@ import type { DataModel } from '@mcschema/core' import { useCallback, useMemo, useRef, useState } from 'preact/hooks' import { Analytics } from '../../Analytics.js' import config from '../../Config.js' -import { Store } from '../../Store.js' -import { writeZip } from '../../Utils.js' -import { DRAFT_PROJECT, disectFilePath, getFilePath, useLocale, useProject, useVersion } from '../../contexts/index.js' +import { disectFilePath, DRAFT_PROJECT, getFilePath, useLocale, useProject, useVersion } from '../../contexts/index.js' import { useFocus } from '../../hooks/useFocus.js' import type { VersionId } from '../../services/index.js' import { stringifySource } from '../../services/index.js' +import { Store } from '../../Store.js' +import { writeZip } from '../../Utils.js' import { Btn } from '../Btn.js' import { BtnMenu } from '../BtnMenu.js' import { Octicon } from '../Octicon.jsx' @@ -44,20 +44,20 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) { id: id.replaceAll('\u2215', '/'), } } - return disectFilePath(entry) - }, [treeViewMode]) + return disectFilePath(entry, version) + }, [treeViewMode, version]) const entries = useMemo(() => project.files.flatMap(f => { - const path = getFilePath(f) + const path = getFilePath(f, version) if (!path) return [] if (f.type === 'pack_mcmeta') return 'pack.mcmeta' if (treeViewMode === 'resources') { return [`${f.type.replaceAll('/', '\u2215')}/${f.id.replaceAll('/', '\u2215')}`] } return [path] - }), [treeViewMode, ...project.files]) + }), [treeViewMode, version, ...project.files]) - const selected = useMemo(() => file && getFilePath(file), [file]) + const selected = useMemo(() => file && getFilePath(file, version), [file, version]) const selectFile = useCallback((entry: string) => { const file = disectEntry(entry) @@ -72,7 +72,7 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) { if (!download.current) return let hasPack = false const entries = project.files.flatMap(file => { - const path = getFilePath(file) + const path = getFilePath(file, version) if (path === undefined) return [] if (path === 'pack.mcmeta') hasPack = true return [[path, stringifySource(file.data)]] as [string, string][] @@ -126,7 +126,7 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) { } const file = disectEntry(entry) - return
selectFile(entry)} onContextMenu={onContextMenu} > + return
selectFile(entry)} onContextMenu={onContextMenu} > {Octicon.file} {entry.split('/').at(-1)} {focused &&
diff --git a/src/app/components/generator/SchemaGenerator.tsx b/src/app/components/generator/SchemaGenerator.tsx index 9f20a1f5c..656e50a7d 100644 --- a/src/app/components/generator/SchemaGenerator.tsx +++ b/src/app/components/generator/SchemaGenerator.tsx @@ -4,13 +4,13 @@ import { useCallback, useEffect, useErrorBoundary, useMemo, useRef, useState } f import { Analytics } from '../../Analytics.js' import type { ConfigGenerator } from '../../Config.js' import config from '../../Config.js' -import { Store } from '../../Store.js' -import { cleanUrl, deepEqual } from '../../Utils.js' import { DRAFT_PROJECT, useLocale, useProject, useVersion } from '../../contexts/index.js' import { AsyncCancel, useActiveTimeout, useAsync, useModel, useSearchParam } from '../../hooks/index.js' import { getOutput } from '../../schema/transformOutput.js' import type { VersionId } from '../../services/index.js' import { checkVersion, fetchPreset, getBlockStates, getCollections, getModel, getSnippet, shareSnippet } from '../../services/index.js' +import { Store } from '../../Store.js' +import { cleanUrl, deepEqual, genPath } from '../../Utils.js' import { Ad, Btn, BtnMenu, ErrorPanel, FileCreation, FileRenaming, Footer, HasPreview, Octicon, PreviewPanel, ProjectCreation, ProjectDeletion, ProjectPanel, SearchList, SourcePanel, TextInput, Tree, VersionSwitcher } from '../index.js' export const SHARE_KEY = 'share' @@ -167,7 +167,7 @@ export function SchemaGenerator({ gen, allowedVersions }: Props) { const loadPreset = async (id: string) => { try { - const preset = await fetchPreset(version, gen.path ?? gen.id, id) + const preset = await fetchPreset(version, genPath(gen, version), id) const seed = model?.get(new Path(['generator', 'seed'])) if (preset?.generator?.seed !== undefined && seed !== undefined) { preset.generator.seed = seed diff --git a/src/app/contexts/Project.tsx b/src/app/contexts/Project.tsx index b19c9119e..bda6cdd73 100644 --- a/src/app/contexts/Project.tsx +++ b/src/app/contexts/Project.tsx @@ -5,7 +5,8 @@ import { useCallback, useContext, useMemo, useState } from 'preact/hooks' import config from '../Config.js' import type { VersionId } from '../services/index.js' import { Store } from '../Store.js' -import { cleanUrl } from '../Utils.js' +import { cleanUrl, genPath } from '../Utils.js' +import { useVersion } from './Version.jsx' export type Project = { name: string, @@ -62,6 +63,7 @@ export function useProject() { export function ProjectProvider({ children }: { children: ComponentChildren }) { const [projects, setProjects] = useState(Store.getProjects()) + const { version } = useVersion() const [projectName, setProjectName] = useState(Store.getOpenProject()) const project = useMemo(() => { @@ -119,13 +121,13 @@ export function ProjectProvider({ children }: { children: ComponentChildren }) { }, [updateProject, project, file]) const openFile = useCallback((type: string, id: string) => { - const gen = config.generators.find(g => g.id === type || g.path === type) + const gen = config.generators.find(g => g.id === type || genPath(g, version) === type) if (!gen) { throw new Error(`Cannot find generator of type ${type}`) } setFileId([gen.id, id]) route(cleanUrl(gen.url)) - }, []) + }, [version]) const closeFile = useCallback(() => { setFileId(undefined) @@ -149,7 +151,7 @@ export function ProjectProvider({ children }: { children: ComponentChildren }) { } -export function getFilePath(file: { id: string, type: string }) { +export function getFilePath(file: { id: string, type: string }, version: VersionId) { const [namespace, id] = file.id.includes(':') ? file.id.split(':') : ['minecraft', file.id] if (file.type === 'pack_mcmeta') { if (file.id === 'pack') return 'pack.mcmeta' @@ -159,17 +161,17 @@ export function getFilePath(file: { id: string, type: string }) { if (!gen) { return undefined } - return `data/${namespace}/${gen.path ?? gen.id}/${id}.json` + return `data/${namespace}/${genPath(gen, version)}/${id}.json` } -export function disectFilePath(path: string) { +export function disectFilePath(path: string, version: VersionId) { if (path === 'pack.mcmeta') { return { type: 'pack_mcmeta', id: 'pack' } } for (const p of FilePatterns) { const match = path.match(p) if (!match) continue - const gen = config.generators.find(g => (g.path ?? g.id) === match[2]) + const gen = config.generators.find(g => (genPath(g, version) ?? g.id) === match[2]) if (!gen) continue const namespace = match[1] const name = match[3].replace(/\.[a-z]+$/, '') diff --git a/src/config.json b/src/config.json index b0f7dcf8e..dd2420587 100644 --- a/src/config.json +++ b/src/config.json @@ -157,7 +157,7 @@ "id": "1.21", "dynamic": true, "name": "1.21", - "pack_format": 42, + "pack_format": 43, "show": true } ], @@ -421,7 +421,7 @@ "id": "tag/block", "url": "tags/block", "tags": ["tags"], - "path": "tags/blocks", + "path": "tags/block", "schema": "block_tag", "wiki": "https://minecraft.wiki/w/Tag#Java_Edition" }, @@ -429,7 +429,7 @@ "id": "tag/entity_type", "url": "tags/entity-type", "tags": ["tags"], - "path": "tags/entity_types", + "path": "tags/entity_type", "schema": "entity_type_tag", "wiki": "https://minecraft.wiki/w/Tag#Java_Edition" }, @@ -437,7 +437,7 @@ "id": "tag/fluid", "url": "tags/fluid", "tags": ["tags"], - "path": "tags/fluids", + "path": "tags/fluid", "schema": "fluid_tag", "wiki": "https://minecraft.wiki/w/Tag#Java_Edition" }, @@ -445,7 +445,7 @@ "id": "tag/game_event", "url": "tags/game-event", "tags": ["tags"], - "path": "tags/game_events", + "path": "tags/game_event", "schema": "game_event_tag", "minVersion": "1.17", "wiki": "https://minecraft.wiki/w/Tag#Java_Edition" @@ -454,7 +454,7 @@ "id": "tag/item", "url": "tags/item", "tags": ["tags"], - "path": "tags/items", + "path": "tags/item", "schema": "item_tag", "wiki": "https://minecraft.wiki/w/Tag#Java_Edition" },