have buildings take time to construct

This commit is contained in:
Evan
2025-02-08 13:53:58 -08:00
parent 0487509c03
commit 1594a45dac
13 changed files with 216 additions and 82 deletions
+18
View File
@@ -12,6 +12,8 @@ export class UnitImpl implements Unit {
private _health: number;
private _lastTile: TileRef = null;
private _constructionType: UnitType = undefined;
constructor(
private _type: UnitType,
private mg: GameImpl,
@@ -36,6 +38,7 @@ export class UnitImpl implements Unit {
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) },
health: this.hasHealth() ? this._health : undefined,
constructionType: this._constructionType,
};
}
@@ -116,6 +119,21 @@ export class UnitImpl implements Unit {
return this._active;
}
constructionType(): UnitType | null {
if (this.type() != UnitType.Construction) {
throw new Error(`Cannot get construction type on ${this.type()}`);
}
return this._constructionType;
}
setConstructionType(type: UnitType): void {
if (this.type() != UnitType.Construction) {
throw new Error(`Cannot set construction type on ${this.type()}`);
}
this._constructionType = type;
this.mg.addUpdate(this.toUpdate());
}
hash(): number {
return this.tile() + simpleHash(this.type());
}