From c9c34f013f2c2c3294ea2f0aec56f0918cd352ea Mon Sep 17 00:00:00 2001 From: Davide Passoni Date: Fri, 20 Dec 2024 16:21:35 +0100 Subject: [PATCH] fix: hotgroup button updated when unit dies --- frontend/react/src/ui/panels/hotgroupsbar.tsx | 4 +--- frontend/react/src/unit/unitsmanager.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/react/src/ui/panels/hotgroupsbar.tsx b/frontend/react/src/ui/panels/hotgroupsbar.tsx index c892ccf5..88c1fa6f 100644 --- a/frontend/react/src/ui/panels/hotgroupsbar.tsx +++ b/frontend/react/src/ui/panels/hotgroupsbar.tsx @@ -7,10 +7,8 @@ import { Unit } from "../../unit/unit"; export function HotGroupBar(props: {}) { const [hotgroups, setHotgroups] = useState({} as { [key: number]: Unit[] }); - const [appState, setAppState] = useState(OlympusState.NOT_INITIALIZED); useEffect(() => { - AppStateChangedEvent.on((state, subState) => setAppState(state)); HotgroupsChangedEvent.on((hotgroups) => setHotgroups({ ...hotgroups })); }, []); @@ -38,7 +36,7 @@ export function HotGroupBar(props: {}) { - {units.length} + {units.filter((unit) => unit.getAlive()).length} diff --git a/frontend/react/src/unit/unitsmanager.ts b/frontend/react/src/unit/unitsmanager.ts index 3f06d1be..e220082a 100644 --- a/frontend/react/src/unit/unitsmanager.ts +++ b/frontend/react/src/unit/unitsmanager.ts @@ -32,6 +32,7 @@ import { SelectedUnitsChangedEvent, SelectionClearedEvent, SessionDataLoadedEvent, + UnitDeadEvent, UnitDeselectedEvent, UnitSelectedEvent, UnitsRefreshed, @@ -74,6 +75,10 @@ export class UnitsManager { UnitSelectedEvent.on((unit) => this.#onUnitSelection(unit)); UnitDeselectedEvent.on((unit) => this.#onUnitDeselection(unit)); + UnitDeadEvent.on((unit) => { + if (unit.getHotgroup()) HotgroupsChangedEvent.dispatch(this.getHotgroups()); + }); + SessionDataLoadedEvent.on((sessionData) => { UnitsRefreshed.on(() => { const localSessionData = deepCopyTable(sessionData); @@ -1154,7 +1159,10 @@ export class UnitsManager { if (units === null) units = this.getSelectedUnits(); units.forEach((unit: Unit) => unit.setHotgroup(hotgroup)); this.#showActionMessage(units, `added to hotgroup ${hotgroup}`); + HotgroupsChangedEvent.dispatch(this.getHotgroups()); + } + getHotgroups() { let hotgroups: { [key: number]: Unit[] } = {}; for (let ID in this.#units) { const unit = this.#units[ID]; @@ -1167,7 +1175,7 @@ export class UnitsManager { } } } - HotgroupsChangedEvent.dispatch(hotgroups); + return hotgroups; } /** Delete the selected units