Remove duplicate current system from NavRoute

This commit is contained in:
punkfairie 2023-05-11 03:03:07 -07:00
parent 8432caba41
commit dc9ccdb26b
3 changed files with 29 additions and 14 deletions

View file

@ -76,7 +76,7 @@ export class JournalInterface extends EventEmitter {
const line = JSON.parse(raw) const line = JSON.parse(raw)
if (line.event === 'FSDJump') { if (line.event === 'FSDJump') {
this.location = new System(line.StarSystem) this.location = new System(line)
log(`Current location set to ${this.location.name}.`) log(`Current location set to ${this.location.name}.`)
this.emit('ENTERED_NEW_SYSTEM') this.emit('ENTERED_NEW_SYSTEM')
return false return false
@ -91,7 +91,7 @@ export class JournalInterface extends EventEmitter {
const line = JSON.parse(raw) const line = JSON.parse(raw)
if (line.event === 'Location') { if (line.event === 'Location') {
this.location = new System(line.StarSystem) this.location = new System(line)
log(`Current location set to ${this.location.name}.`) log(`Current location set to ${this.location.name}.`)
this.emit('ENTERED_NEW_SYSTEM') this.emit('ENTERED_NEW_SYSTEM')
return false return false
@ -173,6 +173,7 @@ export class JournalInterface extends EventEmitter {
} }
}).then(() => { }).then(() => {
log('Scanned bodies found.') log('Scanned bodies found.')
log('Reading current nav route.')
this.getNavRoute(true) this.getNavRoute(true)
}) })
} }
@ -234,17 +235,19 @@ export class JournalInterface extends EventEmitter {
try { try {
routeFile = await readFile(this.journalDir + 'NavRoute.json', { encoding: 'utf8' }) routeFile = await readFile(this.journalDir + 'NavRoute.json', { encoding: 'utf8' })
} catch (err) { } catch (err) {
log(`Error getting NavRoute: ${err.message}.`) log(`Error reading nav route file: ${err.message}.`)
} }
if (routeFile) { if (routeFile) {
const route: navRoute = JSON.parse(routeFile) const route: navRoute = JSON.parse(routeFile)
route.Route.forEach((system) => { route.Route.forEach((system) => {
if (system.SystemAddress !== this.location.SystemAddress) {
this.navRoute.push(new System(system)) this.navRoute.push(new System(system))
}
}) })
log('NavRoute set.') log('Nav route set.')
if (init) { if (init) {
this.emit('INIT_COMPLETE') this.emit('INIT_COMPLETE')
@ -289,6 +292,12 @@ export class JournalInterface extends EventEmitter {
this.getNavRoute() this.getNavRoute()
break break
} }
case 'NavRouteClear': {
this.navRoute = []
this.emit('SET_NAV_ROUTE')
break
}
} }
} }

View file

@ -1,6 +1,20 @@
export class UI { export class UI {
constructor() {} 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 ---- */ /* -------------------------------------------------------------------------- buildRings ---- */
static #buildRings(body) { static #buildRings(body) {

View file

@ -60,15 +60,7 @@ const test = {name: 'Test', ID: 'TestID'}
/* --------------------------------------------------------------------------- init complete ---- */ /* --------------------------------------------------------------------------- init complete ---- */
journal.once('INIT_COMPLETE', () => { journal.once('INIT_COMPLETE', () => {
if (journal.location.name !== 'Unknown') { UI.setCurrentSystem(journal.location)
$('#currentSystem')
.addClass('charted')
.removeClass('highlighted text-center')
$('#currentSystemName').text(journal.location.name)
$('#currentSystemIcon').removeClass('hidden')
}
if (journal.location?.bodies?.length > 0) { if (journal.location?.bodies?.length > 0) {
journal.location.bodies.forEach((body) => { journal.location.bodies.forEach((body) => {