diff --git a/src/models/Settings.ts b/src/models/Settings.ts index eb75adc..776dc4a 100644 --- a/src/models/Settings.ts +++ b/src/models/Settings.ts @@ -44,7 +44,7 @@ export class Settings { this.maxDistance = contents.maxDistance; } - static get(isPackaged: boolean): Settings { + static get(isPackaged: boolean = false): Settings { if (!Settings.#instance) { Settings.#instance = new Settings(isPackaged); } diff --git a/src/models/System.ts b/src/models/System.ts index 6f854e6..52cff9d 100755 --- a/src/models/System.ts +++ b/src/models/System.ts @@ -1,44 +1,44 @@ -import type { completeFsdJump, location, navRouteSystem } from "../@types/journalLines" +import type { completeFsdJump, location, navRouteSystem } from '../@types/journalLines'; -import * as _ from 'lodash-es' +import * as _ from 'lodash-es'; -import { Body } from "./Body" -import { EDSM } from "./EDSM" +import { Body } from './Body'; +import { EDSM } from './EDSM'; export class System { - name: string - SystemAddress?: number - StarClass?: string - charted: boolean - bodies: Body[] + name: string; + SystemAddress?: number; + StarClass?: string; + charted: boolean; + bodies: Body[]; // ESDM data - estimatedValue?: number - estimatedValueMapped?: number - valuableBodies?: Body[] + estimatedValue?: number; + estimatedValueMapped?: number; + valuableBodies?: Body[]; constructor(line?: navRouteSystem|completeFsdJump|location) { // In future, this is where we preform EDSM lookup if (!line) { - this.name = 'Unknown' + this.name = 'Unknown'; } else { - this.name = line.StarSystem - this.SystemAddress = line.SystemAddress + this.name = line.StarSystem; + this.SystemAddress = line.SystemAddress; if ('StarClass' in line) { - this.StarClass = line.StarClass + this.StarClass = line.StarClass; } } // Set this to true initially, since it likely is and the system is technically inserted // into the UI before it's appraised. - this.charted = true - this.bodies = [] + this.charted = true; + this.bodies = []; if (this.name !== 'Unknown') { - this.#getValue() + this.#getValue(); } } @@ -46,32 +46,36 @@ export class System { async #getValue() { // display estimatedValueMapped - const data = await EDSM.getSystemValue(this) + const data = await EDSM.getSystemValue(this); if (data) { - this.estimatedValue = data.estimatedValue - this.estimatedValueMapped = data.estimatedValueMapped + this.estimatedValue = data.estimatedValue; + this.estimatedValueMapped = data.estimatedValueMapped; // If EDSM doesn't have an estimate, then it's likely undiscovered. - this.charted = this.estimatedValue > 0 + this.charted = this.estimatedValue > 0; // Save valuable bodies in system, if any. if (data.valuableBodies.length > 0) { - this.valuableBodies = [] + this.valuableBodies = []; data.valuableBodies.forEach((body) => { - this.valuableBodies?.push(new Body(body)) - }) + this.valuableBodies?.push(new Body(body)); + }); } // Let the UI know it needs to update. - EDSM.connect().emit('SYSTEM_APPRAISED', this) + EDSM.connect().emit('SYSTEM_APPRAISED', this); } } /* -------------------------------------------------------------------------- sortBodies ---- */ sortBodies(): void { - this.bodies = _.orderBy(this.bodies, ['mappedValue'], ['desc']) + this.bodies = _.orderBy( + this.bodies, + ['mappedValue', 'DistanceFromArrivalLS'], + ['desc', 'desc'], + ); } } \ No newline at end of file diff --git a/src/models/UI.js b/src/models/UI.js index 897c3db..ca50983 100755 --- a/src/models/UI.js +++ b/src/models/UI.js @@ -1,176 +1,186 @@ +import { Settings } from './Settings'; + export class UI { constructor() {} /* ----------------------------------------------------------------------- #formatNumber ---- */ static #formatNumber(number) { - return Intl.NumberFormat().format(Math.round(number)) + return Intl.NumberFormat().format(Math.round(number)); } /* --------------------------------------------------------------------- enterWitchSpace ---- */ static enterWitchSpace() { - $('#scans').children().remove() + $('#scans').children().remove(); - $('#currentSystem').removeClass('charted').addClass('highlighted text-center') - $('#currentSystemIcon').addClass('hidden') + $('#currentSystem').removeClass('charted').addClass('highlighted text-center'); + $('#currentSystemIcon').addClass('hidden'); - $('#currentSystemName').text('> > > Hyperspace < < <') + $('#currentSystemName').text('> > > Hyperspace < < <'); } /* -------------------------------------------------------------------- setCurrentSystem ---- */ static setCurrentSystem(system) { - $('#scans').children().remove() - $('#currentSystem').children().remove() + $('#scans').children().remove(); + $('#currentSystem').children().remove(); - let row + let row; if (system.name === 'Unknown') { - row = $('