from pathlib import Path
root=Path(r'G:\项目\NumberSwipe-Variants\campaign-50')
p=root/'tools/build.mjs';s=p.read_text(encoding='utf-8-sig');a=s.index('const html=`');b=s.index('fs.writeFileSync(path.join(root,\'index.html\')',a)
s=s[:a]+'''const html=`
数字一笔 · 50关DEMO
试玩反馈
记下有趣、枯燥、太难或规则不清楚的关卡,导出记录后用于调整。
`;
''' +s[b:]
p.write_text(s,encoding='utf-8')
p=root/'ui.mjs';s=p.read_text(encoding='utf-8').replace('(height-20)/(ymax-ymin)','(height-20-height*.06)/(ymax-ymin)');p.write_text(s,encoding='utf-8')
p=root/'tests/ui.test.mjs';s=p.read_text(encoding='utf-8-sig')
s=s.replace("this.value='';", "this.value='';this.style={};this.className='';")
s=s.replace("lineTo(x,y){this.p.push([x,y]);},closePath()", "lineTo(x,y){this.p.push([x,y]);},quadraticCurveTo(cx,cy,x,y){this.p.push([x,y]);},closePath()")
s=s.replace("setTimeout:f=>f()", "setTimeout:f=>f(),clearTimeout(){}")
s=s.replace("get('difficulties').children[ch].click();get('levels').children[(n-1)%10].click();", "get('pack-list').children[ch].children[1].children[(n-1)%10].click();")
s=s.replace("ui.get('difficulties').children.length,5", "ui.get('pack-list').children.length,5")
s=s.replace("ui.get('levels').children.length,10", "ui.get('pack-list').children[Math.floor((n-1)/10)].children[1].children.length,10")
s=s.replace("ui.get('remaining').textContent,'完成 ✓'", "ui.get('remaining-n').textContent,'完成'")
s=s.replace("/1\\/50/", "/1\\s*\\/\\s*50/")
s+='''\ntest('original project select/play screens, progress segments and rule sheet',()=>{const ui=boot();assert.equal(ui.snapshot().screen,'select');ui.get('btn-continue').click();assert.equal(ui.snapshot().screen,'play');assert.equal(ui.get('level-progress').children.length,10);ui.get('btn-rules').click();assert.equal(ui.get('rules-sheet').hidden,false);ui.get('close-rules').click();assert.equal(ui.get('rules-sheet').hidden,true);ui.get('btn-back').click();assert.equal(ui.snapshot().screen,'select');ui.select(22);assert.equal(ui.snapshot().screen,'play');assert.equal(ui.get('position').textContent,'3-2');});
'''
p.write_text(s,encoding='utf-8')