mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-23 23:13:40 +00:00
Fix user having to click 3-4x times before building is deleted (#2195)
## Description: There is a 5 second cooldown between building deletions (as was proposed here: https://github.com/openfrontio/OpenFrontIO/pull/1609#issuecomment-3146188728). But this cooldown is only checked when in DeleteUnitExecution from canDeleteUnit in PlayerImpl. The delete button in RadialMenuElements always gets True back from canDeleteUnit in GameView. This results in a user seeing an enabled Delete button after just deleting another building. And being able to click it, but no deletion would happen. So they have to click 3-4 times before it 'works'. Fix: also apply the 5s cooldown when deciding to disable the button. In the fix in canDeleteUnit in GameView, added +1 to the current game tick. So the Delete button is enabled 1 tick before DeleteUnitExecution would get True back from canDeleteUnit in PlayerImpl. Between seeing and clicking the button is probably 1 tick anyway, and sometimes also after clicking it and the execution it takes another tick so this is safe. Also tested the other way around: after deletion the button should immediately not be visible, while it can take 2 ticks before GameView gets lastDeleteUnitTick back from PlayerImpl. But since the Radial menu is closed after clicking the button, i couldn't open it fast enough again to still see the button enabled (ie. it was always already neatly disabled). And if someone with an auto-clicker were to be able to click it still, their attempt would still be blocked by the cooldown check in DeleteUnitExecution. BEFORE: https://github.com/user-attachments/assets/17242c39-982e-47c6-89f2-6fe22a296c7d AFTER: https://github.com/user-attachments/assets/dfe20111-3313-4ad2-95a9-0152c0270c08 ## 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: tryout33 --------- Co-authored-by: evanpelle <evanpelle@gmail.com>
This commit is contained in:
@@ -169,6 +169,7 @@ export interface PlayerUpdate {
|
||||
alliances: AllianceView[];
|
||||
hasSpawned: boolean;
|
||||
betrayals?: bigint;
|
||||
lastDeleteUnitTick: Tick;
|
||||
}
|
||||
|
||||
export interface AllianceView {
|
||||
|
||||
@@ -426,8 +426,15 @@ export class PlayerView {
|
||||
return this.data.isDisconnected;
|
||||
}
|
||||
|
||||
lastDeleteUnitTick(): Tick {
|
||||
return this.data.lastDeleteUnitTick;
|
||||
}
|
||||
|
||||
canDeleteUnit(): boolean {
|
||||
return true;
|
||||
return (
|
||||
this.game.ticks() + 1 - this.lastDeleteUnitTick() >=
|
||||
this.game.config().deleteUnitCooldown()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,6 +174,7 @@ export class PlayerImpl implements Player {
|
||||
),
|
||||
hasSpawned: this.hasSpawned(),
|
||||
betrayals: stats?.betrayals,
|
||||
lastDeleteUnitTick: this.lastDeleteUnitTick,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user