diff --git a/src/interfaces/JournalInterface.ts b/src/interfaces/JournalInterface.ts index edc2bd5..a33cfe9 100644 --- a/src/interfaces/JournalInterface.ts +++ b/src/interfaces/JournalInterface.ts @@ -6,7 +6,7 @@ import { System } from '../models/System' const EventEmitter = require('events') const fs = require('fs') const path = require('path') -import { globSync } from 'glob' +const { globSync } = require('glob') const os = require('os') const lineReader = require('reverse-line-reader') const chokidar = require('chokidar') @@ -57,8 +57,7 @@ export class JournalInterface extends EventEmitter { const journals = globSync(this.journalPattern) return maxBy(journals, file => { - const fullPath = path.join(this.journalDir, file) - return fs.statSync(fullPath).mtime + return fs.statSync(file).mtime }) } @@ -82,7 +81,7 @@ export class JournalInterface extends EventEmitter { } } }).then(() => { - if (this.location) { + if (this.location.name !== 'Unknown') { log('Attempting to find scanned bodies in current system.') this.getScannedBodies() } diff --git a/src/models/UI.js b/src/models/UI.js new file mode 100644 index 0000000..f3a923f --- /dev/null +++ b/src/models/UI.js @@ -0,0 +1,102 @@ +export class UI { + constructor() {} + + /* -------------------------------------------------------------------------- buildRings ---- */ + + static buildRings(body) { + const rings = $('') + const seperator = $('').text(' ) ') + rings.appendChild(seperator) + + body.Rings.forEach((ring) => { + const ringClass = ring.RingClass.replace('eRingClass_', '') + let icon = null + + switch (ringClass) { + case 'MetalRich': { + icon = 'gold-bars' + break + } + + case 'Metalic': + case 'Metallic': { + icon = 'ingot' + break + } + + case 'Icy': { + icon = 'snowflake' + break + } + + case 'Rocky': { + icon = 'asteroid-3' + break + } + } + + if (icon !== null) { + rings.appendChild($('').addClass(`flaticon-${icon}`)) + rings.appendChild(seperator) + } + }) + + return rings + } + + /* ----------------------------------------------------------------------- createBodyRow ---- */ + + static createBodyRow(body) { + const chartedStyle = body.WasDiscovered && !body.DSSDone ? 'charted' : 'uncharted' + const row = $('
').addClass('row ms-1 me-1') + row.attr('id', body.bodyID) + + // spacer + row.appendChild($('
').addClass('col-1 system')) + + // name + const name = $('
').addClass(`col-2 text-left system ${chartedStyle}`) + name.appendChild($('')).addClass(`flaticon-${body.nameIcon()}`) + name.appendChild($('')).text(body.simpleName()) + row.appendChild(name) + + // type icon + const type = $('
').addClass(`col pe-0 me-0 system ${chartedStyle}`) + type.appendChild($('').addClass(`flaticon-${body.typeIcon()}`)) + // rings + if (body.Rings !== undefined) { + type.appendChild(buildRings(body)) + } + // type + const typeName = body.PlanetClass || body.starType || '' + type.appendChild($('').text(typeName)) + row.appendChild(type) + + // distance + const distance = $('
').addClass(`col-auto ps-2 ms-0 system ${chartedStyle}`) + distance.text(body.distance()) + row.appendChild(distance) + + // info + const info = $('
').addClass(`col-1 system ${chartedStyle}`) + // terraformable + const terraform = $('').addClass('flaticon-cooling-tower opacity-0') + if (body.isPlanet && body.TerraformState) { + terraform.removeClass('opacity-0') + } + info.appendChild(terraform) + // was mapped + const mapped = $('').addClass('flaticon-flag-outline-on-a-pole-with-stars-around opacity-0') + if (body.isPlanet() && !body.WasMapped) { + mapped.removeClass('opacity-0') + } + info.appendChild(mapped) + row.appendChild(info) + + // mapped value + const value = $('
').addClass(`col-2 text-right system ${chartedStyle}`) + row.appendChild(value) + + return row + } +} \ No newline at end of file diff --git a/src/renderer.js b/src/renderer.js index 7106e02..ffe928f 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -32,7 +32,7 @@ import './icons/flaticon.css' const { app } = require('electron') import { JournalInterface } from './interfaces/JournalInterface' -import { createBodyRow } from './ui' +import { UI } from './models/UI' import { Body } from './models/Body' // Grab app.isPackaged from main process @@ -71,7 +71,7 @@ journal.once('INIT_COMPLETE', () => { if (journal.location?.bodies?.length > 0) { journal.location.bodies.forEach((body) => { - const row = createBodyRow(body) + const row = UI.createBodyRow(body) // TODO APPRAISAL DATA $('#lowValueScans').appendChild(row) }) @@ -98,13 +98,13 @@ journal.on('BODY_SCANNED', (body, DSS) => { if (bodyRow.length > 0) { // check just in case body was missed in earlier scans bodyRow.removeClass('highlighted uncharted').addClass('charted') } else { - const row = createBodyRow(body) + const row = UI.createBodyRow(body) // TODO APPRAISAL DATA $('#lowValueScans').appendChild(row) } } else { // else it's an FSS/auto scan and won't be in the list yet - const row = createBodyRow(body) + const row = UI.createBodyRow(body) // TODO APPRAISAL DATA $('#lowValueScans').appendChild(row) } diff --git a/src/ui.js b/src/ui.js deleted file mode 100644 index cc05031..0000000 --- a/src/ui.js +++ /dev/null @@ -1,98 +0,0 @@ -/* ------------------------------------------------------------------------------ buildRings ---- */ - -const buildRings = (body) => { - const rings = $('') - const seperator = $('').text(' ) ') - rings.appendChild(seperator) - - body.Rings.forEach((ring) => { - const ringClass = ring.RingClass.replace('eRingClass_', '') - let icon = null - - switch (ringClass) { - case 'MetalRich': { - icon = 'gold-bars' - break - } - - case 'Metalic': - case 'Metallic': { - icon = 'ingot' - break - } - - case 'Icy': { - icon = 'snowflake' - break - } - - case 'Rocky': { - icon = 'asteroid-3' - break - } - } - - if (icon !== null) { - rings.appendChild($('').addClass(`flaticon-${icon}`)) - rings.appendChild(seperator) - } - }) - - return rings -} - -/* --------------------------------------------------------------------------- createBodyRow ---- */ - -export const createBodyRow = (body) => { - const chartedStyle = body.WasDiscovered && !body.DSSDone ? 'charted' : 'uncharted' - const row = $('
').addClass('row ms-1 me-1') - row.attr('id', body.bodyID) - - // spacer - row.appendChild($('
').addClass('col-1 system')) - - // name - const name = $('
').addClass(`col-2 text-left system ${chartedStyle}`) - name.appendChild($('')).addClass(`flaticon-${body.nameIcon()}`) - name.appendChild($('')).text(body.simpleName()) - row.appendChild(name) - - // type icon - const type = $('
').addClass(`col pe-0 me-0 system ${chartedStyle}`) - type.appendChild($('').addClass(`flaticon-${body.typeIcon()}`)) - // rings - if (body.Rings !== undefined) { - type.appendChild(buildRings(body)) - } - // type - const typeName = body.PlanetClass || body.starType || '' - type.appendChild($('').text(typeName)) - row.appendChild(type) - - // distance - const distance = $('
').addClass(`col-auto ps-2 ms-0 system ${chartedStyle}`) - distance.text(body.distance()) - row.appendChild(distance) - - // info - const info = $('
').addClass(`col-1 system ${chartedStyle}`) - // terraformable - const terraform = $('').addClass('flaticon-cooling-tower opacity-0') - if (body.isPlanet && body.TerraformState) { - terraform.removeClass('opacity-0') - } - info.appendChild(terraform) - // was mapped - const mapped = $('').addClass('flaticon-flag-outline-on-a-pole-with-stars-around opacity-0') - if (body.isPlanet() && !body.WasMapped) { - mapped.removeClass('opacity-0') - } - info.appendChild(mapped) - row.appendChild(info) - - // mapped value - const value = $('
').addClass(`col-2 text-right system ${chartedStyle}`) - row.appendChild(value) - - return row -} \ No newline at end of file