| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import fs from 'node:fs';
- import path from 'node:path';
- import { fileURLToPath } from 'node:url';
- const root=path.dirname(fileURLToPath(import.meta.url));
- const source=fs.readFileSync(path.join(root,'../塔防_UI演示.html'),'utf8');
- let css=source.match(/<style>([\s\S]*?)<\/style>/)[1].replace(/^[ \t]*--logo:.*\r?\n/m,'');
- let html=source.match(/<body>([\s\S]*?)<script>/)[1];
- let js=source.match(/<script>([\s\S]*?)<\/script>/)[1];
- js=js.replace("const SAVE_KEY = 'rc_siege_v1';","const SAVE_KEY = 'buffalo_siege_style_a_preview_v1';");
- js=js.replace(/^boot\(\);/m,'// Boot follows local artwork preload in style-a.js.');
- js=js.replace('loopRunning = false','loopRunning = true');
- js=js.replace('Campaign has 20 fixed maps.','Campaign has 20 levels across four desert routes.');
- js=js.replace('spent on items only.','spent on support items and permanent tower upgrades.');
- js=js.replace("el.className = 'av-cell' + (state.player.avatar===a.key?' is-sel':'');", "el.className = 'av-cell' + (state.player.avatar===a.key?' is-sel':'');\n el.setAttribute('aria-label',a.name||a.key); el.dataset.avatar=a.key;");
- js=js.replace("if(el.dataset.close==='sheetPause' || el.dataset.close==='sheetBuy') G.paused = false;",'');
- js=js.replace("if(G.phase==='prep'){","if(G.phase==='prep' && G.prepLeft>0){");
- js=js.replace("if(G.score > (state.best.score||0)) state.best = { score:G.score, wave:cleared };","state.best = { score:Math.max(G.score,state.best.score||0), wave:Math.max(cleared,state.best.wave||0) };");
- js=js.replace('showResult(win, cleared, reward, false);','save();\n showResult(win, cleared, reward, false);');
- js=js.replace('const open = [...document.querySelectorAll(\'.sheet.is-open\')].pop();','const open = [...document.querySelectorAll(\'.sheet.is-open\')].pop();\n if(open && open.id===\'sheetResult\') return;');
- js=js.replace("if(c==='Volley'){ range*=1.15; rate*=0.90; }","if(c==='Volley'){ range*=1.15; rate/=1.10; }");
- js=js.replace("if(c==='Suppression'){ rate*=0.75; }","if(c==='Suppression'){ rate/=1.25; }");
- js=js.replace("if(c==='Siege Line'){ splash*=1.25; dmg*=1.10; }","if(c==='Siege Line' && t.type==='mortar'){ splash*=1.25; dmg*=1.10; }");
- js=js.replace("if(c==='Pierce Shell'){ dmg*=1.20; pierce=true; }","if(c==='Pierce Shell'){ if(t.type==='crossbow') dmg*=1.20; if(t.type==='mortar') pierce=true; }");
- // A sprite symbol points at an atlas cell, preserving independent HTML text and controls.
- function atlasSymbol(id,file,col,row,cols,rows){
- const body=`<symbol id="${id}" viewBox="0 0 100 100"><svg x="0" y="0" width="100" height="100" viewBox="${col} ${row} 1 1" overflow="hidden"><image href="assets/art/${file}.png" x="0" y="0" width="${cols}" height="${rows}" preserveAspectRatio="none"/></svg></symbol>`;
- html=html.replace(new RegExp('<symbol[^>]+id="'+id+'"[\\s\\S]*?<\\/symbol>'),body);
- }
- ['archer','pistol','crossbow','rifle','mortar'].forEach((key,i)=>atlasSymbol('t-'+key,'tower-item-atlas',i,0,5,2));
- ['air','frost','heal','gold'].forEach((key,i)=>atlasSymbol('it-'+key,'tower-item-atlas',i,1,5,2));
- ['bison','wolf','eagle','scorpion','rabbit','bear','horse','snake'].forEach((key,i)=>atlasSymbol('a-'+key,'avatar-atlas',i%4,Math.floor(i/4),4,2));
- const icons={'i-coin':'coin','i-star':'star','i-shield':'heart','i-pause':'pause','i-play':'play','i-back':'back','i-cart':'shop','i-book':'book','i-gear':'settings','i-cal':'calendar','i-trophy':'trophy','i-check':'check','i-lock':'lock','i-music':'music','i-sound':'sound','i-copy':'copy'};
- for(const[id,file]of Object.entries(icons))html=html.replace(new RegExp('<symbol[^>]+id="'+id+'"[\\s\\S]*?<\\/symbol>'),`<symbol id="${id}" viewBox="0 0 64 64"><image href="assets/ui/${file}.svg" width="64" height="64"/></symbol>`);
- for(const[id,file]of Object.entries({'i-vol':'sound','i-trash':'trash','i-doc':'document'}))html=html.replace(new RegExp('<symbol[^>]+id="'+id+'"[\\s\\S]*?<\\/symbol>'),`<symbol id="${id}" viewBox="0 0 64 64"><image href="assets/ui/${file}.svg" width="64" height="64"/></symbol>`);
- html=html.replace('<div class="lb-brand">','<div class="lb-brand"><img class="brand-bison" src="assets/ui/buffalo-mark.svg" alt="">');
- html=html.replace('<span class="chip">4–14 waves</span><span class="chip">5 towers</span>','<span class="chip">4 MAPS</span>');
- html=html.replace('<span class="chip">Infinite waves</span><span class="chip">Leaderboard</span><span class="chip">Score</span>','<span class="chip">SURVIVE</span><span class="chip">HIGH SCORE</span>');
- html=html.replace('Twenty hand-built desert maps. Clear them all to crown the outpost.','Twenty outposts. Four desert routes. Hold the line.');
- html=html.replace('Twenty outposts. Four desert routes. Hold the line.','Defend twenty outposts.');
- html=html.replace('Waves never stop. Every 5th wave brings a king. Climb the board.','Survive the stampede.');
- html=html.replace('Shop & coin records','Shop & inventory').replace('Items, balance, spend history','Items and coin balance');
- html=html.replace(/<div class="caption">[\s\S]*?<\/div>/,'');
- const toolbar=`<aside class="review-toolbar" aria-label="界面预览工具"><div class="review-brand"><strong>BUFFALO SIEGE</strong><span>A / 手绘西部荒漠 · UI 预览</span></div><div class="review-controls"><label>界面 <select id="reviewScreen"><option value="lobby">大厅</option><option value="start">开始页</option><option value="loading">Loading</option><option value="levels">关卡选择</option><option value="battle">战斗 · 普通波</option><option value="boss">战斗 · BOSS</option><option value="tower">塔属性 / 升级</option><option value="buy">局内购买</option><option value="pause">暂停</option><option value="victory">胜利结算</option><option value="defeat">失败结算</option><option value="endless">无尽结算</option><option value="armory">军械库</option><option value="shop">商城</option><option value="checkin">每日签到</option><option value="profile">个人资料</option><option value="avatar">头像选择</option><option value="rename">改名</option><option value="board">排行榜</option><option value="settings">设置</option><option value="help">玩法帮助</option><option value="terms">条款</option><option value="privacy">隐私</option></select></label><label>屏幕 <select id="reviewSize"><option value="750,1334,0,0">750 × 1334</option><option value="1125,2436,44,34">刘海屏 · 1125 × 2436</option><option value="1179,2556,59,34">灵动岛 · 1179 × 2556</option><option value="1290,2796,59,34">大屏 · 1290 × 2796</option></select></label><button id="reviewLive" aria-pressed="false">播放战斗</button><button id="reviewReset">还原样例</button><a href="assets.html" target="_blank" rel="noopener">素材一览 ↗</a></div><div class="review-note">在游戏内点击按钮即可浏览全部界面;上方工具可直接检查指定状态。<span id="reviewStatus">正在加载素材…</span></div></aside>`;
- const output=`<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><meta name="theme-color" content="#23151d"><title>Buffalo Siege · Style A UI Preview</title><link rel="stylesheet" href="base.css"><link rel="stylesheet" href="style-a.css"></head><body>${toolbar}${html}<script src="app.js"></script><script src="style-a.js"></script></body></html>`;
- fs.writeFileSync(path.join(root,'base.css'),css);
- fs.writeFileSync(path.join(root,'app.js'),js);
- fs.writeFileSync(path.join(root,'index.html'),output);
- const emblem=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="4 1 1 1"><image href="../art/tower-item-atlas.png" width="5" height="2" preserveAspectRatio="none"/></svg>`;
- // Standalone SVG image resources cannot load external image subresources in browsers.
- // Inline the unmodified PNG atlas bytes when artwork is available, preserving the original alpha.
- const atlas=path.join(root,'assets/art/tower-item-atlas.png');
- if(fs.existsSync(atlas))fs.writeFileSync(path.join(root,'assets/ui/buffalo-mark.svg'),emblem.replace('../art/tower-item-atlas.png','data:image/png;base64,'+fs.readFileSync(atlas).toString('base64')));
- console.log('Prepared HTML + original gameplay logic + atlas-backed SVG symbols.');
|