From 2b155c4ed3b22761bc9878e14220907275aa46df Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Wed, 17 May 2023 19:36:12 +0100 Subject: [PATCH 1/2] ATC clocks now synched to mission time --- client/src/atc/atc.ts | 8 ++- client/src/atc/atcboard.ts | 19 ++++++- client/src/missionhandler/missionhandler.ts | 63 +++++++++++++++++++++ client/src/units/aircraftdatabase.ts | 2 +- 4 files changed, 87 insertions(+), 5 deletions(-) diff --git a/client/src/atc/atc.ts b/client/src/atc/atc.ts index e85c1ee2..1597ca7e 100644 --- a/client/src/atc/atc.ts +++ b/client/src/atc/atc.ts @@ -1,3 +1,5 @@ +import { getMissionData } from ".."; +import { getConnected } from "../server/server"; import { ATCBoard } from "./atcboard"; import { ATCBoardGround } from "./board/ground"; import { ATCBoardTower } from "./board/tower"; @@ -48,6 +50,10 @@ class ATCDataHandler { this.#updateInterval = window.setInterval( () => { + if ( !getConnected() ) { + return; + } + const aBoardIsVisible = this.#atc.getBoards().some( board => board.boardIsVisible() ); if ( aBoardIsVisible ) { @@ -135,7 +141,7 @@ export class ATC { getMissionDateTime() : Date { - return new Date( this.getMissionStartDateTime().getTime() + this.getMissionElapsedSeconds() ); + return new Date( getMissionData().getNowDate() ); } diff --git a/client/src/atc/atcboard.ts b/client/src/atc/atcboard.ts index 79586def..959874ab 100644 --- a/client/src/atc/atcboard.ts +++ b/client/src/atc/atcboard.ts @@ -2,9 +2,10 @@ import { Dropdown } from "../controls/dropdown"; import { zeroAppend } from "../other/utils"; import { ATC } from "./atc"; import { Unit } from "../units/unit"; -import { getUnitsManager } from ".."; +import { getMissionData, getUnitsManager } from ".."; import Sortable from "sortablejs"; import { FlightInterface } from "./atc"; +import { getConnected } from "../server/server"; export interface StripBoardStripInterface { "id": string, @@ -84,6 +85,10 @@ export abstract class ATCBoard { window.setInterval( () => { + + if ( !getConnected() ) { + return; + } this.updateClock(); }, 1000 ); @@ -410,6 +415,10 @@ export abstract class ATCBoard { this.#updateInterval = window.setInterval( () => { + if ( !getConnected() ) { + return; + } + this.update(); }, this.#updateIntervalDelay ); @@ -446,8 +455,12 @@ export abstract class ATCBoard { updateClock() { - const now = this.#atc.getMissionDateTime(); - this.#clockElement.innerText = now.toLocaleTimeString(); + const missionTime = this.#atc.getMissionDateTime().getTime(); + const timeDiff = new Date().getTime() - getMissionData().getUpdateTime(); + + const nowDate = new Date( missionTime + timeDiff ); + + this.#clockElement.innerText = nowDate.toLocaleTimeString(); } diff --git a/client/src/missionhandler/missionhandler.ts b/client/src/missionhandler/missionhandler.ts index 66233f0a..22051aa3 100644 --- a/client/src/missionhandler/missionhandler.ts +++ b/client/src/missionhandler/missionhandler.ts @@ -16,6 +16,14 @@ export class MissionHandler #airbasesMarkers: {[name: string]: Airbase}; #theatre : string = ""; + // Time + #date : any; + #elapsedTime : any; + #startTime : any; + #time : any; + + #updateTime : any; + constructor() { this.#bullseyes = undefined; @@ -50,7 +58,30 @@ export class MissionHandler getInfoPopup().setText("Map set to " + this.#theatre); } + + if ( "date" in data.mission ) { + this.#date = data.mission.date; + } + + if ( "elapsedTime" in data.mission ) { + this.#elapsedTime = data.mission.elapsedTime; + } + + if ( "startTime" in data.mission ) { + this.#startTime = data.mission.startTime; + } + + if ( "time" in data.mission ) { + this.#time = data.mission.time; + } + } + + + if ( "time" in data ) { + this.#updateTime = data.time; + } + } getBullseyes() @@ -90,6 +121,38 @@ export class MissionHandler } } + + getDate() { + return this.#date; + } + + + getNowDate() { + const date = this.getDate(); + const time = this.getTime(); + + let year = date.Year; + let month = date.Month - 1; + + if ( month < 0 ) { + month = 11; + year--; + } + + return new Date( year, month, date.Day, time.h, time.m, time.s ); + } + + + getTime() { + return this.#time; + } + + + getUpdateTime() { + return this.#updateTime; + } + + #onAirbaseClick(e: any) { getMap().showAirbaseContextMenu(e, e.sourceTarget); diff --git a/client/src/units/aircraftdatabase.ts b/client/src/units/aircraftdatabase.ts index b738b4b6..f2448468 100644 --- a/client/src/units/aircraftdatabase.ts +++ b/client/src/units/aircraftdatabase.ts @@ -322,7 +322,7 @@ export class AircraftDatabase extends UnitDatabase { }, "H-6J": { "name": "H-6J", - "label": "H-6J Badger, + "label": "H-6J Badger", "era": ["Mid Cold War, Late Cold War", "Modern"], "shortLabel": "H6", "loadouts": [ From 05a8085e065694ef9daab723a09a1582f0520969 Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Sat, 20 May 2023 22:17:04 +0100 Subject: [PATCH 2/2] ATC now 'live'; added visual improvemnts. --- client/public/stylesheets/atc.css | 12 ++++++++++- client/src/featureswitches.ts | 24 ++++++++++++--------- client/src/missionhandler/missionhandler.ts | 5 +++++ client/views/atc/board.ejs | 7 ++---- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/client/public/stylesheets/atc.css b/client/public/stylesheets/atc.css index c19e19fd..e9fa7441 100644 --- a/client/public/stylesheets/atc.css +++ b/client/public/stylesheets/atc.css @@ -1,4 +1,8 @@ - +.ol-strip-board .ol-dialog-header { + align-items: center; + display:flex; + justify-content: space-between; +} .ol-strip-board-strips { display:flex; @@ -178,6 +182,7 @@ .ol-strip-board-add-flight .ol-auto-suggest[data-has-suggestions] { display:flex; + row-gap: 4px; } .ol-strip-board-add-flight .ol-auto-suggest[data-has-suggestions] a { @@ -192,4 +197,9 @@ [data-board-type="tower"] { right:10px; top:10px; +} + +[data-board-type="tower"] .ol-auto-suggest { + top:30px; + translate:0; } \ No newline at end of file diff --git a/client/src/featureswitches.ts b/client/src/featureswitches.ts index c5776683..600a17a2 100644 --- a/client/src/featureswitches.ts +++ b/client/src/featureswitches.ts @@ -1,7 +1,7 @@ export interface FeatureSwitchInterface { - "defaultEnabled": boolean, // default on/off state (if allowed by masterSwitch) + "defaultEnabled": boolean, // default on/off state (if allowed by forceState) + "forceState": number, // -1 don't force; 0 force off; 1 force on "label": string, - "masterSwitch": boolean, // on/off regardless of user preference "name": string, "onEnabled"?: CallableFunction, "options"?: object, @@ -13,8 +13,8 @@ class FeatureSwitch { // From config param defaultEnabled; + forceState = -1; label; - masterSwitch; name; onEnabled; removeArtifactsIfDisabled = true; @@ -26,8 +26,8 @@ class FeatureSwitch { constructor( config:FeatureSwitchInterface ) { this.defaultEnabled = config.defaultEnabled; + this.forceState = config.forceState; this.label = config.label; - this.masterSwitch = config.masterSwitch; this.name = config.name; this.onEnabled = config.onEnabled; @@ -47,10 +47,14 @@ class FeatureSwitch { isEnabled() { - if ( !this.masterSwitch ) { + if ( this.forceState === 0 ) { return false; } + if ( this.forceState === 1 ) { + return true; + } + return this.userPreference; } @@ -62,37 +66,37 @@ export class FeatureSwitches { new FeatureSwitch({ "defaultEnabled": false, + "forceState": -1, "label": "AIC", - "masterSwitch": true, "name": "aic" }), new FeatureSwitch({ "defaultEnabled": false, + "forceState": -1, "label": "AI Formations", - "masterSwitch": true, "name": "ai-formations", "removeArtifactsIfDisabled": false }), new FeatureSwitch({ "defaultEnabled": false, + "forceState": 1, "label": "ATC", - "masterSwitch": true, "name": "atc" }), new FeatureSwitch({ "defaultEnabled": false, + "forceState": -1, "label": "Force show unit control panel", - "masterSwitch": true, "name": "forceShowUnitControlPanel" }), new FeatureSwitch({ "defaultEnabled": true, + "forceState": -1, "label": "Show splash screen", - "masterSwitch": true, "name": "splashScreen" }) diff --git a/client/src/missionhandler/missionhandler.ts b/client/src/missionhandler/missionhandler.ts index 22051aa3..ba6ef35a 100644 --- a/client/src/missionhandler/missionhandler.ts +++ b/client/src/missionhandler/missionhandler.ts @@ -128,8 +128,13 @@ export class MissionHandler getNowDate() { + const date = this.getDate(); const time = this.getTime(); + + if ( !date ) { + return new Date(); + } let year = date.Year; let month = date.Month - 1; diff --git a/client/views/atc/board.ejs b/client/views/atc/board.ejs index 007b91f2..58d3dfcc 100644 --- a/client/views/atc/board.ejs +++ b/client/views/atc/board.ejs @@ -1,9 +1,10 @@ -
+

<%= boardType %>

+ <%- include('addflight.ejs') %>
@@ -18,8 +19,4 @@
- -
\ No newline at end of file