From 9b0e1b04a4bd5af2c287f7b03d6db9d777a37bbf Mon Sep 17 00:00:00 2001 From: Vivacious Box Date: Thu, 3 Jul 2025 01:12:54 +0200 Subject: [PATCH] fix healthbars not being removed (#1329) ## Description: Warships being nuked doesnt remove the healthbar ![image](https://github.com/user-attachments/assets/67d40a5b-255b-45ea-9b5d-4f5441ff271a) ## 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 - [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: Vivacious Box --------- Co-authored-by: evanpelle --- src/client/graphics/layers/UILayer.ts | 6 +++++- tests/client/graphics/UILayer.test.ts | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/client/graphics/layers/UILayer.ts b/src/client/graphics/layers/UILayer.ts index a743c5ae7..f3ba9711f 100644 --- a/src/client/graphics/layers/UILayer.ts +++ b/src/client/graphics/layers/UILayer.ts @@ -340,7 +340,11 @@ export class UILayer implements Layer { // full hp/dead warships dont need a hp bar this.allHealthBars.get(unit.id())?.clear(); this.allHealthBars.delete(unit.id()); - } else if (unit.health() < maxHealth && unit.health() > 0) { + } else if ( + unit.isActive() && + unit.health() < maxHealth && + unit.health() > 0 + ) { this.allHealthBars.get(unit.id())?.clear(); const healthBar = new ProgressBar( COLOR_PROGRESSION, diff --git a/tests/client/graphics/UILayer.test.ts b/tests/client/graphics/UILayer.test.ts index dbc131cec..0a31d69be 100644 --- a/tests/client/graphics/UILayer.test.ts +++ b/tests/client/graphics/UILayer.test.ts @@ -83,6 +83,26 @@ describe("UILayer", () => { expect(ui["allHealthBars"].has(1)).toBe(false); }); + it("should remove health bars for inactive units", () => { + const ui = new UILayer(game, eventBus, transformHandler); + ui.redraw(); + const unit = { + id: () => 1, + type: () => "Warship", + health: () => 5, + tile: () => ({}), + owner: () => ({}), + isActive: () => true, + } as unknown as UnitView; + ui.drawHealthBar(unit); + expect(ui["allHealthBars"].has(1)).toBe(true); + + // an inactive unit doesnt have a health bar + unit.isActive = () => false; + ui.drawHealthBar(unit); + expect(ui["allHealthBars"].has(1)).toBe(false); + }); + it("should add loading bar for unit", () => { const ui = new UILayer(game, eventBus, transformHandler); ui.redraw();