Refactored app state

This commit is contained in:
Davide Passoni
2024-10-21 19:02:33 +02:00
parent 4946807d88
commit 14c0a2f1e8
27 changed files with 1070 additions and 1056 deletions

View File

@@ -48,6 +48,8 @@ export abstract class UnitDatabase {
}
getBlueprints(includeDisabled: boolean = false) {
if (!getApp()) return {};
if (
getApp().getMissionManager().getCommandModeOptions().commandMode == GAME_MASTER ||
!getApp().getMissionManager().getCommandModeOptions().restrictSpawns

View File

@@ -25,7 +25,6 @@ import {
DLINK,
DataIndexes,
GAME_MASTER,
IDLE,
IRST,
OPTIC,
RADAR,
@@ -38,10 +37,10 @@ import {
GROUPING_ZOOM_TRANSITION,
MAX_SHOTS_SCATTER,
SHOTS_SCATTER_DEGREES,
CONTEXT_ACTION,
SELECT_JTAC_TARGET,
ContextActionColors,
CONTEXT_ACTION_COLORS,
OlympusState,
JTACSubState,
} from "../constants/constants";
import { DataExtractor } from "../server/dataextractor";
import { groundUnitDatabase } from "./databases/groundunitdatabase";
@@ -1384,18 +1383,18 @@ export abstract class Unit extends CustomMarker {
#onShortPress(e: LeafletMouseEvent) {
console.log(`Short press on ${this.getUnitName()}`);
if (getApp().getMap().getState() === IDLE || e.originalEvent.ctrlKey) {
if (getApp().getState() === OlympusState.IDLE || e.originalEvent.ctrlKey) {
if (!e.originalEvent.ctrlKey) getApp().getUnitsManager().deselectAllUnits();
this.setSelected(!this.getSelected());
} else if (getApp().getMap().getState() === CONTEXT_ACTION) {
} else if (getApp().getState() === OlympusState.UNIT_CONTROL) {
if (getApp().getMap().getContextAction()) getApp().getMap().executeContextAction(this, null);
else {
getApp().getUnitsManager().deselectAllUnits();
this.setSelected(!this.getSelected());
}
} else if (getApp().getMap().getState() === SELECT_JTAC_TARGET) {
} else if (getApp().getState() === OlympusState.JTAC && getApp().getSubState() === JTACSubState.SELECT_TARGET) {
document.dispatchEvent(new CustomEvent("selectJTACTarget", { detail: { unit: this } }));
getApp().getMap().setState(IDLE);
getApp().setState(OlympusState.IDLE);
}
}

View File

@@ -19,7 +19,7 @@ import {
} from "../other/utils";
import { CoalitionPolygon } from "../map/coalitionarea/coalitionpolygon";
import { groundUnitDatabase } from "./databases/groundunitdatabase";
import { CONTEXT_ACTION, DELETE_CYCLE_TIME, DELETE_SLOW_THRESHOLD, DataIndexes, GAME_MASTER, IADSDensities, IDLE } from "../constants/constants";
import { DELETE_CYCLE_TIME, DELETE_SLOW_THRESHOLD, DataIndexes, GAME_MASTER, IADSDensities, OlympusState } from "../constants/constants";
import { DataExtractor } from "../server/dataextractor";
import { citiesDatabase } from "./databases/citiesdatabase";
import { aircraftDatabase } from "./databases/aircraftdatabase";
@@ -1461,10 +1461,9 @@ export class UnitsManager {
let newContextActionSet = new ContextActionSet();
this.getSelectedUnits().forEach((unit) => unit.appendContextActions(newContextActionSet));
getApp().getMap().setState(CONTEXT_ACTION, {
contextAction: null,
defaultContextAction: newContextActionSet.getDefaultContextAction(),
});
getApp().getMap().setContextAction(null);
getApp().getMap().setDefaultContextAction(newContextActionSet.getDefaultContextAction());
getApp().setState(OlympusState.UNIT_CONTROL);
this.#selectionEventDisabled = false;
this.#showNumberOfSelectedProtectedUnits();
@@ -1472,14 +1471,15 @@ export class UnitsManager {
this.#selectionEventDisabled = true;
}
} else {
getApp().getMap().setState(IDLE);
getApp().setState(OlympusState.IDLE);
document.dispatchEvent(new CustomEvent("clearSelection"));
}
}
#onUnitDeselection(unit: Unit) {
if (this.getSelectedUnits().length == 0) {
getApp().getMap().setState(IDLE);
if (getApp().getState() === OlympusState.UNIT_CONTROL)
getApp().setState(OlympusState.IDLE);
document.dispatchEvent(new CustomEvent("clearSelection"));
} else {
/* Disable the firing of the selection event for a certain amount of time. This avoids firing many events if many units are selected */