mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 09:14:09 +00:00
use tileref instead of MapPos for UnitUpdate
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user