Adjusting body highlight to match settings.

This commit is contained in:
punkfairie 2023-05-13 16:01:46 -07:00
parent 26b112ae9a
commit e519bdbcdf
4 changed files with 158 additions and 172 deletions

View file

@ -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);
}

View file

@ -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'],
);
}
}

View file

@ -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 = $('<div>').addClass('row ms-1 me-1')
const child = $('<div>').addClass('col system highlighted text-center')
child.text(system.name)
row.appendChild(child)
row = $('<div>').addClass('row ms-1 me-1');
const child = $('<div>').addClass('col system highlighted text-center');
child.text(system.name);
row.appendChild(child);
} else {
row = UI.createSystemRow(system)
row = UI.createSystemRow(system);
}
$('#currentSystem').appendChild(row)
$('#currentSystem').appendChild(row);
}
/* -------------------------------------------------------------------------- buildRings ---- */
static #buildRings(body) {
const rings = $('<span>')
const seperator = $('<span>').text(' ) ')
rings.appendChild(seperator)
const rings = $('<span>');
const seperator = $('<span>').text(' ) ');
rings.appendChild(seperator);
body.Rings.forEach((ring) => {
const ringClass = ring.RingClass.replace('eRingClass_', '')
let icon = null
const ringClass = ring.RingClass.replace('eRingClass_', '');
let icon = null;
switch (ringClass) {
case 'MetalRich': {
icon = 'gold-bars'
break
icon = 'gold-bars';
break;
}
case 'Metalic':
case 'Metallic': {
icon = 'ingot'
break
icon = 'ingot';
break;
}
case 'Icy': {
icon = 'snowflake'
break
icon = 'snowflake';
break;
}
case 'Rocky': {
icon = 'asteroid-3'
break
icon = 'asteroid-3';
break;
}
}
if (icon !== null) {
rings.appendChild($('<i>').addClass(`flaticon-${icon}`))
rings.appendChild(seperator)
rings.appendChild($('<i>').addClass(`flaticon-${icon}`));
rings.appendChild(seperator);
}
})
return rings
return rings;
}
/* ----------------------------------------------------------------------- createBodyRow ---- */
static createBodyRow(body) {
const chartedStyle = body.WasDiscovered && !body.DSSDone ? 'charted' : 'uncharted'
// TODO USER SETTINGS
const valuableStyle = body.mappedValue > 2000 ? 'highlighted' : ''
const chartedStyle = body.WasDiscovered && !body.DSSDone ? 'charted' : 'uncharted';
const row = $('<div>').addClass('row ms-1 me-1')
row.attr('id', body.bodyID)
const settings = Settings.get();
let valuableStyle = '';
if (
body.mappedValue > settings.minValue
&& body.DistanceFromArrivalLS < settings.maxDistance
) {
valuableStyle = 'highlighted';
}
const row = $('<div>').addClass('row ms-1 me-1');
row.attr('id', body.bodyID);
// spacer
row.appendChild($('<div>').addClass('col-1 system'))
row.appendChild($('<div>').addClass('col-1 system'));
// name
const name = $('<div>').addClass(`col-2 text-start system ${chartedStyle} ${valuableStyle}`)
name.appendChild($('<i>')).addClass(`flaticon-${body.nameIcon()}`)
name.appendChild($('<span>')).text(body.simpleName())
row.appendChild(name)
const name = $('<div>');
name.addClass(`col-2 text-start system ${chartedStyle} ${valuableStyle}`)
name.appendChild($('<i>')).addClass(`flaticon-${body.nameIcon()}`);
name.appendChild($('<span>')).text(body.simpleName());
row.appendChild(name);
// type icon
const type = $('<div>').addClass(`col pe-0 me-0 system ${chartedStyle} ${valuableStyle}`)
type.appendChild($('<i>').addClass(`flaticon-${body.typeIcon()}`))
const type = $('<div>').addClass(`col pe-0 me-0 system ${chartedStyle} ${valuableStyle}`);
type.appendChild($('<i>').addClass(`flaticon-${body.typeIcon()}`));
// rings
if (body.Rings !== undefined) {
type.appendChild(UI.#buildRings(body))
type.appendChild(UI.#buildRings(body));
}
// type
const typeName = body.PlanetClass || body.starType || ''
type.appendChild($('<span>').text(` ${typeName}`))
row.appendChild(type)
const typeName = body.PlanetClass || body.starType || '';
type.appendChild($('<span>').text(` ${typeName}`));
row.appendChild(type);
// distance
const distance = $('<div>')
distance.addClass(`col-auto ps-2 ms-0 system ${chartedStyle} ${valuableStyle}`)
distance.text(UI.#formatNumber(body.DistanceFromArrivalLS))
row.appendChild(distance)
const distance = $('<div>');
distance.addClass(`col-auto ps-2 ms-0 system ${chartedStyle} ${valuableStyle}`);
distance.text(UI.#formatNumber(body.DistanceFromArrivalLS));
row.appendChild(distance);
// info
const info = $('<div>').addClass(`col-1 system ${chartedStyle} ${valuableStyle}`)
const info = $('<div>').addClass(`col-1 system ${chartedStyle} ${valuableStyle}`);
// terraformable
const terraform = $('<i>').addClass('flaticon-cooling-tower opacity-0')
const terraform = $('<i>').addClass('flaticon-cooling-tower opacity-0');
if (body.isPlanet && body.TerraformState) {
terraform.removeClass('opacity-0')
terraform.removeClass('opacity-0');
}
info.appendChild(terraform)
info.appendChild(terraform);
// was mapped
const mapped = $('<i>')
mapped.addClass('flaticon-flag-outline-on-a-pole-with-stars-around opacity-0')
mapped.addClass('flaticon-flag-outline-on-a-pole-with-stars-around opacity-0');
if (body.isPlanet() && !body.WasMapped) {
mapped.removeClass('opacity-0')
mapped.removeClass('opacity-0');
}
info.appendChild(mapped)
row.appendChild(info)
info.appendChild(mapped);
row.appendChild(info);
// mapped value
const value = $('<div>').addClass(`col-2 text-end system ${chartedStyle} ${valuableStyle}`)
value.text(UI.#formatNumber(body.mappedValue))
row.appendChild(value)
const value = $('<div>').addClass(`col-2 text-end system ${chartedStyle} ${valuableStyle}`);
value.text(UI.#formatNumber(body.mappedValue));
row.appendChild(value);
return row
return row;
}
/* --------------------------------------------------------------------- createSystemRow ---- */
static createSystemRow(system) {
const row = $('<div>').addClass('row ms-1 me-1')
row.attr('id', system.SystemAddress)
const row = $('<div>').addClass('row ms-1 me-1');
row.attr('id', system.SystemAddress);
// This is probably still the default 'true' value, but check in case the fetch() was quick.
const chartedStyle = system.charted ? 'charted' : 'uncharted'
const chartedStyle = system.charted ? 'charted' : 'uncharted';
// name
const name = $('<div>').addClass(`col system ${chartedStyle}`)
name.appendChild($('<i>').addClass('flaticon-solar-system'))
name.appendChild($('<span>').text(` ${system.name}`))
row.appendChild(name)
const name = $('<div>').addClass(`col system ${chartedStyle}`);
name.appendChild($('<i>').addClass('flaticon-solar-system'));
name.appendChild($('<span>').text(` ${system.name}`));
row.appendChild(name);
// mapped value
// Check if EDSM has responded yet, otherwise value will be filled in later.
const value = $('<div>').addClass(`col-2 text-end system ${chartedStyle} value`)
const value = $('<div>').addClass(`col-2 text-end system ${chartedStyle} value`);
if ('estimatedValueMapped' in system) {
value.text(UI.#formatNumber(system.estimatedValueMapped))
value.text(UI.#formatNumber(system.estimatedValueMapped));
}
row.appendChild(value)
row.appendChild(value);
return row
return row;
}
/* ---------------------------------------------------------------------------- setValue ---- */
static setValue(row, value) {
row.children().filter('.value').text(UI.#formatNumber(value))
row.children().filter('.value').text(UI.#formatNumber(value));
}
}

View file

@ -1,130 +1,102 @@
/**
* This file will automatically be loaded by vite and run in the "renderer" context.
* To learn more about the differences between the "main" and the "renderer" context in
* Electron, visit:
*
* https://electronjs.org/docs/tutorial/application-architecture#main-and-renderer-processes
*
* By default, Node.js integration in this file is disabled. When enabling Node.js integration
* in a renderer process, please be aware of potential security implications. You can read
* more about security risks here:
*
* https://electronjs.org/docs/tutorial/security
*
* To enable Node.js integration in this file, open up `main.js` and enable the `nodeIntegration`
* flag:
*
* ```
* // Create the browser window.
* mainWindow = new BrowserWindow({
* width: 800,
* height: 600,
* webPreferences: {
* nodeIntegration: true
* }
* });
* ```
*/
import 'bootstrap/dist/css/bootstrap.css';
import './assets/index.css';
import './icons/flaticon.css';
import 'bootstrap/dist/css/bootstrap.css'
import './assets/index.css'
import './icons/flaticon.css'
import './assets/ldom.min';
import './assets/ldom.min'
const { app, ipcRenderer } = require('electron');
const { app, ipcRenderer } = require('electron')
import { Safari } from './models/Safari'
import { Settings } from './models/Settings'
import { UI } from './models/UI'
import { Body } from './models/Body'
import { EDSM } from './models/EDSM'
import { Safari } from './models/Safari';
import { Settings } from './models/Settings';
import { UI } from './models/UI';
import { Body } from './models/Body';
import { EDSM } from './models/EDSM';
// Grab app.isPackaged from main process
let isPackaged = false
let isPackaged = false;
window.process.argv.forEach((item) => {
if (item.includes('EDS-ENV')) {
isPackaged = (item.split('=').pop() === 'true')
isPackaged = (item.split('=').pop() === 'true');
}
})
/* ------------------------------------------------------------------------------- app setup ---- */
const safari = Safari.start(isPackaged)
const settings = Settings.get(isPackaged)
const journal = safari.journal
const edsm = EDSM.connect()
const safari = Safari.start(isPackaged);
const settings = Settings.get(isPackaged);
const journal = safari.journal;
const edsm = EDSM.connect();
if (!journal) {
// handle error
// TODO handle error
}
safari.watchJournalDir()
journal.watch()
safari.watchJournalDir();
journal.watch();
/* -------------------------------------------------------------------- close window handler ---- */
$('#closeBtn').on('click', () => {
ipcRenderer.send('CLOSE_WINDOW')
ipcRenderer.send('CLOSE_WINDOW');
})
/* ----------------------------------------------------------------- settings button handler ---- */
$('#settingsBtn').on('click', () => {
ipcRenderer.send('LOAD_SETTINGS')
ipcRenderer.send('LOAD_SETTINGS');
})
/* ------------------------------------------------------------------------- build body list ---- */
journal.once('BUILD_BODY_LIST', () => {
if (journal.location?.bodies?.length > 0) {
journal.location.sortBodies()
journal.location.sortBodies();
journal.location.bodies.forEach((body) => {
const row = UI.createBodyRow(body)
const row = UI.createBodyRow(body);
$('#scans').appendChild(row)
$('#scans').appendChild(row);
})
}
})
/* ----------------------------------------------------------------- started hyperspace jump ---- */
journal.on('ENTERING_WITCH_SPACE', () => UI.enterWitchSpace())
journal.on('ENTERING_WITCH_SPACE', () => UI.enterWitchSpace());
/* ---------------------------------------------------------------------- entered new system ---- */
journal.on('ENTERED_NEW_SYSTEM', () => {
UI.setCurrentSystem(journal.location)
UI.setCurrentSystem(journal.location);
$('#navRoute').children().filter(`#${CSS.escape(journal.location.SystemAddress)}`).remove()
$('#navRoute').children().filter(`#${CSS.escape(journal.location.SystemAddress)}`).remove();
// verify that the internal navRoute matches the UI navRoute, and rebuild it if not
if ($('#navRoute').children().length !== journal.navRoute.length) {
journal.emit('SET_NAV_ROUTE')
journal.emit('SET_NAV_ROUTE');
}
})
/* ---------------------------------------------------------------------- body scan detected ---- */
journal.on('BODY_SCANNED', (body, DSS) => {
journal.location.sortBodies()
journal.location.sortBodies();
// If this is a DSS scan, it's very likely that the body already exists in our list so we just
// need to remove the highlighting if applicable
if (DSS) {
const bodyRow = $(`#${body.BodyID}`)
const bodyRow = $(`#${body.BodyID}`);
if (bodyRow.length > 0) { // check just in case body was missed in earlier scans
bodyRow.removeClass('highlighted uncharted').addClass('charted')
bodyRow.removeClass('highlighted uncharted').addClass('charted');
} else {
const row = UI.createBodyRow(body)
$('#scans').appendChild(row)
const row = UI.createBodyRow(body);
$('#scans').appendChild(row);
}
} else { // else it's an FSS/auto scan and won't be in the list yet
const row = UI.createBodyRow(body)
$('#scans').appendChild(row)
const row = UI.createBodyRow(body);
$('#scans').appendChild(row);
}
})
@ -132,17 +104,17 @@ journal.on('BODY_SCANNED', (body, DSS) => {
journal.on('SET_NAV_ROUTE', () => {
// clear previous nav route, if any
$('#navRoute').children().remove()
$('#navRoute').children().remove();
if (journal.navRoute.length > 0) {
journal.navRoute.forEach((system) => {
// duplicate check
// CSS.escape is needed since CSS technically doesn't allow numeric IDs
const systemRow = $(`#${CSS.escape(system.SystemAddress)}`)
const systemRow = $(`#${CSS.escape(system.SystemAddress)}`);
if (systemRow.length === 0) {
const row = UI.createSystemRow(system)
$('#navRoute').appendChild(row)
const row = UI.createSystemRow(system);
$('#navRoute').appendChild(row);
}
})
}
@ -151,9 +123,9 @@ journal.on('SET_NAV_ROUTE', () => {
/* ------------------------------------------------------------------------ system value set ---- */
edsm.on('SYSTEM_APPRAISED', (system) => {
const systemRow = $(`#${CSS.escape(system.SystemAddress)}`)
const systemRow = $(`#${CSS.escape(system.SystemAddress)}`);
if (systemRow.length > 0) {
UI.setValue(systemRow, system.estimatedValueMapped)
UI.setValue(systemRow, system.estimatedValueMapped);
}
})