mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-22 23:08:02 +00:00
Clean up and refactor the Unit class (#769)
## Description: * Merged similar fields so they can be reused (eg warshipTarget => targetUnit) * simplified isCooldown api * added "touch" method to send update to UI layer * standardized on "undefined" ## Please complete the following: - [ ] I have added screenshots for all UI updates - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: <DISCORD USERNAME> evan <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Unified and simplified how unit targets and cooldowns are managed across all unit types, resulting in more consistent in-game behavior for nukes, warships, trade ships, and SAM launchers. - Updated naming and logic for unit targeting and cooldowns, improving clarity in status displays and interactions. - Reorganized unit interface and streamlined cooldown handling for smoother gameplay experience. - **Bug Fixes** - Corrected visual indicators for nukes and warships to accurately reflect their targets. - **Tests** - Updated automated tests to align with the new cooldown and targeting logic. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -8,7 +8,6 @@ import {
|
||||
GameUpdates,
|
||||
Gold,
|
||||
NameViewData,
|
||||
nukeTypes,
|
||||
Player,
|
||||
PlayerActions,
|
||||
PlayerBorderTiles,
|
||||
@@ -83,7 +82,7 @@ export class UnitView {
|
||||
return this.data.pos;
|
||||
}
|
||||
owner(): PlayerView {
|
||||
return this.gameView.playerBySmallID(this.data.ownerID) as PlayerView;
|
||||
return this.gameView.playerBySmallID(this.data.ownerID)! as PlayerView;
|
||||
}
|
||||
isActive(): boolean {
|
||||
return this.data.isActive;
|
||||
@@ -97,20 +96,11 @@ export class UnitView {
|
||||
constructionType(): UnitType | undefined {
|
||||
return this.data.constructionType;
|
||||
}
|
||||
dstPortId(): number | undefined {
|
||||
return this.data.dstPortId;
|
||||
targetUnitId(): number | undefined {
|
||||
return this.data.targetUnitId;
|
||||
}
|
||||
detonationDst(): TileRef | undefined {
|
||||
if (!nukeTypes.includes(this.type())) {
|
||||
throw Error("Must be a nuke");
|
||||
}
|
||||
return this.data.detonationDst;
|
||||
}
|
||||
warshipTargetId(): number | undefined {
|
||||
if (this.type() !== UnitType.Warship) {
|
||||
throw Error("Must be a warship");
|
||||
}
|
||||
return this.data.warshipTargetId;
|
||||
targetTile(): TileRef | undefined {
|
||||
return this.data.targetTile;
|
||||
}
|
||||
ticksLeftInCooldown(): Tick | undefined {
|
||||
return this.data.ticksLeftInCooldown;
|
||||
|
||||
Reference in New Issue
Block a user