update views

This commit is contained in:
Evan
2025-02-01 12:05:11 -08:00
parent dab427d614
commit f988d555bb
10 changed files with 233 additions and 206 deletions
+14 -1
View File
@@ -1,4 +1,5 @@
import { MessageType } from "../../client/graphics/layers/EventsDisplay";
import { UnitViewData, ViewData, ViewSerializable } from "../GameView";
import { simpleHash, within } from "../Util";
import { MutableUnit, Tile, TerraNullius, UnitType, Player, UnitInfo } from "./Game";
import { GameImpl } from "./GameImpl";
@@ -6,7 +7,7 @@ import { PlayerImpl } from "./PlayerImpl";
import { TerraNulliusImpl } from "./TerraNulliusImpl";
export class UnitImpl implements MutableUnit {
export class UnitImpl implements MutableUnit, ViewSerializable<UnitViewData> {
private _active = true;
private _health: number
@@ -21,6 +22,18 @@ export class UnitImpl implements MutableUnit {
this._health = (this.g.unitInfo(_type).maxHealth ?? 2) / 2
}
toViewData(): ViewData<UnitViewData> {
return {
type: this._type,
troops: this._troops,
x: this.tile().cell().x,
y: this.tile().cell().y,
owner: this.owner().id(),
isActive: this.isActive(),
health: this._health,
}
}
type(): UnitType {
return this._type
}