diff --git a/src/interfaces/JournalInterface.ts b/src/interfaces/JournalInterface.ts index 92cf737..76b8bc2 100644 --- a/src/interfaces/JournalInterface.ts +++ b/src/interfaces/JournalInterface.ts @@ -76,7 +76,7 @@ export class JournalInterface extends EventEmitter { const line = JSON.parse(raw) if (line.event === 'FSDJump') { - this.location = new System(line.StarSystem) + this.location = new System(line) log(`Current location set to ${this.location.name}.`) this.emit('ENTERED_NEW_SYSTEM') return false @@ -91,7 +91,7 @@ export class JournalInterface extends EventEmitter { const line = JSON.parse(raw) if (line.event === 'Location') { - this.location = new System(line.StarSystem) + this.location = new System(line) log(`Current location set to ${this.location.name}.`) this.emit('ENTERED_NEW_SYSTEM') return false @@ -173,6 +173,7 @@ export class JournalInterface extends EventEmitter { } }).then(() => { log('Scanned bodies found.') + log('Reading current nav route.') this.getNavRoute(true) }) } @@ -234,17 +235,19 @@ export class JournalInterface extends EventEmitter { try { routeFile = await readFile(this.journalDir + 'NavRoute.json', { encoding: 'utf8' }) } catch (err) { - log(`Error getting NavRoute: ${err.message}.`) + log(`Error reading nav route file: ${err.message}.`) } if (routeFile) { const route: navRoute = JSON.parse(routeFile) route.Route.forEach((system) => { - this.navRoute.push(new System(system)) + if (system.SystemAddress !== this.location.SystemAddress) { + this.navRoute.push(new System(system)) + } }) - log('NavRoute set.') + log('Nav route set.') if (init) { this.emit('INIT_COMPLETE') @@ -289,6 +292,12 @@ export class JournalInterface extends EventEmitter { this.getNavRoute() break } + + case 'NavRouteClear': { + this.navRoute = [] + this.emit('SET_NAV_ROUTE') + break + } } } diff --git a/src/models/UI.js b/src/models/UI.js index 2946346..15477e1 100644 --- a/src/models/UI.js +++ b/src/models/UI.js @@ -1,6 +1,20 @@ export class UI { constructor() {} + /* -------------------------------------------------------------------- setCurrentSystem ---- */ + + static setCurrentSystem(system) { + if (system.name === 'Unknown') { + $('#currentSystem').removeClass('charted').addClass('highlighted text-center') + $('#currentSystemIcon').addClass('hidden') + } else { + $('#currentSystem').addClass('charted').removeClass('highlighted text-center') + $('#currentSystemIcon').removeClass('hidden') + } + + $('#currentSystemName').text(system.name) + } + /* -------------------------------------------------------------------------- buildRings ---- */ static #buildRings(body) { diff --git a/src/renderer.js b/src/renderer.js index b82da79..38dfc9a 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -60,15 +60,7 @@ const test = {name: 'Test', ID: 'TestID'} /* --------------------------------------------------------------------------- init complete ---- */ journal.once('INIT_COMPLETE', () => { - if (journal.location.name !== 'Unknown') { - $('#currentSystem') - .addClass('charted') - .removeClass('highlighted text-center') - - $('#currentSystemName').text(journal.location.name) - - $('#currentSystemIcon').removeClass('hidden') - } + UI.setCurrentSystem(journal.location) if (journal.location?.bodies?.length > 0) { journal.location.bodies.forEach((body) => {