mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-20 17:20:05 +00:00
fix: store embargoes as smallID numbers (drop string[] wart)
PlayerState.embargoes was string[] of stringified smallIDs — the renderer parsed each entry with parseInt() to use as an array index. Flagged in the integration handoff as something that should be number[]. Switch to number[] end-to-end: renderer type, relation-matrix derive (no parseInt), PlayerView.setEmbargoSmallIDs / hasEmbargoAgainst (numeric Array.includes, no String() temporaries), and GameView's embargo translation pass. Also updates the PlayerView test that pinned the old format.
This commit is contained in:
@@ -64,8 +64,8 @@ function staticFromUpdate(pu: PlayerUpdate): PlayerStatic {
|
||||
}
|
||||
|
||||
function stateFromUpdate(pu: PlayerUpdate): PlayerState {
|
||||
// embargoes: Set<PlayerID strings> on the wire, but the renderer expects
|
||||
// stringified smallIDs. GameView fills these in via setEmbargoes() because
|
||||
// embargoes: Set<PlayerID strings> 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 {
|
||||
|
||||
Reference in New Issue
Block a user