Spaces:
Running
Running
Download patch_movement.mjs from bep40/hangmu-docker: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/spaces/bep40/hangmu-docker/resolve/main/patch_movement.mjs
- Command line
-
hf download hf://spaces/bep40/hangmu-docker/patch_movement.mjs
-
curl -L -o patch_movement.mjs https://huggingface.co/spaces/bep40/hangmu-docker/resolve/main/patch_movement.mjs
1.74 kB
| /* patch_movement.mjs — ROOT CAUSE FIX: "không điều khiển được nhân vật 3D". | |
| Trong vòng lặp Movement (app.js), nx/nz được khai báo bằng `let` BÊN TRONG | |
| khối `if (moving) {...}` nhưng lại được tham chiếu BÊN NGOÀI khối đó trong | |
| điều kiện gửi Net.update(...): | |
| let nx = me.pos.x + ... | |
| let nz = me.pos.z + ... // scope chỉ trong if (moving) | |
| const p = last.current | |
| if (!p.pos || Math.abs(nx - p.pos.x) > 0.01 || Math.abs(nz - p.pos.z) > 0.01 ...) | |
| // ^^ ReferenceError: nx is not defined khi đứng yên | |
| Khi nhân vật đứng yên (mới vào hang), luồng rAF văng ReferenceError ngay | |
| frame thứ 2 -> loop chết -> KHÔNG điều khiển được nhân vật. Fix: dùng | |
| me.pos.x / me.pos.z thay cho nx/nz (luôn tồn tại), độc lập với việc đang | |
| di chuyển hay đứng yên. */ | |
| import fs from 'node:fs' | |
| const path = 'frontend/app.js' | |
| let s = fs.readFileSync(path, 'utf8') | |
| const marker = | |
| " if (!p.pos || Math.abs(nx - p.pos.x) > 0.01 || Math.abs(nz - p.pos.z) > 0.01 || p.rot !== rot || p.anim !== anim) {" | |
| const count = s.split(marker).length - 1 | |
| if (count !== 1) { | |
| console.error(`PATCH MOVEMENT FAILED: marker not unique/found (count=${count})`) | |
| process.exit(1) | |
| } | |
| const fixed = | |
| " // dùng me.pos thay nx/nz (nx/nz chỉ có scope trong if (moving) -> chống ReferenceError khi đứng yên)\n" + | |
| " if (!p.pos || Math.abs(me.pos.x - p.pos.x) > 0.01 || Math.abs(me.pos.z - p.pos.z) > 0.01 || p.rot !== rot || p.anim !== anim) {" | |
| s = s.replace(marker, fixed) | |
| fs.writeFileSync(path, s) | |
| console.log('patched app.js ok (MOVEMENT root-cause fix: nx/nz scope)') |