From 3055378b86007e524d4fcd60112459a7fe9db120 Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Tue, 15 Aug 2023 11:19:44 +0200 Subject: [PATCH] Minimal code refactoring --- .../public/stylesheets/other/contextmenus.css | 2 - client/src/controls/airbasecontextmenu.ts | 132 ++++++++---------- client/src/mission/missionhandler.ts | 5 - 3 files changed, 62 insertions(+), 77 deletions(-) diff --git a/client/public/stylesheets/other/contextmenus.css b/client/public/stylesheets/other/contextmenus.css index 3e2ad830..8ba2c64d 100644 --- a/client/public/stylesheets/other/contextmenus.css +++ b/client/public/stylesheets/other/contextmenus.css @@ -448,8 +448,6 @@ width: 100%; } - - /* Airbase context menu */ #airbase-contextmenu #airbase-runways { display:flex; diff --git a/client/src/controls/airbasecontextmenu.ts b/client/src/controls/airbasecontextmenu.ts index 19a32a1c..0d00d17d 100644 --- a/client/src/controls/airbasecontextmenu.ts +++ b/client/src/controls/airbasecontextmenu.ts @@ -22,80 +22,16 @@ export class AirbaseContextMenu extends ContextMenu { setAirbase(airbase: Airbase) { this.#airbase = airbase; - this.setName(airbase.getName()); - this.setProperties(airbase.getProperties()); - this.setParkings(airbase.getParkings()); - this.setCoalition(airbase.getCoalition()); - this.enableLandButton(getUnitsManager().getSelectedUnitsTypes().length == 1 && ["Aircraft", "Helicopter"].includes(getUnitsManager().getSelectedUnitsTypes()[0]) && (getUnitsManager().getSelectedUnitsCoalition() === airbase.getCoalition() || airbase.getCoalition() === "neutral")) + this.setName(this.#airbase.getName()); + this.setProperties(this.#airbase.getProperties()); + this.setParkings(this.#airbase.getParkings()); + this.setCoalition(this.#airbase.getCoalition()); + this.enableLandButton(getUnitsManager().getSelectedUnitsTypes().length == 1 && ["Aircraft", "Helicopter"].includes(getUnitsManager().getSelectedUnitsTypes()[0]) && (getUnitsManager().getSelectedUnitsCoalition() === this.#airbase.getCoalition() || this.#airbase.getCoalition() === "neutral")) this.enableSpawnButton(getMissionHandler().getCommandModeOptions().commandMode == GAME_MASTER || this.#airbase.getCoalition() == getMissionHandler().getCommandedCoalition()); - - - dataPointMap( this.getContainer(), { - "coalition": airbase.getCoalition(), - "airbaseName": airbase.getName() - }); - dataPointMap( this.getContainer(), this.#airbase.getChartData() ); + this.#setAirbaseData(); - const runwaysContainer = this.getContainer()?.querySelector( "#airbase-runways" ); - runwaysContainer.innerHTML = ""; - - if ( runwaysContainer instanceof HTMLElement ) { - - const runways = this.#airbase.getChartData().runways; - - if ( runways.length === 0 ) { - runwaysContainer.innerText = "No data"; - } else { - runways.forEach( runway => { - - let runwayDiv = document.createElement( "div" ); - runwayDiv.classList.add( "runway" ); - - runway.headings.forEach( headings => { - - //* - for ( const [ heading, data ] of Object.entries( headings ) ) { - - let headingDiv = document.createElement( "div" ); - headingDiv.classList.add( "heading" ); - - let abbr = document.createElement( "abbr" ); - abbr.title = `Mag heading: ${data.magHeading}`; - abbr.innerText = heading; - - headingDiv.appendChild( abbr ); - - runwayDiv.appendChild( headingDiv ); - - if ( data.ILS ) { - let ilsDiv = document.createElement( "div" ); - ilsDiv.classList.add( "ils" ); - - abbr = document.createElement( "abbr" ); - abbr.title = data.ILS; - abbr.innerText = "ILS"; - - ilsDiv.appendChild( abbr ); - headingDiv.appendChild( ilsDiv ); - } - - - } - //*/ - - }); - - runwaysContainer.appendChild( runwayDiv ); - - }); - } - - } - this.clip(); - - } setName(airbaseName: string) { @@ -144,4 +80,60 @@ export class AirbaseContextMenu extends ContextMenu { getMap().getMapContextMenu().setLatLng(this.#airbase.getLatLng()); } } + + #setAirbaseData() { + if (this.#airbase && this.getContainer()) { + dataPointMap(this.getContainer() as HTMLElement, { + "coalition": this.#airbase.getCoalition(), + "airbaseName": this.#airbase.getName() + }); + + dataPointMap( this.getContainer() as HTMLElement, this.#airbase.getChartData() ); + + const runwaysContainer = this.getContainer()?.querySelector( "#airbase-runways" ) as HTMLElement; + runwaysContainer.innerHTML = ""; + + if ( runwaysContainer instanceof HTMLElement ) { + const runways = this.#airbase.getChartData().runways; + + if ( runways.length === 0 ) { + runwaysContainer.innerText = "No data"; + } else { + runways.forEach( runway => { + let runwayDiv = document.createElement( "div" ); + runwayDiv.classList.add( "runway" ); + + runway.headings.forEach( headings => { + for ( const [ heading, data ] of Object.entries( headings ) ) { + + let headingDiv = document.createElement( "div" ); + headingDiv.classList.add( "heading" ); + + let abbr = document.createElement( "abbr" ); + abbr.title = `Mag heading: ${data.magHeading}`; + abbr.innerText = heading; + + headingDiv.appendChild( abbr ); + runwayDiv.appendChild( headingDiv ); + + if ( data.ILS ) { + let ilsDiv = document.createElement( "div" ); + ilsDiv.classList.add( "ils" ); + + abbr = document.createElement( "abbr" ); + abbr.title = data.ILS; + abbr.innerText = "ILS"; + + ilsDiv.appendChild( abbr ); + headingDiv.appendChild( ilsDiv ); + } + } + }); + + runwaysContainer.appendChild( runwayDiv ); + }); + } + } + } + } } \ No newline at end of file diff --git a/client/src/mission/missionhandler.ts b/client/src/mission/missionhandler.ts index 77e32f07..ebadaa82 100644 --- a/client/src/mission/missionhandler.ts +++ b/client/src/mission/missionhandler.ts @@ -235,9 +235,7 @@ export class MissionHandler { getMap().showAirbaseContextMenu(e.originalEvent.x, e.originalEvent.y, e.latlng, e.sourceTarget); } - #loadAirbaseChartData() { - if ( !this.#theatre ) { return; } @@ -264,8 +262,5 @@ export class MissionHandler { } }); - - } - } \ No newline at end of file