pike/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Files 9fbef6e294d737de91c700aa68f14bfc493d2019
| 1 | /** |
| 2 | * Your five, always. |
| 3 | * |
| 4 | * Who is on your team and who is still standing must not depend on whether |
| 5 | * you can see them — for most of a round you cannot see anybody. Every team |
| 6 | * mate is in every snapshot already (the server shows you your own side), so |
| 7 | * this is a read of what is there: a fixed order, health clamped, and the |
| 8 | * dead marked. |
| 9 | */ |
| 10 | |
| 11 | /** The player's own team, in a stable order, ready to draw as rows. */ |
| 12 | export function roster(snap) { |
| 13 | if (!snap || !snap.players) return []; |
| 14 | return snap.players |
| 15 | .filter((p) => p.mate) |
| 16 | .map((p) => ({ |
| 17 | id: p.id, |
| 18 | name: p.name, |
| 19 | agent: p.agent, |
| 20 | hp: p.alive ? Math.max(0, Math.min(100, p.hp)) : 0, |
| 21 | alive: p.alive === true, |
| 22 | spike: p.spike === true, |
| 23 | mine: p.id === snap.me.id, |
| 24 | })) |
| 25 | .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)); |
| 26 | } |
| 27 | |
| 28 | /** Enough of the roster to know when the panel has to be rebuilt. */ |
| 29 | export const rosterKey = (rows) => |
| 30 | rows.map((r) => `${r.id}:${r.agent}:${Math.round(r.hp)}:${r.alive ? 1 : 0}:${r.spike ? 1 : 0}`).join("|"); |