mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Minimal code refactoring
This commit is contained in:
@@ -121,18 +121,15 @@ export class UnitControlPanel extends Panel {
|
||||
button.classList.add("pill", "highlight-coalition")
|
||||
|
||||
button.addEventListener("click", ( ev:MouseEventInit ) => {
|
||||
|
||||
// Ctrl-click deselection
|
||||
if ( ev.ctrlKey === true && ev.shiftKey === false && ev.altKey === false ) {
|
||||
getUnitsManager().deselectUnit( unit.ID );
|
||||
button.remove();
|
||||
|
||||
// Deselect all
|
||||
} else {
|
||||
getUnitsManager().deselectAllUnits();
|
||||
getUnitsManager().selectUnit(unit.ID, true);
|
||||
}
|
||||
|
||||
});
|
||||
return (button);
|
||||
}));
|
||||
|
||||
@@ -708,28 +708,15 @@ export class Unit extends CustomMarker {
|
||||
#onClick(e: any) {
|
||||
if (!this.#preventClick) {
|
||||
if (getMap().getState() === IDLE || getMap().getState() === MOVE_UNIT || e.originalEvent.ctrlKey) {
|
||||
|
||||
if (!e.originalEvent.ctrlKey) {
|
||||
if (!e.originalEvent.ctrlKey)
|
||||
getUnitsManager().deselectAllUnits();
|
||||
}
|
||||
|
||||
const unitIsSelected = !this.getSelected();
|
||||
|
||||
this.setSelected( unitIsSelected );
|
||||
|
||||
|
||||
// Tell everyone a unit (de-)selection has happened, usually a panel or something.
|
||||
|
||||
const detail = {
|
||||
"detail": this
|
||||
};
|
||||
|
||||
if ( unitIsSelected ) {
|
||||
document.dispatchEvent( new CustomEvent( "unitSelection", detail ) );
|
||||
this.setSelected( !this.getSelected() );
|
||||
if ( this.getSelected() ) {
|
||||
document.dispatchEvent( new CustomEvent( "unitSelection", { "detail": this }));
|
||||
} else {
|
||||
document.dispatchEvent( new CustomEvent( "unitDeselection", detail ) );
|
||||
document.dispatchEvent( new CustomEvent( "unitDeselection", { "detail": this }));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,13 +197,11 @@ export class UnitsManager {
|
||||
}
|
||||
|
||||
deselectUnit( ID:number ) {
|
||||
|
||||
if ( this.#units.hasOwnProperty( ID ) ) {
|
||||
this.#units[ID].setSelected(false);
|
||||
} else {
|
||||
console.error( `deselectUnit(): no unit found with ID "${ID}".` );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
selectUnitsByHotgroup(hotgroup: number) {
|
||||
|
||||
Reference in New Issue
Block a user