From fb2ecc75ebda91a013d4af9dd724642f789e9df0 Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Sun, 17 Dec 2023 19:42:30 +0000 Subject: [PATCH] FL now has three digits --- client/src/other/utils.ts | 8 ++++++++ client/src/unit/unit.ts | 4 ++-- client/src/weapon/weapon.ts | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/src/other/utils.ts b/client/src/other/utils.ts index 21fb2360..74866674 100644 --- a/client/src/other/utils.ts +++ b/client/src/other/utils.ts @@ -104,6 +104,14 @@ export function reciprocalHeading(heading: number): number { return heading > 180? heading - 180: heading + 180; } +/** + * Prepend numbers to the start of a string + * + * @param num subject number + * @param places places to pad + * @param decimal whether this is a decimal number or not + * + * */ export const zeroAppend = function (num: number, places: number, decimal: boolean = false) { var string = decimal? num.toFixed(2): String(num); while (string.length < places) { diff --git a/client/src/unit/unit.ts b/client/src/unit/unit.ts index b4a92c63..6166ce41 100644 --- a/client/src/unit/unit.ts +++ b/client/src/unit/unit.ts @@ -1,6 +1,6 @@ import { Marker, LatLng, Polyline, Icon, DivIcon, CircleMarker, Map, Point } from 'leaflet'; import { getApp } from '..'; -import { enumToCoalition, enumToEmissioNCountermeasure, enumToROE, enumToReactionToThreat, enumToState, getUnitDatabaseByCategory, mToFt, msToKnots, rad2deg, bearing, deg2rad, ftToM, getGroundElevation, coalitionToEnum, nmToFt, nmToM } from '../other/utils'; +import { enumToCoalition, enumToEmissioNCountermeasure, enumToROE, enumToReactionToThreat, enumToState, getUnitDatabaseByCategory, mToFt, msToKnots, rad2deg, bearing, deg2rad, ftToM, getGroundElevation, coalitionToEnum, nmToFt, nmToM, zeroAppend } from '../other/utils'; import { CustomMarker } from '../map/markers/custommarker'; import { SVGInjector } from '@tanem/svg-injector'; import { UnitDatabase } from './databases/unitdatabase'; @@ -1184,7 +1184,7 @@ export abstract class Unit extends CustomMarker { /* Set altitude and speed */ if (element.querySelector(".unit-altitude")) - (element.querySelector(".unit-altitude")).innerText = "FL" + String(Math.floor(mToFt(this.#position.alt as number) / 100)); + (element.querySelector(".unit-altitude")).innerText = "FL" + zeroAppend(Math.floor(mToFt(this.#position.alt as number) / 100), 3); if (element.querySelector(".unit-speed")) (element.querySelector(".unit-speed")).innerText = String(Math.floor(msToKnots(this.#speed))) + "GS"; diff --git a/client/src/weapon/weapon.ts b/client/src/weapon/weapon.ts index 2930f3b4..b157cff4 100644 --- a/client/src/weapon/weapon.ts +++ b/client/src/weapon/weapon.ts @@ -1,6 +1,6 @@ import { LatLng, DivIcon, Map } from 'leaflet'; import { getApp } from '..'; -import { enumToCoalition, mToFt, msToKnots, rad2deg } from '../other/utils'; +import { enumToCoalition, mToFt, msToKnots, rad2deg, zeroAppend } from '../other/utils'; import { CustomMarker } from '../map/markers/custommarker'; import { SVGInjector } from '@tanem/svg-injector'; import { DLINK, DataIndexes, GAME_MASTER, IRST, OPTIC, RADAR, VISUAL } from '../constants/constants'; @@ -230,7 +230,7 @@ export class Weapon extends CustomMarker { /* Set altitude and speed */ if (element.querySelector(".unit-altitude")) - (element.querySelector(".unit-altitude")).innerText = "FL" + String(Math.floor(mToFt(this.#position.alt as number) / 100)); + (element.querySelector(".unit-altitude")).innerText = "FL" + zeroAppend(Math.floor(mToFt(this.#position.alt as number) / 100), 3); if (element.querySelector(".unit-speed")) (element.querySelector(".unit-speed")).innerText = String(Math.floor(msToKnots(this.#speed))) + "GS";