// Mechanical asset preparation: preserve alpha, uniformly scale, pad, slice and record provenance. const fs=require('fs'),path=require('path'); const sharp=require('C:/Users/EDY/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/sharp'); const root=path.resolve(__dirname,'../..'),art=path.join(root,'Assets/BuffaloSiege/Art'); const records=JSON.parse(fs.readFileSync(path.join(__dirname,'generation-records.json'))); const manifests=[path.join(art,'asset-manifest.json'),path.join(root,'docs/ui-style-a/asset-manifest.json')]; function bounds(data,w,h,threshold=0){let l=w,t=h,r=-1,b=-1;for(let y=0;ythreshold){l=Math.min(l,x);r=Math.max(r,x);t=Math.min(t,y);b=Math.max(b,y);}if(r<0)throw Error('Empty image');return {left:l,top:t,width:r-l+1,height:b-t+1};} async function alphaBounds(file){const {data,info}=await sharp(file).ensureAlpha().raw().toBuffer({resolveWithObject:true});return bounds(data,info.width,info.height);} async function update(){ const docs=manifests.map(f=>JSON.parse(fs.readFileSync(f)));const report=[]; fs.mkdirSync(path.join(__dirname,'sources'),{recursive:true}); for(const rec of records){ if(!rec.path)throw Error('Missing source '+rec.id); const source=path.join(__dirname,'sources',rec.id+'.png');if(!fs.existsSync(source))fs.copyFileSync(rec.path,source); if(rec.id.startsWith('animation.'))continue; const output=path.join(art,rec.id+'.png');let b,dimensions; if(rec.id.startsWith('illustration.')){ // Crop an overscan composition at its native proportions; never squeeze the image. await sharp(source).extract(rec.crop).resize(688,152,{fit:'cover',position:'centre'}).flatten({background:'#241521'}).png().toFile(output); dimensions=[688,152];b={left:0,top:0,width:688,height:152}; }else{ const box=await alphaBounds(source),size=rec.id.startsWith('avatar.')||rec.id==='prop.build-pad'?256:512,pad=size/16; const content=await sharp(source).extract(box).resize(size-pad*2,size-pad*2,{fit:'inside'}).png().toBuffer(); const meta=await sharp(content).metadata(); await sharp({create:{width:size,height:size,channels:4,background:'#00000000'}}).composite([{input:content,left:Math.floor((size-meta.width)/2),top:Math.floor((size-meta.height)/2)}]).png().toFile(output); dimensions=[size,size];b=await alphaBounds(output); } const padding=[b.top,dimensions[0]-b.left-b.width,dimensions[1]-b.top-b.height,b.left]; const shared=path.join(root,'docs/ui-style-a/assets/sprites',rec.id+'.png');fs.copyFileSync(output,shared); for(let i=0;ia.id===rec.id);if(!entry)throw Error('Unknown ID '+rec.id); for(const key of ['atlas','grid','cellIndex','sourceRect','uv'])delete entry[key]; Object.assign(entry,{file:i===0?rec.id+'.png':'assets/sprites/'+rec.id+'.png',width:dimensions[0],height:dimensions[1],transparent:!rec.id.startsWith('illustration.'),transparentPadding:padding,pivot:[.5,.5],source:'docs/art-refresh-2026-10-29/sources/'+rec.id+'.png',sourceRoot:'project',revision:'2026-10-29'}); } report.push({id:rec.id,width:dimensions[0],height:dimensions[1],padding}); } for(let i=0;i{console.error(e);process.exit(1);});