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 <evanpelle@gmail.com>
This commit is contained in:
Vivacious Box
2025-07-03 01:12:54 +02:00
committed by GitHub
parent dd8e9468f4
commit 9b0e1b04a4
2 changed files with 25 additions and 1 deletions
+5 -1
View File
@@ -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,
+20
View File
@@ -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();