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

View file

@ -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) {

View file

@ -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) => {