Skip to content

Commit

Permalink
Add resource pack files to symbols and java-edition binder
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Oct 7, 2024
1 parent ca6caf2 commit eb39b59
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
12 changes: 12 additions & 0 deletions __snapshots__/packages/java-edition/test-out/binder/index.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 39 additions & 4 deletions packages/core/src/symbol/Symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ export const TagFileCategories = Object.freeze(
)
export type TagFileCategory = (typeof TagFileCategories)[number]

export const FileCategories = Object.freeze(
export const DataFileCategories = Object.freeze(
[...NormalFileCategories, ...TagFileCategories, ...WorldgenFileCategories] as const,
)
export type FileCategory = (typeof FileCategories)[number]
export type DataFileCategory = (typeof DataFileCategories)[number]

export const MiscCategories = Object.freeze(
[
Expand All @@ -193,15 +193,50 @@ export const DatapackCategories = Object.freeze(
'score_holder',
'tag',
'team',
...FileCategories,
...DataFileCategories,
...MiscCategories,
] as const,
)
export type DatapackCategory = (typeof DatapackCategories)[number]
// #endregion

// #region Resource Pack Categories
export const AssetsFileCategories = Object.freeze(
[
'atlas',
'block_definition', // blockstates
'font',
'lang',
'model',
'particle',
'post_effect',
'shader',
'sound',
'texture',
] as const,
)
export type AssetsFileCategory = (typeof AssetsFileCategories)[number]

export const ResourcepackCategories = Object.freeze(
[
...AssetsFileCategories,
] as const,
)
export type ResourcepackCategory = (typeof ResourcepackCategories)[number]
// #endregion

export const FileCategories = Object.freeze(
[...DataFileCategories, ...AssetsFileCategories] as const,
)
export type FileCategory = (typeof FileCategories)[number]

export const AllCategories = Object.freeze(
[...DatapackCategories, ...McdocCategories, ...RegistryCategories] as const,
[
...DatapackCategories,
...ResourcepackCategories,
...McdocCategories,
...RegistryCategories,
] as const,
)
export type AllCategory = (typeof AllCategories)[number]

Expand Down
23 changes: 20 additions & 3 deletions packages/java-edition/src/binder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface Resource {
path: string
category: FileCategory
ext: `.${string}`
pack: 'data' | 'assets'
since?: ReleaseVersion
until?: ReleaseVersion
}
Expand All @@ -33,6 +34,7 @@ function resource(path: string, resource: Partial<Resource> = {}) {
path,
category: resource.category ?? path as FileCategory,
ext: resource.ext ?? '.json',
pack: resource.pack ?? 'data',
...resource,
})
}
Expand Down Expand Up @@ -120,6 +122,18 @@ for (const registry of TaggableResourceLocationCategories) {
resource(`tags/${registry}`, { category: `tag/${registry}`, since: '1.18' })
}

// Resource pack
resource('atlases', { pack: 'assets', category: 'atlas', since: '1.19.3' })
resource('blockstates', { pack: 'assets', category: 'block_definition' })
resource('fonts', { pack: 'assets', category: 'font', since: '1.16' })
resource('lang', { pack: 'assets', category: 'lang' })
resource('models', { pack: 'assets', category: 'model' })
resource('particles', { pack: 'assets', category: 'particle' })
resource('post_effect', { pack: 'assets' })
resource('shaders', { pack: 'assets', category: 'shader' }) // TODO: support other extensions
resource('sounds', { pack: 'assets', category: 'sound', ext: '.ogg' })
resource('textures', { pack: 'assets', category: 'texture', ext: '.png' })

export function* getRels(
uri: string,
rootUris: readonly RootUriString[],
Expand All @@ -128,7 +142,7 @@ export function* getRels(

const parts = uri.split('/')
for (let i = parts.length - 2; i >= 0; i--) {
if (parts[i] === 'data') { // TODO: support assets
if (parts[i] === 'data' || parts[i] === 'assets') {
yield parts.slice(i).join('/')
}
}
Expand All @@ -149,8 +163,8 @@ export function dissectUri(uri: string, ctx: UriBinderContext) {
continue
}
const [pack, namespace, ...rest] = parts
if (pack !== 'data') {
continue // TODO: support assets
if (pack !== 'data' && pack !== 'assets') {
continue
}
let resource: Resource | undefined = undefined
let matchIndex = 0
Expand All @@ -164,6 +178,9 @@ export function dissectUri(uri: string, ctx: UriBinderContext) {
if (!resource) {
continue
}
if (resource.pack !== pack) {
continue
}
let identifier = rest.slice(matchIndex).join('/')
if (!identifier.endsWith(resource.ext)) {
continue
Expand Down

0 comments on commit eb39b59

Please sign in to comment.