File size: 1,220 Bytes
999e17c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* patch_store.mjs — ROOT CAUSE FIX: "không có nhân vật 3D". */
import fs from 'node:fs'

const path = 'frontend/store.js'
let s = fs.readFileSync(path, 'utf8')

const marker =
  `      if (typeof data.inRoom === 'number') g.set({ inRoom: data.inRoom })
      break
    }`

const count = s.split(marker).length - 1
if (count !== 1) {
  console.error(`PATCH STORE FAILED: 'connected' marker not unique/found (count=${count})`)
  process.exit(1)
}

const inject =
  `      if (typeof data.inRoom === 'number') g.set({ inRoom: data.inRoom })
      // ===== SELF-AVATAR (fix "không có nhân vật 3D") =====
      const selfId = data.player_id || g.playerId
      if (selfId && !g.players.has(selfId)) {
        const sp = data.position || { x: 0, y: 0, z: 36 }
        g.players.set(selfId, {
          id: selfId,
          name: g.me?.name || 'Bạn',
          number: g.me?.number ?? null,
          pos: new THREE.Vector3(sp.x, sp.y, sp.z),
          rot: 0,
          anim: 'idle',
          lastSeen: Date.now(),
        })
        g.set({ players: new Map(g.players) })
      }
      break
    }`

s = s.replace(marker, inject)
fs.writeFileSync(path, s)
console.log('patched store.js ok (SELF-AVATAR fix)')