cleanup, better resource pack support (#173)

This commit is contained in:
Vitaly 2024-08-06 20:42:33 +03:00 committed by GitHub
commit 6bac74b6c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 114 additions and 4890 deletions

View file

@ -23,11 +23,14 @@ fs.writeFileSync('./generated/minecraft-data-data.js', mcDataContents, 'utf8')
// app resources
let headerImports = ''
let resourcesContent = 'export const appReplacableResources: { [key: string]: { content: any, resourcePackPath: string, cssVar?: string, cssVarRepeat?: number } } = {\n'
let resourcesContent = 'export const appReplacableResources: { [key in Keys]: { content: any, resourcePackPath: string, cssVar?: string, cssVarRepeat?: number } } = {\n'
let resourcesContentOriginal = 'export const resourcesContentOriginal = {\n'
const keys = [] as string[]
for (const resource of appReplacableResources) {
const { path, ...rest } = resource
const name = path.split('/').slice(-4).join('_').replace('.png', '').replaceAll('-', '_').replaceAll('.', '_')
keys.push(name)
headerImports += `import ${name} from '${path.replace('../node_modules/', '')}'\n`
resourcesContent += `
'${name}': {
@ -35,10 +38,16 @@ for (const resource of appReplacableResources) {
resourcePackPath: 'minecraft/textures/${path.slice(path.indexOf('other-textures/') + 'other-textures/'.length).split('/').slice(1).join('/')}',
...${JSON.stringify(rest)}
},
`
resourcesContentOriginal += `
'${name}': ${name},
`
}
resourcesContent += '}'
resourcesContent += '}\n'
resourcesContent += `type Keys = ${keys.map(k => `'${k}'`).join(' | ')}\n`
resourcesContentOriginal += '}\n'
resourcesContent += resourcesContentOriginal
fs.mkdirSync('./src/generated', { recursive: true })
fs.writeFileSync('./src/generated/resources.ts', headerImports + '\n' + resourcesContent, 'utf8')