From 69fc14f1fd4d1ad3c6ca81341c24b26a2b95f90f Mon Sep 17 00:00:00 2001 From: VariableVince <24507472+VariableVince@users.noreply.github.com> Date: Tue, 14 Oct 2025 20:18:50 +0200 Subject: [PATCH] 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 --- src/core/game/GameUpdates.ts | 1 + src/core/game/GameView.ts | 9 ++++++++- src/core/game/PlayerImpl.ts | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/game/GameUpdates.ts b/src/core/game/GameUpdates.ts index 54fae1b1e..f117e210a 100644 --- a/src/core/game/GameUpdates.ts +++ b/src/core/game/GameUpdates.ts @@ -169,6 +169,7 @@ export interface PlayerUpdate { alliances: AllianceView[]; hasSpawned: boolean; betrayals?: bigint; + lastDeleteUnitTick: Tick; } export interface AllianceView { diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index c15887a86..d6ed3730d 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -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() + ); } } diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index d2287d886..d9ba8ba7c 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -174,6 +174,7 @@ export class PlayerImpl implements Player { ), hasSpawned: this.hasSpawned(), betrayals: stats?.betrayals, + lastDeleteUnitTick: this.lastDeleteUnitTick, }; }