From 97ef81b399543ceac7020b9a28d207ecfb1fb353 Mon Sep 17 00:00:00 2001 From: ralfisalhon Date: Tue, 17 Mar 2026 05:48:42 +0000 Subject: [PATCH] Rename centers to positions --- .../graphics/layers/AttackingTroopsOverlay.ts | 20 +++++++++---------- src/core/GameRunner.ts | 4 ++-- src/core/game/GameView.ts | 2 +- src/core/worker/WorkerClient.ts | 4 ++-- src/core/worker/WorkerMessages.ts | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/client/graphics/layers/AttackingTroopsOverlay.ts b/src/client/graphics/layers/AttackingTroopsOverlay.ts index 60be22c57..679cf7ffd 100644 --- a/src/client/graphics/layers/AttackingTroopsOverlay.ts +++ b/src/client/graphics/layers/AttackingTroopsOverlay.ts @@ -51,8 +51,6 @@ export class AttackingTroopsOverlay implements Layer { } init() { - // The container is anchored at the viewport centre (50%, 50%) so that - // label transforms can use raw world coordinates without an extra offset. this.container = document.createElement("div"); this.container.style.position = "fixed"; this.container.style.left = "50%"; @@ -137,10 +135,10 @@ export class AttackingTroopsOverlay implements Layer { void myPlayer .attackFrontLinePositions() .then((attacks) => { - for (const { id, centers } of attacks) { + for (const { id, positions } of attacks) { const lbl = this.labels.get(id); if (!lbl) continue; - this.reconcileLabelPositions(lbl, centers); + this.reconcileLabelPositions(lbl, positions); } }) .catch(() => { @@ -209,8 +207,8 @@ export class AttackingTroopsOverlay implements Layer { // position (greedy nearest-neighbour matching). This prevents labels from // swapping front-line segments when their relative sizes change between ticks, // which would otherwise cause visible jumping. - private reconcileLabelPositions(lbl: AttackLabel, centers: Cell[]) { - const availableCenterIndexes = centers.map((_, i) => i); + private reconcileLabelPositions(lbl: AttackLabel, positions: Cell[]) { + const availableCenterIndexes = positions.map((_, i) => i); const updatedPositions: (Cell | null)[] = []; for ( @@ -221,7 +219,7 @@ export class AttackingTroopsOverlay implements Layer { const currentPos = lbl.positions[elementIndex]; if (!currentPos) { // Element has no position yet — assign the first available center. - updatedPositions.push(centers[availableCenterIndexes.shift()!]); + updatedPositions.push(positions[availableCenterIndexes.shift()!]); continue; } @@ -229,7 +227,7 @@ export class AttackingTroopsOverlay implements Layer { let closestCenterAt = 0; let closestDistance = Infinity; for (let i = 0; i < availableCenterIndexes.length; i++) { - const candidate = centers[availableCenterIndexes[i]]; + const candidate = positions[availableCenterIndexes[i]]; const dx = candidate.x - currentPos.x; const dy = candidate.y - currentPos.y; const squaredDistance = dx * dx + dy * dy; @@ -239,11 +237,11 @@ export class AttackingTroopsOverlay implements Layer { } } updatedPositions.push( - centers[availableCenterIndexes.splice(closestCenterAt, 1)[0]], + positions[availableCenterIndexes.splice(closestCenterAt, 1)[0]], ); } - // Create new label elements for centers that had no existing element to match. + // Create new label elements for positions that had no existing element to match. for (const centerIndex of availableCenterIndexes) { lbl.elements.push( this.createLabelElement( @@ -252,7 +250,7 @@ export class AttackingTroopsOverlay implements Layer { lbl.isIncoming, ), ); - updatedPositions.push(centers[centerIndex]); + updatedPositions.push(positions[centerIndex]); } // Remove elements for front-line segments that no longer exist. diff --git a/src/core/GameRunner.ts b/src/core/GameRunner.ts index f1752bdcc..52c973687 100644 --- a/src/core/GameRunner.ts +++ b/src/core/GameRunner.ts @@ -257,7 +257,7 @@ export class GameRunner { public attackFrontLinePositions( playerID: number, attackID?: string, - ): { id: string; centers: { x: number; y: number }[] }[] { + ): { id: string; positions: { x: number; y: number }[] }[] { const player = this.game.playerBySmallID(playerID); if (!player.isPlayer()) { throw new Error(`player with id ${playerID} not found`); @@ -273,7 +273,7 @@ export class GameRunner { return attacks.map((a) => ({ id: a.id(), - centers: a.frontLinePositions().map((tile) => ({ + positions: a.frontLinePositions().map((tile) => ({ x: this.game.map().x(tile), y: this.game.map().y(tile), })), diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index 513fcde14..c6f55472c 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -459,7 +459,7 @@ export class PlayerView { async attackFrontLinePositions( attackID?: string, - ): Promise<{ id: string; centers: Cell[] }[]> { + ): Promise<{ id: string; positions: Cell[] }[]> { return this.game.worker.attackFrontLinePositions(this.smallID(), attackID); } diff --git a/src/core/worker/WorkerClient.ts b/src/core/worker/WorkerClient.ts index b070bcca9..5a445331d 100644 --- a/src/core/worker/WorkerClient.ts +++ b/src/core/worker/WorkerClient.ts @@ -269,7 +269,7 @@ export class WorkerClient { attackFrontLinePositions( playerID: number, attackID?: string, - ): Promise<{ id: string; centers: Cell[] }[]> { + ): Promise<{ id: string; positions: Cell[] }[]> { return new Promise((resolve, reject) => { if (!this.isInitialized) { reject(new Error("Worker not initialized")); @@ -296,7 +296,7 @@ export class WorkerClient { resolve( message.attacks.map((a) => ({ id: a.id, - centers: a.centers.map((c) => new Cell(c.x, c.y)), + positions: a.positions.map((c) => new Cell(c.x, c.y)), })), ); }); diff --git a/src/core/worker/WorkerMessages.ts b/src/core/worker/WorkerMessages.ts index 20b89a4c6..d00663d69 100644 --- a/src/core/worker/WorkerMessages.ts +++ b/src/core/worker/WorkerMessages.ts @@ -131,7 +131,7 @@ export interface AttackFrontLinePositionsMessage extends BaseWorkerMessage { export interface AttackFrontLinePositionsResultMessage extends BaseWorkerMessage { type: "attack_front_line_positions_result"; - attacks: { id: string; centers: { x: number; y: number }[] }[]; + attacks: { id: string; positions: { x: number; y: number }[] }[]; } export interface TransportShipSpawnMessage extends BaseWorkerMessage {