mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-20 03:32:14 +00:00
Add deletion duration and indicators (#2216)
## Description: Adds a timer before self deleting units Adds a loading bar under deleting units Adds a timer in radial menu for clarity purposes  ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: Mr.Box --------- Co-authored-by: Evan <evanpelle@gmail.com>
This commit is contained in:
@@ -39,6 +39,7 @@ export class UnitImpl implements Unit {
|
||||
// Nuke only
|
||||
private _trajectoryIndex: number = 0;
|
||||
private _trajectory: TrajectoryTile[];
|
||||
private _deletionAt: number | null = null;
|
||||
|
||||
constructor(
|
||||
private _type: UnitType,
|
||||
@@ -126,6 +127,7 @@ export class UnitImpl implements Unit {
|
||||
reachedTarget: this._reachedTarget,
|
||||
retreating: this._retreating,
|
||||
pos: this._tile,
|
||||
markedForDeletion: this._deletionAt ?? false,
|
||||
targetable: this._targetable,
|
||||
lastPos: this._lastTile,
|
||||
health: this.hasHealth() ? Number(this._health) : undefined,
|
||||
@@ -182,6 +184,7 @@ export class UnitImpl implements Unit {
|
||||
}
|
||||
|
||||
setOwner(newOwner: PlayerImpl): void {
|
||||
this.clearPendingDeletion();
|
||||
switch (this._type) {
|
||||
case UnitType.Warship:
|
||||
case UnitType.Port:
|
||||
@@ -221,6 +224,30 @@ export class UnitImpl implements Unit {
|
||||
}
|
||||
}
|
||||
|
||||
clearPendingDeletion(): void {
|
||||
this._deletionAt = null;
|
||||
}
|
||||
|
||||
isMarkedForDeletion(): boolean {
|
||||
return this._deletionAt !== null;
|
||||
}
|
||||
|
||||
markForDeletion(): void {
|
||||
if (!this.isActive()) {
|
||||
return;
|
||||
}
|
||||
this._deletionAt =
|
||||
this.mg.ticks() + this.mg.config().deletionMarkDuration();
|
||||
this.mg.addUpdate(this.toUpdate());
|
||||
}
|
||||
|
||||
isOverdueDeletion(): boolean {
|
||||
if (!this.isActive()) {
|
||||
return false;
|
||||
}
|
||||
return this._deletionAt !== null && this.mg.ticks() - this._deletionAt > 0;
|
||||
}
|
||||
|
||||
delete(displayMessage?: boolean, destroyer?: Player): void {
|
||||
if (!this.isActive()) {
|
||||
throw new Error(`cannot delete ${this} not active`);
|
||||
|
||||
Reference in New Issue
Block a user