/* Deterministic asset slicing, SVG rasterization and editable effect export. No repainting or background removal: source artwork remains unchanged. */ import fs from 'node:fs';import path from 'node:path';import vm from 'node:vm'; import {createRequire} from 'node:module';import {fileURLToPath} from 'node:url'; const require=createRequire(import.meta.url),root=path.dirname(fileURLToPath(import.meta.url)); let sharp;try{sharp=require('sharp');}catch{sharp=require(process.env.BUFFALO_SHARP_PATH||'C:/Users/EDY/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/sharp');} const at=p=>path.join(root,p);const write=(p,v)=>fs.writeFileSync(at(p),typeof v==='string'?v:JSON.stringify(v,null,2)); for(const dir of ['assets/sprites','assets/ui/png','assets/fx','assets/maps'])fs.mkdirSync(at(dir),{recursive:true}); const records=[]; const atlases=[ ['tower-item-atlas',5,2,['tower.archer','tower.pistol','tower.crossbow','tower.rifle','tower.mortar','item.airstrike','item.frost','item.repair','item.gold','brand.buffalo']], ['enemy-atlas',3,2,['enemy.rabbit','enemy.bison','enemy.wolf','enemy.vulture','enemy.scorpion','enemy.king']], ['avatar-atlas',4,2,['avatar.bison','avatar.wolf','avatar.eagle','avatar.scorpion','avatar.rabbit','avatar.bear','avatar.horse','avatar.snake']], ['props-atlas',4,4,['prop.base','prop.portal','prop.build-pad','prop.watchtower','prop.cactus','prop.prickly-pear','prop.grass','prop.shrub','prop.red-rock','prop.tan-rock','prop.skull','prop.ribs','prop.wagon','prop.fence','prop.barrels','prop.windmill']], ['terrain-atlas',2,2,['terrain.serpentine','terrain.longhorn','terrain.switchback','terrain.chokepoint']] ]; for(const [name,cols,rows,ids]of atlases){ const src='assets/art/'+name+'.png',meta=await sharp(at(src)).metadata(); for(let i=0;i8){minX=Math.min(minX,px);maxX=Math.max(maxX,px);minY=Math.min(minY,py);maxY=Math.max(maxY,py);} records.push({id:ids[i],file,width:w,height:h,transparent:meta.hasAlpha,atlas:src,grid:[cols,rows],cellIndex:i,sourceRect:{x,y,width:w,height:h},uv:[x/meta.width,y/meta.height,w/meta.width,h/meta.height],transparentPadding:[minY,w-1-maxX,h-1-maxY,minX],pivot:[.5,.5],nineSlice:[0,0,0,0]}); } } const ui=JSON.parse(fs.readFileSync(at('assets/ui/ui-assets.json'),'utf8')); const extraUI=[ ['trash',64,64,0,''], ['document',64,64,0,''], ['progress-track',128,24,8,''], ['progress-fill',128,16,5,''], ['tab-normal',128,64,12,''], ['tab-selected',128,64,12,''], ['switch-off',84,44,0,''], ['switch-on',84,44,0,''], ['badge',48,48,0,''] ]; for(const [name,w,h,slice,body]of extraUI){const file=name+'.svg';write('assets/ui/'+file,`${body}`);ui.assets.push({id:'ui.'+name,file,width:w,height:h,transparent:true,pivot:[.5,.5],kind:'component',borderSlices:[slice,slice,slice,slice]});} for(const a of ui.assets){const file='assets/ui/png/'+a.file.replace('.svg','.png');await sharp(at('assets/ui/'+a.file)).png().toFile(at(file));records.push({...a,source:'assets/ui/'+a.file,file,nineSlice:a.borderSlices});} // Reuse the exact gameplay geometry and deterministic decoration placement for all four maps. const app=fs.readFileSync(at('app.js'),'utf8'); const maps=vm.runInNewContext(app.match(/const MAP_DEFS = (\[[\s\S]*?\n\]);/)[1]); function rng(seed){let s=seed>>>0;return()=>{s=(s*1664525+1013904223)>>>0;return s/4294967296;};} function segment(px,py,a,b){const dx=b[0]-a[0],dy=b[1]-a[1],l=dx*dx+dy*dy;const t=Math.max(0,Math.min(1,((px-a[0])*dx+(py-a[1])*dy)/l));return Math.hypot(px-a[0]-dx*t,py-a[1]-dy*t);} function dataImage(file){return 'data:image/png;base64,'+fs.readFileSync(at(file)).toString('base64');} for(let i=0;iMath.min(...m.path.slice(1).map((p,j)=>segment(x,y,m.path[j],p))),slots=[]; m.rows.forEach(y=>m.cols.forEach(x=>{if(x>=24&&x<=406&&y>=18&&y<=580&&distance(x,y)>=m.minD&&Math.hypot(x-m.base.x,y-m.base.y)>=80)slots.push({x,y});}));m.slots=slots;m.coordinateSize=[430,600]; const d=m.path.map((p,j)=>(j?'L':'M')+p.join(' ')).join(' '),r=rng(1024+i*87); let svg=``; for(const [w,c]of [[53,'#714b2a55'],[48,'#a47440'],[41,'#c99859'],[33,'#dcb275']])svg+=``; svg+=``; for(let j=0;j<38;j++){const x=12+r()*406,y=15+r()*565;if(distance(x,y)<41||slots.some(s=>Math.hypot(s.x-x,s.y-y)<38)||Math.hypot(m.base.x-x,m.base.y-y)<68)continue;const idx=4+Math.floor(r()*12),size=idx===15?50:25+r()*24;svg+=``;} svg+=''; const file='assets/maps/'+m.key+'.png';write('assets/maps/'+m.key+'.svg',svg);await sharp(Buffer.from(svg)).png().toFile(at(file));m.background=file;records.push({id:'map.'+m.key,file,width:750,height:1047,transparent:false,source:'assets/maps/'+m.key+'.svg',pivot:[.5,.5],nineSlice:[0,0,0,0]}); } write('assets/maps/maps.json',{coordinateSize:[430,600],referenceWidth:750,maps}); // Eight-frame transparent VFX sheets are vector-authored and editable. for(const name of ['impact','frost','repair','muzzle','portal']){ let svg=''; for(let i=0;i<8;i++){const t=i/7,a=1-t*.9,r=8+t*49,x=i*128+64;svg+=``; if(name==='impact')svg+=``; if(name==='frost'){svg+=``;for(let j=0;j<6;j++)svg+=``;} if(name==='repair')svg+=``; if(name==='muzzle')svg+=``; if(name==='portal')svg+=``; svg+=''; } svg+='';const source='assets/fx/'+name+'.svg',file='assets/fx/'+name+'.png';write(source,svg);await sharp(Buffer.from(svg)).png().toFile(at(file));records.push({id:'fx.'+name,source,file,width:1024,height:128,transparent:true,frames:8,grid:[8,1],fps:name==='portal'?12:16,pivot:[.5,.5],loop:name==='portal',nineSlice:[0,0,0,0]}); } const backgrounds=['menu-desert','mode-campaign','mode-endless']; for(const name of backgrounds){const file='assets/art/'+name+'.png',m=await sharp(at(file)).metadata();records.push({id:'illustration.'+name,file,width:m.width,height:m.height,transparent:false,pivot:[.5,.5],nineSlice:[0,0,0,0]});} write('assets/animation.json',{version:1,notes:'Procedural sprite motion plus transparent VFX frame strips. No directional skeletal animation is implied.',units:'430-wide gameplay coordinates; multiply by 750/430 for reference UI',enemy:{run:{duration:.45,loop:true,positionY:[0,-1.3,0,1.3,0],mirrorX:'movement.x < 0'},fly:{duration:.78,loop:true,positionY:[0,-3,0,3,0]},hit:{duration:.12,brightness:[1.6,1]},death:{duration:.25,opacity:[1,0],scale:[1,.85]}},tower:{recoil:{duration:.12,positionY:[0,2,0]},levelUp:{duration:.55,scale:[1,1.12,1]}},ui:{pressed:{duration:.1,positionY:[0,2],brightness:.9},popup:{duration:.2,positionY:[8,0],scale:[.97,1],opacity:[0,1]}},effects:records.filter(a=>a.id.startsWith('fx.'))}); write('theme.json',{style:'A / Handpainted Western Desert',reference:{width:750,height:1334,matchWidth:1,htmlLogicalWidth:430,htmlToDesign:750/430},colors:ui.palette,fonts:{brand:{family:'Rye',file:'assets/fonts/Rye-Regular.ttf'},heading:{family:'Bree Serif',file:'assets/fonts/BreeSerif-Regular.ttf'},body:{family:'Barlow Semi Condensed',file:'assets/fonts/BarlowSemiCondensed-SemiBold.ttf'},number:{family:'Barlow Semi Condensed',file:'assets/fonts/BarlowSemiCondensed-Bold.ttf'}},typeScaleDesign:{pageTitle:42,section:24,button:24,body:23,meta:19},geometry:{panelBorder:20,cardBorder:18,buttonBorder:16,iconBox:64,light:'upper left',corners:'clipped brass corners; small functional corner radii',shadow:'warm dark plum'},safeArea:'Read the platform safe-area inset; fill the background, inset the interactive root. Fit the entire 430×600 battlefield uniformly between HUD and dock.'}); write('asset-manifest.json',{version:1,status:'awaiting_html_visual_review',style:'A',reference:[750,1334],sliceOrder:['top','right','bottom','left'],spriteSourceOrigin:'top-left; Unity pixel Y = atlasHeight - sourceRect.y - sourceRect.height',textPolicy:'All interface text remains live HTML or TextMeshPro. Art contains no interface labels.',generatedWith:'OpenAI imagegen; prompts and original paths in art-prompts.json',fonts:{license:'SIL Open Font License; license files included',source:'https://github.com/google/fonts/tree/main/ofl',families:['Rye','Bree Serif','Barlow Semi Condensed']},assets:records}); const cards=records.map(a=>`
${a.frames?'':`${a.id}`}
${a.id}${a.width} × ${a.height}${a.transparent?' · Alpha':''}${a.frames?' · 8 frames':''}PNG ↓${a.source?` SVG ↓`:''}
`).join(''); write('assets.html',`Buffalo Siege · A 素材一览

Buffalo Siege / Style A

统一素材清单 · ${records.length} 项资源。图像保留透明通道,文字独立排版。原始图集、单张切片、可编辑控件、四张地图、特效帧条与字体许可均包含在本地目录。

← 返回交互预览资源清单 JSON ↓主题参数 JSON ↓动画参数 JSON ↓

${cards}
`); console.log('Exported '+records.length+' asset records, four maps, five effects and gallery.');