From 1bfd90efd4fb63eed1a288d4ecb4312e2f6f7781 Mon Sep 17 00:00:00 2001 From: Misode Date: Sat, 14 Dec 2024 13:29:23 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Support=20special=20resource=20pack?= =?UTF-8?q?=20files=20(#1676)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/symbol/Symbol.ts | 5 +++ packages/java-edition/src/binder/index.ts | 43 ++++++++++++++++--- .../java-edition/src/json/checker/index.ts | 2 +- packages/vscode-extension/src/extension.mts | 4 +- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/packages/core/src/symbol/Symbol.ts b/packages/core/src/symbol/Symbol.ts index e52a0d1ac..5fb8118d2 100644 --- a/packages/core/src/symbol/Symbol.ts +++ b/packages/core/src/symbol/Symbol.ts @@ -215,16 +215,21 @@ export const AssetsFileCategories = Object.freeze( 'font/ttf', 'font/otf', 'font/unihex', + 'gpu_warnlist', 'item_definition', // items 'lang', + 'lang/deprecated', 'model', 'particle', 'post_effect', + 'regional_compliancies', 'shader', 'shader/fragment', 'shader/vertex', 'sound', + 'sounds', // sounds.json 'texture', + 'texture_meta', // *.png.mcmeta ] as const, ) export type AssetsFileCategory = (typeof AssetsFileCategories)[number] diff --git a/packages/java-edition/src/binder/index.ts b/packages/java-edition/src/binder/index.ts index f4041513f..f981b8913 100644 --- a/packages/java-edition/src/binder/index.ts +++ b/packages/java-edition/src/binder/index.ts @@ -21,6 +21,7 @@ interface Resource { category: FileCategory ext: `.${string}` pack: 'data' | 'assets' + identifier?: string since?: ReleaseVersion until?: ReleaseVersion } @@ -129,13 +130,13 @@ for (const registry of TaggableResourceLocationCategories) { // Resource pack resource('atlases', { pack: 'assets', category: 'atlas', since: '1.19.3' }) resource('blockstates', { pack: 'assets', category: 'block_definition' }) -resource('equipment', { pack: 'assets', category: 'equipment', since: '1.21.4' }) -resource('font', { pack: 'assets', category: 'font', since: '1.16' }) +resource('equipment', { pack: 'assets', since: '1.21.4' }) +resource('font', { pack: 'assets', since: '1.16' }) resource('font', { pack: 'assets', category: 'font/ttf', since: '1.16', ext: '.ttf' }) resource('font', { pack: 'assets', category: 'font/otf', since: '1.16', ext: '.otf' }) resource('font', { pack: 'assets', category: 'font/unihex', since: '1.20', ext: '.zip' }) resource('items', { pack: 'assets', category: 'item_definition', since: '1.21.4' }) -resource('lang', { pack: 'assets', category: 'lang' }) +resource('lang', { pack: 'assets' }) resource('models', { pack: 'assets', category: 'model' }) resource('models/equipment', { pack: 'assets', @@ -151,6 +152,16 @@ resource('shaders', { pack: 'assets', category: 'shader/fragment', ext: '.fsh' } resource('shaders', { pack: 'assets', category: 'shader/vertex', ext: '.vsh' }) resource('sounds', { pack: 'assets', category: 'sound', ext: '.ogg' }) resource('textures', { pack: 'assets', category: 'texture', ext: '.png' }) +resource('textures', { pack: 'assets', category: 'texture_meta', ext: '.png.mcmeta' }) + +resource('lang', { pack: 'assets', category: 'lang/deprecated', identifier: 'deprecated' }) +resource('', { pack: 'assets', category: 'sounds', identifier: 'sounds' }) +resource('', { + pack: 'assets', + category: 'regional_compliancies', + identifier: 'regional_compliancies', +}) +resource('', { pack: 'assets', category: 'gpu_warnlist', identifier: 'gpu_warnlist' }) export function* getRels( uri: string, @@ -177,7 +188,7 @@ export function dissectUri(uri: string, ctx: UriBinderContext) { for (const rel of rels) { const parts = rel.split('/') - if (parts.length < 4) { + if (parts.length < 3) { continue } const [pack, namespace, ...rest] = parts @@ -185,6 +196,23 @@ export function dissectUri(uri: string, ctx: UriBinderContext) { continue } const candidateResources: [Resource, string][] = [] + if (rest.length === 1) { + const resources = Resources.get('') + for (const res of resources ?? []) { + if (res.pack !== pack) { + continue + } + let identifier = rest[0] + if (!identifier.endsWith(res.ext)) { + continue + } + identifier = identifier.slice(0, -res.ext.length) + if (res.identifier && identifier !== res.identifier) { + continue + } + candidateResources.push([res, identifier]) + } + } for (let i = 1; i < rest.length; i += 1) { const resources = Resources.get(rest.slice(0, i).join('/')) for (const res of resources ?? []) { @@ -196,6 +224,9 @@ export function dissectUri(uri: string, ctx: UriBinderContext) { continue } identifier = identifier.slice(0, -res.ext.length) + if (res.identifier && identifier !== res.identifier) { + continue + } candidateResources.push([res, identifier]) } } @@ -240,9 +271,7 @@ export const uriBinder: UriBinder = (uris: readonly string[], ctx: UriBinderCont export function registerCustomResources(config: Config) { for (const [path, res] of Object.entries(config.env.customResources)) { - if (res.pack === undefined || res.pack === 'data') { - resource(path, { ...res, category: res.category as FileCategory }) - } + resource(path, { ...res, category: res.category as FileCategory }) } } diff --git a/packages/java-edition/src/json/checker/index.ts b/packages/java-edition/src/json/checker/index.ts index 7c336ac48..8d04d737b 100644 --- a/packages/java-edition/src/json/checker/index.ts +++ b/packages/java-edition/src/json/checker/index.ts @@ -26,7 +26,7 @@ export const file: core.Checker = (node, ctx) => { } const parts = dissectUri(ctx.doc.uri, ctx) if (parts?.ok) { - if (parts?.category.startsWith('tag/')) { + if (parts.category.startsWith('tag/')) { const type = createTagDefinition(parts.category.slice(4)) return json.checker.index(type)(child, ctx) } diff --git a/packages/vscode-extension/src/extension.mts b/packages/vscode-extension/src/extension.mts index d008c5122..741e273bb 100644 --- a/packages/vscode-extension/src/extension.mts +++ b/packages/vscode-extension/src/extension.mts @@ -43,8 +43,8 @@ export async function activate(context: vsc.ExtensionContext) { { language: 'mcdoc' }, { language: 'snbt' }, { language: 'mcmeta' }, - { language: 'json', pattern: '**/data/*/*/**/*.json' }, - { language: 'json', pattern: '**/assets/*/*/**/*.json' }, + { language: 'json', pattern: '**/data/*/**/*.json' }, + { language: 'json', pattern: '**/assets/*/**/*.json' }, ] const gameVersion = vsc.workspace.getConfiguration('spyglassmc.env').get('gameVersion')