use tileref instead of MapPos for UnitUpdate

This commit is contained in:
Evan
2025-02-12 16:22:02 -08:00
parent 5c85ac36fc
commit 421c6e7841
4 changed files with 11 additions and 11 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ export class TerritoryLayer implements Layer {
this.game.updatesSinceLastTick()[GameUpdateType.Unit].forEach((u) => {
const update = u as UnitUpdate;
if (update.unitType == UnitType.DefensePost && update.isActive) {
const tile = this.game.ref(update.pos.x, update.pos.y);
const tile = update.pos;
this.game
.bfs(
tile,
+3 -3
View File
@@ -10,7 +10,7 @@ import {
Tick,
UnitType,
} from "./Game";
import { TileUpdate } from "./GameMap";
import { TileRef, TileUpdate } from "./GameMap";
export interface GameUpdateViewData {
tick: number;
@@ -63,8 +63,8 @@ export interface UnitUpdate {
id: number;
ownerID: number;
// TODO: make these tilerefs
pos: MapPos;
lastPos: MapPos;
pos: TileRef;
lastPos: TileRef;
isActive: boolean;
health?: number;
constructionType?: UnitType;
+5 -5
View File
@@ -34,7 +34,7 @@ import { DefenseGrid } from "./DefensePostGrid";
export class UnitView {
public _wasUpdated = true;
public lastPos: MapPos[] = [];
public lastPos: TileRef[] = [];
constructor(
private gameView: GameView,
@@ -48,14 +48,14 @@ export class UnitView {
}
lastTiles(): TileRef[] {
return this.lastPos.map((pos) => this.gameView.ref(pos.x, pos.y));
return this.lastPos;
}
lastTile(): TileRef {
if (this.lastPos.length == 0) {
return this.gameView.ref(this.data.pos.x, this.data.pos.y);
return this.data.pos;
}
return this.gameView.ref(this.lastPos[0].x, this.lastPos[0].y);
return this.lastPos[0];
}
update(data: UnitUpdate) {
@@ -75,7 +75,7 @@ export class UnitView {
return this.data.troops;
}
tile(): TileRef {
return this.gameView.ref(this.data.pos.x, this.data.pos.y);
return this.data.pos;
}
owner(): PlayerView {
return this.gameView.playerBySmallID(this.data.ownerID) as PlayerView;
+2 -2
View File
@@ -35,8 +35,8 @@ export class UnitImpl implements Unit {
troops: this._troops,
ownerID: this._owner.smallID(),
isActive: this._active,
pos: { x: this.mg.x(this._tile), y: this.mg.y(this._tile) },
lastPos: { x: this.mg.x(this._lastTile), y: this.mg.y(this._lastTile) },
pos: this._tile,
lastPos: this._lastTile,
health: this.hasHealth() ? this._health : undefined,
constructionType: this._constructionType,
};