From 4a93c1eead551c3cc546f766dcc416d62f389a39 Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Wed, 17 May 2023 16:59:36 +0100 Subject: [PATCH 1/4] Added (crude) confirm function --- client/src/index.ts | 1 + client/src/units/unit.ts | 1 - client/src/units/unitsmanager.ts | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/src/index.ts b/client/src/index.ts index b3e7e63e..0e927822 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -94,6 +94,7 @@ function readConfig(config: any) { } function setupEvents() { + /* Generic clicks */ document.addEventListener("click", (ev) => { if (ev instanceof MouseEvent && ev.target instanceof HTMLElement) { diff --git a/client/src/units/unit.ts b/client/src/units/unit.ts index 82d10681..6b3830c6 100644 --- a/client/src/units/unit.ts +++ b/client/src/units/unit.ts @@ -371,7 +371,6 @@ export class Unit extends Marker { } delete() { - // TODO: add confirmation popup deleteUnit(this.ID); } diff --git a/client/src/units/unitsmanager.ts b/client/src/units/unitsmanager.ts index 62ac5db6..9c05e34b 100644 --- a/client/src/units/unitsmanager.ts +++ b/client/src/units/unitsmanager.ts @@ -19,7 +19,7 @@ export class UnitsManager { document.addEventListener('paste', () => this.pasteUnits()); document.addEventListener('unitSelection', (e: CustomEvent) => this.#onUnitSelection(e.detail)); document.addEventListener('unitDeselection', (e: CustomEvent) => this.#onUnitDeselection(e.detail)); - document.addEventListener('keydown', (event) => this.#onKeyDown(event)); + document.addEventListener('keyup', (event) => this.#onKeyUp(event)); document.addEventListener('deleteSelectedUnits', () => this.selectedUnitsDelete()) } @@ -329,8 +329,8 @@ export class UnitsManager { } /***********************************************/ - #onKeyDown(event: KeyboardEvent) { - if (!keyEventWasInInput(event) && event.key === "Delete") { + #onKeyUp(event: KeyboardEvent) { + if (!keyEventWasInInput(event) && event.key === "Delete" && confirm( "Are you sure you want to delete?" ) ) { this.selectedUnitsDelete(); } } From 4e9eab2cce1bf8b2459931d7458e70d74abc13ab Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Wed, 24 May 2023 21:38:35 +0100 Subject: [PATCH 2/4] Warning now only shows when humans are in the selection. --- client/src/units/unitsmanager.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/client/src/units/unitsmanager.ts b/client/src/units/unitsmanager.ts index 9c05e34b..80699b05 100644 --- a/client/src/units/unitsmanager.ts +++ b/client/src/units/unitsmanager.ts @@ -330,8 +330,17 @@ export class UnitsManager { /***********************************************/ #onKeyUp(event: KeyboardEvent) { - if (!keyEventWasInInput(event) && event.key === "Delete" && confirm( "Are you sure you want to delete?" ) ) { - this.selectedUnitsDelete(); + if (!keyEventWasInInput(event) && event.key === "Delete" ) { + + const selectedUnits = this.getSelectedUnits(); + const selectionContainsAHuman = selectedUnits.some( ( unit:Unit ) => { + return unit.getBaseData().AI === false; + }); + + if ( !selectionContainsAHuman || confirm( "Your selection includes a human player. Deleting humans causes their vehicle to crash.\n\nAre you sure you want to do this?" ) ) { + this.selectedUnitsDelete(); + } + } } From e6d642994c1617dba15fc3b0dd99ce5acec56fc5 Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Wed, 24 May 2023 21:55:09 +0100 Subject: [PATCH 3/4] Improved check for humans --- client/src/units/unitsmanager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/units/unitsmanager.ts b/client/src/units/unitsmanager.ts index 80699b05..9fc61fde 100644 --- a/client/src/units/unitsmanager.ts +++ b/client/src/units/unitsmanager.ts @@ -334,7 +334,7 @@ export class UnitsManager { const selectedUnits = this.getSelectedUnits(); const selectionContainsAHuman = selectedUnits.some( ( unit:Unit ) => { - return unit.getBaseData().AI === false; + return unit.getMissionData().flags.human === true; }); if ( !selectionContainsAHuman || confirm( "Your selection includes a human player. Deleting humans causes their vehicle to crash.\n\nAre you sure you want to do this?" ) ) { From a5a2a803c69a82940e72788c951edcd16b0d3621 Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Wed, 24 May 2023 23:13:47 +0100 Subject: [PATCH 4/4] Fixed casing. --- client/src/units/unitsmanager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/units/unitsmanager.ts b/client/src/units/unitsmanager.ts index 9fc61fde..f7f3443e 100644 --- a/client/src/units/unitsmanager.ts +++ b/client/src/units/unitsmanager.ts @@ -334,7 +334,7 @@ export class UnitsManager { const selectedUnits = this.getSelectedUnits(); const selectionContainsAHuman = selectedUnits.some( ( unit:Unit ) => { - return unit.getMissionData().flags.human === true; + return unit.getMissionData().flags.Human === true; }); if ( !selectionContainsAHuman || confirm( "Your selection includes a human player. Deleting humans causes their vehicle to crash.\n\nAre you sure you want to do this?" ) ) {