hangmu-docker / patch_boards.mjs
bep40's picture
Upload patch_boards.mjs
ee1174e verified
Raw History Blame Contribute Delete
3 kB
/* patch_boards.mjs — v26: đưa 2 bảng TRẬN GẦN NHẤT / TRẬN SẮP TỚI về đúng vị trí
spec: dựa tường 2 BÊN lối vào hang (z=71, x=∓8.5) thay vì treo trong hang (z=54).
Đồng thời bump VERSION_ID backend v25 -> v26 để khớp cache-bust ?v=26.
Nếu pattern không khớp -> exit(1) để build fail (không ship bản thiếu). */
import fs from 'node:fs'
function patchFile(path, reps) {
let s = fs.readFileSync(path, 'utf8')
const failures = []
function toRe(str) {
const esc = str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
return esc.replace(/\s+/g, '\\s+')
}
function rep(oldStr, newStr) {
const exact = s.split(oldStr).length - 1
if (exact === 1) { s = s.replace(oldStr, newStr); return }
const re = new RegExp(toRe(oldStr), 'g')
const m = s.match(re)
if (m && m.length === 1) { s = s.replace(re, newStr); return }
failures.push(`pattern not unique/found (exact=${exact}, re=${m ? m.length : 0}): ${oldStr.slice(0, 70)}`)
}
for (const [o, n] of reps) rep(o, n)
if (failures.length) {
console.error(`PATCH BOARDS FAILED (${path}):`)
failures.forEach((f) => console.error(' -', f))
process.exit(1)
}
fs.writeFileSync(path, s)
console.log('patched ok (boards):', path)
}
/* ================= cave3d.js - vị trí 2 bảng trận MU ================= */
patchFile('frontend/cave3d.js', [
/* Bảng TRẬN GẦN NHẤT: z=54 (treo trong hang) -> z=71 (dựa tường TRÁI lối vào) */
[ ` {/* 2 bảng dựa tường 2 bên lối vào (z≈71, cửa tunnel ở z≈73) — không treo lơ lửng */}
{/* sát tường dome 2 bên lối vào (r≈54.6 < 58, trong hang), quay mặt vào tâm */}
<MuMatchBoard pos={[-8.5, 3.2, 54]} rot={0.45} tex={lastTex} />
<MuMatchBoard pos={[8.5, 3.2, 54]} rot={-0.45} tex={nextTex} />`,
` {/* 2 bảng dựa tường 2 BÊN lối vào hang (z=71, x=∓8.5) — đúng spec, thấy ngay
khi đứng trong hang nhìn ra cửa (tunnel ở z≈73) */}
<MuMatchBoard pos={[-8.5, 3.2, 71]} rot={0.32} tex={lastTex} />
<MuMatchBoard pos={[8.5, 3.2, 71]} rot={-0.32} tex={nextTex} />`,
],
])
/* ================= backend.py - bump VERSION_ID ================= */
try {
const s = fs.readFileSync('backend.py', 'utf8')
let out = s
for (const v of ['v26', 'v25', 'v24', 'v23', 'v22', 'v21', 'v20', 'v19', 'v18', 'v17', 'v16', 'v15', 'v14', 'v13', 'v12', 'v11', 'v10']) {
if (out.includes(`VERSION_ID = "${v}"`)) {
out = out.split(`VERSION_ID = "${v}"`).join('VERSION_ID = "v26"')
break
}
}
if (out.includes('VERSION_ID = "v26"')) {
console.log('backend.py VERSION_ID -> v26 OK')
} else {
console.warn('patch_boards WARN: VERSION_ID marker not found')
}
fs.writeFileSync('backend.py', out)
} catch (e) {
console.warn('patch_boards SKIP: ' + String(e.message || e))
}
console.log('patch_boards.mjs OK — MU match boards at z=71, VERSION_ID=v26')