From 07b69fe96f52500f8277f9b1f6959b7f621fca1a Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Sat, 12 Aug 2023 19:31:08 +0100 Subject: [PATCH] Added dbl-click select but it's buggy AF --- client/src/unit/unit.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/client/src/unit/unit.ts b/client/src/unit/unit.ts index 3a3f2cd4..7d972ee1 100644 --- a/client/src/unit/unit.ts +++ b/client/src/unit/unit.ts @@ -567,6 +567,18 @@ export class Unit extends CustomMarker { return false; } + isInViewport() { + + const mapBounds = getMap().getBounds(); + const unitPos = this.getPosition(); + + return ( unitPos.lng > mapBounds.getWest() + && unitPos.lng < mapBounds.getEast() + && unitPos.lat > mapBounds.getSouth() + && unitPos.lat < mapBounds.getNorth() ); + + } + /********************** Unit commands *************************/ addDestination(latlng: L.LatLng) { if (!this.#human) { @@ -707,6 +719,7 @@ export class Unit extends CustomMarker { /***********************************************/ #onClick(e: any) { if (!this.#preventClick) { + console.log( getMap().getState() ); if (getMap().getState() === IDLE || getMap().getState() === MOVE_UNIT || e.originalEvent.ctrlKey) { if (!e.originalEvent.ctrlKey) { @@ -716,10 +729,10 @@ export class Unit extends CustomMarker { const unitIsSelected = !this.getSelected(); this.setSelected( unitIsSelected ); - - - // Tell everyone a unit (de-)selection has happened, usually a panel or something. + + // Tell everyone a unit (de-)selection has happened, usually a panel or something. + // const detail = { "detail": { "unit": this @@ -741,6 +754,18 @@ export class Unit extends CustomMarker { } #onDoubleClick(e: any) { + + const unitsManager = getUnitsManager(); + + Object.values( unitsManager.getUnits() ).forEach( ( unit:Unit ) => { + + if ( unit.getAlive() === true && unit.getControlled() && unit.getName() === this.getName() && unit.isInViewport() ) { + unitsManager.selectUnit( unit.ID, false ); + } + + }); + + clearTimeout(this.#timer); this.#preventClick = true; }