validate-preview.cjs 2.3 KB

123456789101112131415161718192021222324252627
  1. const fs=require('fs'),path=require('path');
  2. const sharp=require('C:/Users/EDY/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/sharp');
  3. const root=path.resolve(__dirname,'../..'),art=path.join(root,'Assets/BuffaloSiege/Art');
  4. async function main(){
  5. const inventory=JSON.parse(fs.readFileSync(path.join(__dirname,'asset-validation.json')));
  6. const animations=JSON.parse(fs.readFileSync(path.join(__dirname,'animation-manifest.json')));
  7. const files=[...inventory.filter(x=>!x.id.startsWith('illustration.')).map(x=>x.id+'.png'),...animations.flatMap(x=>x.files)];
  8. const checks=[];
  9. for(const file of files){
  10. const {data,info}=await sharp(path.join(art,file)).ensureAlpha().raw().toBuffer({resolveWithObject:true});const {width:w,height:h}=info;
  11. let edge=0,l=w,t=h,r=0,b=0;
  12. for(let y=0;y<h;y++)for(let x=0;x<w;x++){const alpha=data[(y*w+x)*4+3];if((x<8||y<8||x>=w-8||y>=h-8)&&alpha>0)edge++;if(alpha>0){l=Math.min(l,x);t=Math.min(t,y);r=Math.max(r,x);b=Math.max(b,y);}}
  13. if(edge)throw Error(file+': opaque pixels inside the 8 px safety border');
  14. checks.push({file,width:w,height:h,edgePixels:edge,padding:[t,w-1-r,h-1-b,l]});
  15. }
  16. fs.writeFileSync(path.join(__dirname,'alpha-validation.json'),JSON.stringify(checks,null,2)+'\n');
  17. // Review movie uses the exact imported PNG frames, independent labels and their game frame rates.
  18. const dir=path.join(__dirname,'preview-frames');fs.mkdirSync(dir,{recursive:true});
  19. const sprites=await Promise.all(animations.map(a=>Promise.all(a.files.map(f=>sharp(path.join(art,f)).resize(224,224).png().toBuffer()))));
  20. const labels=Buffer.from('<svg width="720" height="540">'+animations.map((a,i)=>'<text x="'+(i%3*240+12)+'" y="'+(Math.floor(i/3)*270+30)+'" fill="#ffe9ba" font-family="Arial" font-size="18">'+a.id.toUpperCase()+' · '+a.fps+' FPS</text>').join('')+'</svg>');
  21. for(let n=0;n<72;n++){
  22. const layers=animations.map((a,i)=>({input:sprites[i][Math.floor(n/24*a.fps)%6],left:i%3*240+8,top:Math.floor(i/3)*270+42}));
  23. await sharp({create:{width:720,height:540,channels:4,background:'#382638'}}).composite([...layers,{input:labels}]).png().toFile(path.join(dir,'frame-'+String(n).padStart(3,'0')+'.png'));
  24. }
  25. console.log('60 transparent assets passed the 8 px edge check; 72 review frames ready.');
  26. }
  27. main().catch(e=>{console.error(e);process.exit(1);});