diff --git a/src/client/render/frame/derive/relation-matrix.ts b/src/client/render/frame/derive/relation-matrix.ts index f0eca51eb..ca3b7dcb8 100644 --- a/src/client/render/frame/derive/relation-matrix.ts +++ b/src/client/render/frame/derive/relation-matrix.ts @@ -67,8 +67,7 @@ export function buildRelationMatrix( } if (ps.embargoes) { - for (const eStr of ps.embargoes) { - const eID = parseInt(eStr, 10); + for (const eID of ps.embargoes) { if (eID > 0 && eID < RELATION_SIZE) { matrix[sid * RELATION_SIZE + eID] = RELATION_EMBARGO; matrix[eID * RELATION_SIZE + sid] = RELATION_EMBARGO; diff --git a/src/client/render/types/renderer.ts b/src/client/render/types/renderer.ts index 14b873207..be262a75f 100644 --- a/src/client/render/types/renderer.ts +++ b/src/client/render/types/renderer.ts @@ -63,7 +63,7 @@ export interface PlayerState { hasSpawned: boolean; lastDeleteUnitTick: number; allies: number[]; - embargoes: string[]; + embargoes: number[]; targets: number[]; outgoingAttacks: AttackData[]; incomingAttacks: AttackData[]; diff --git a/src/client/view/GameView.ts b/src/client/view/GameView.ts index 0e70bb85c..497ad7463 100644 --- a/src/client/view/GameView.ts +++ b/src/client/view/GameView.ts @@ -342,14 +342,14 @@ export class GameView implements GameMap { gu.updates[GameUpdateType.Player].forEach((pu) => { const player = this._players.get(pu.id); if (player === undefined) return; - const smallIDStrings: string[] = []; + const smallIDs: number[] = []; for (const otherPlayerID of pu.embargoes) { const otherPV = this._players.get(otherPlayerID); if (otherPV !== undefined) { - smallIDStrings.push(String(otherPV.smallID())); + smallIDs.push(otherPV.smallID()); } } - player.setEmbargoSmallIDs(smallIDStrings); + player.setEmbargoSmallIDs(smallIDs); }); if (this._myClientID) { diff --git a/src/client/view/PlayerView.ts b/src/client/view/PlayerView.ts index 6c2272d99..2e49d9916 100644 --- a/src/client/view/PlayerView.ts +++ b/src/client/view/PlayerView.ts @@ -64,8 +64,8 @@ function staticFromUpdate(pu: PlayerUpdate): PlayerStatic { } function stateFromUpdate(pu: PlayerUpdate): PlayerState { - // embargoes: Set on the wire, but the renderer expects - // stringified smallIDs. GameView fills these in via setEmbargoes() because + // embargoes: Set on the wire, but the renderer stores + // smallIDs (numbers). GameView fills these in via setEmbargoes() because // it has the PlayerID → smallID lookup table. return { smallID: pu.smallID, @@ -249,9 +249,9 @@ export class PlayerView { applyStateUpdate(this.state, pu); } - /** Set the renderer-format embargoes (stringified smallIDs). */ - setEmbargoSmallIDs(smallIDStrings: string[]): void { - this.state.embargoes = smallIDStrings; + /** Set the renderer-format embargoes (smallIDs). */ + setEmbargoSmallIDs(smallIDs: number[]): void { + this.state.embargoes = smallIDs; } territoryColor(tile?: TileRef): Colord { @@ -493,8 +493,7 @@ export class PlayerView { } hasEmbargoAgainst(other: PlayerView): boolean { - const otherSmallIDStr = String(other.smallID()); - return this.state.embargoes.includes(otherSmallIDStr); + return this.state.embargoes.includes(other.smallID()); } hasEmbargo(other: PlayerView): boolean { diff --git a/tests/client/view/PlayerView.test.ts b/tests/client/view/PlayerView.test.ts index 4acea7a61..c41b0d5be 100644 --- a/tests/client/view/PlayerView.test.ts +++ b/tests/client/view/PlayerView.test.ts @@ -152,8 +152,8 @@ describe("PlayerView relations", () => { aTeam?: string; bTeam?: string; // Embargoes are renderer-format: stringified smallIDs of the OTHER player. - aEmbargoSmallIDs?: string[]; - bEmbargoSmallIDs?: string[]; + aEmbargoSmallIDs?: number[]; + bEmbargoSmallIDs?: number[]; aOutgoingReq?: string[]; } = {}, ) { @@ -207,7 +207,7 @@ describe("PlayerView relations", () => { it("hasEmbargoAgainst / hasEmbargo are symmetric on the second", () => { // a embargoes b — by smallID (renderer format) - const aEmbargoesB = pair(1, 2, { aEmbargoSmallIDs: ["2"] }); + const aEmbargoesB = pair(1, 2, { aEmbargoSmallIDs: [2] }); // One-way directional embargo from a expect(aEmbargoesB.a.hasEmbargoAgainst(aEmbargoesB.b)).toBe(true); expect(aEmbargoesB.b.hasEmbargoAgainst(aEmbargoesB.a)).toBe(false);