feat: WarShips red color outside if target current player

Hard to know when warship captures your trade so if they target one of
your trade or war ship they are highlighted in red.
Known limitation: doesn't work well if the WarShip is already in red
(player's color)
This commit is contained in:
ilan schemoul
2025-03-04 00:46:22 +01:00
parent 9fd1203d50
commit d2208755c4
6 changed files with 38 additions and 9 deletions
+13 -8
View File
@@ -1,4 +1,4 @@
import { Colord } from "colord";
import { colord, Colord } from "colord";
import { Theme } from "../../../core/configuration/Config";
import { Unit, UnitType, Player } from "../../../core/game/Game";
import { Layer } from "./Layer";
@@ -240,15 +240,20 @@ export class UnitLayer implements Layer {
return;
}
let outerColor = this.theme.territoryColor(unit.owner().info());
if (unit.targetId()) {
const targetOwner = this.game
.units()
.find((u) => u.id() == unit.targetId())
.owner();
if (targetOwner == this.myPlayer) {
outerColor = colord({ r: 200, b: 0, g: 0 });
}
}
// Paint outer territory
for (const t of this.game.bfs(unit.tile(), euclDistFN(unit.tile(), 5))) {
this.paintCell(
this.game.x(t),
this.game.y(t),
rel,
this.theme.territoryColor(unit.owner().info()),
255,
);
this.paintCell(this.game.x(t), this.game.y(t), rel, outerColor, 255);
}
// Paint border