forked from unimatrix/web
Share identical imperial atlas artwork in the central pack
This commit is contained in:
parent
911e581b1d
commit
4b9d8282d0
3 changed files with 48 additions and 1 deletions
|
|
@ -102,7 +102,7 @@ jobs:
|
|||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
PYTHON
|
||||
node tools/build-central-resource-pack.mjs central-pack-base central-pack-output 4 network/resource-pack/shared
|
||||
node tools/build-central-resource-pack.mjs central-pack-base central-pack-output 5 network/resource-pack/shared
|
||||
printf '%s\n' "$GITHUB_SHA" > central-pack-output/SOURCE_COMMIT
|
||||
(cd central-pack-output && sha256sum -- *.zip central-pack-manifest.json SOURCE_COMMIT > SHA256SUMS)
|
||||
- uses: actions/upload-artifact@v3
|
||||
|
|
|
|||
|
|
@ -61,11 +61,36 @@ export function mergePackAssets(base,sources){
|
|||
return merged;
|
||||
}
|
||||
|
||||
function deduplicateImperialAtlas(entries){
|
||||
const legacy='dunerealms:gui/imperial_menu_atlas_v2';
|
||||
const canonical='dunerealms:gui/imperial-menu-atlas-v2';
|
||||
const legacyFile='assets/dunerealms/textures/gui/imperial_menu_atlas_v2.png';
|
||||
const canonicalFile='assets/dunerealms/textures/gui/imperial-menu-atlas-v2.png';
|
||||
const oldBytes=entries.get(legacyFile),newBytes=entries.get(canonicalFile);
|
||||
if(!oldBytes||!newBytes||!oldBytes.equals(newBytes)||entries.has(legacyFile+'.mcmeta')||entries.has(canonicalFile+'.mcmeta'))return;
|
||||
for(const [name,data] of entries){
|
||||
if(name.endsWith('.json')&&data.includes(Buffer.from(legacy+'.png')))return;
|
||||
}
|
||||
const aliases=new Map();
|
||||
for(const path of [blocksAtlas,'assets/minecraft/atlases/items.json']){
|
||||
if(!entries.has(path))return;
|
||||
const atlas=JSON.parse(entries.get(path));
|
||||
const index=atlas.sources?.findIndex(source=>
|
||||
(source.type==='single'||source.type==='minecraft:single')&&source.resource===legacy&&(source.sprite??source.resource)===legacy);
|
||||
if(index==null||index<0)return;
|
||||
atlas.sources[index]={...atlas.sources[index],resource:canonical,sprite:legacy};
|
||||
aliases.set(path,json(atlas));
|
||||
}
|
||||
for(const [name,bytes] of aliases)entries.set(name,bytes);
|
||||
entries.delete(legacyFile);
|
||||
}
|
||||
|
||||
export function centralPackEntries(base,planetEntries=textureEntries,assetSources=[]){
|
||||
const merged=mergePackAssets(base,assetSources);
|
||||
if(!merged.has('pack.mcmeta'))throw Error('The base must be an extracted network resource pack');
|
||||
const packInfo=JSON.parse(merged.get('pack.mcmeta'));
|
||||
if(!packInfo.pack)throw Error('The network pack metadata is invalid');
|
||||
deduplicateImperialAtlas(merged);
|
||||
const atlas=merged.has(blocksAtlas)?JSON.parse(merged.get(blocksAtlas)):{sources:[]};
|
||||
if(!Array.isArray(atlas.sources))throw Error('The network blocks atlas is invalid');
|
||||
const sprites=new Map(atlas.sources.filter(source=>source.type==='single'||source.type==='minecraft:single')
|
||||
|
|
|
|||
|
|
@ -172,3 +172,25 @@ test('the supplied DuneMenus logo glyph points to compact shared artwork',()=>{
|
|||
assert(image.readUInt32BE(20)<=36);
|
||||
assert(image.length<16*1024);
|
||||
});
|
||||
|
||||
test('identical imperial atlas artwork shares a texture while retaining both sprite registrations',()=>{
|
||||
const atlasPaths=['assets/minecraft/atlases/blocks.json','assets/minecraft/atlases/items.json'];
|
||||
const legacy='dunerealms:gui/imperial_menu_atlas_v2', canonical='dunerealms:gui/imperial-menu-atlas-v2';
|
||||
const oldFile='assets/dunerealms/textures/gui/imperial_menu_atlas_v2.png';
|
||||
const newFile='assets/dunerealms/textures/gui/imperial-menu-atlas-v2.png';
|
||||
const source=Buffer.from(JSON.stringify({sources:[{type:'single',resource:legacy}]}));
|
||||
const fixture=new Map([['pack.mcmeta',Buffer.from('{"pack":{"pack_format":64}}')],
|
||||
[oldFile,Buffer.from('identical')],[newFile,Buffer.from('identical')],...atlasPaths.map(name=>[name,source])]);
|
||||
const entries=centralPackEntries(fixture,()=>new Map());
|
||||
assert(!entries.has(oldFile));
|
||||
assert(entries.has(newFile));
|
||||
for(const name of atlasPaths){
|
||||
assert.deepEqual(JSON.parse(entries.get(name)).sources[0],{type:'single',resource:canonical,sprite:legacy});
|
||||
}
|
||||
const different=new Map(fixture);
|
||||
different.set(oldFile,Buffer.from('different'));
|
||||
assert(centralPackEntries(different,()=>new Map()).has(oldFile));
|
||||
const direct=new Map(fixture);
|
||||
direct.set('assets/dunerealms/font/direct.json',Buffer.from(JSON.stringify({providers:[{file:legacy+'.png'}]})));
|
||||
assert(centralPackEntries(direct,()=>new Map()).has(oldFile));
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff