Shouldn't check for Location if FSDJump was found.
This commit is contained in:
parent
dc9ccdb26b
commit
913767a6ea
3 changed files with 49 additions and 15 deletions
24
package-lock.json
generated
24
package-lock.json
generated
|
@ -9,12 +9,11 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/lodash": "^4.14.194",
|
|
||||||
"bootstrap": "^5.3.0-alpha3",
|
"bootstrap": "^5.3.0-alpha3",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.5.3",
|
||||||
"electron-squirrel-startup": "^1.0.0",
|
"electron-squirrel-startup": "^1.0.0",
|
||||||
"glob": "^10.2.2",
|
"glob": "^10.2.2",
|
||||||
"lodash": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"reverse-line-reader": "^0.2.6",
|
"reverse-line-reader": "^0.2.6",
|
||||||
"tail": "^2.2.6"
|
"tail": "^2.2.6"
|
||||||
},
|
},
|
||||||
|
@ -26,6 +25,7 @@
|
||||||
"@electron-forge/maker-zip": "^6.1.1",
|
"@electron-forge/maker-zip": "^6.1.1",
|
||||||
"@electron-forge/plugin-vite": "^6.1.1",
|
"@electron-forge/plugin-vite": "^6.1.1",
|
||||||
"@tsconfig/node20": "^1.0.0",
|
"@tsconfig/node20": "^1.0.0",
|
||||||
|
"@types/lodash-es": "^4.17.7",
|
||||||
"@types/node": "^20.1.2",
|
"@types/node": "^20.1.2",
|
||||||
"@types/tail": "^2.2.1",
|
"@types/tail": "^2.2.1",
|
||||||
"electron": "24.2.0",
|
"electron": "24.2.0",
|
||||||
|
@ -1232,7 +1232,17 @@
|
||||||
"node_modules/@types/lodash": {
|
"node_modules/@types/lodash": {
|
||||||
"version": "4.14.194",
|
"version": "4.14.194",
|
||||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.194.tgz",
|
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.194.tgz",
|
||||||
"integrity": "sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g=="
|
"integrity": "sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"node_modules/@types/lodash-es": {
|
||||||
|
"version": "4.17.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.7.tgz",
|
||||||
|
"integrity": "sha512-z0ptr6UI10VlU6l5MYhGwS4mC8DZyYer2mCoyysZtSF7p26zOX8UpbrV0YpNYLGS8K4PUFIyEr62IMFFjveSiQ==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/lodash": "*"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/minimatch": {
|
"node_modules/@types/minimatch": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
|
@ -4252,7 +4262,13 @@
|
||||||
"node_modules/lodash": {
|
"node_modules/lodash": {
|
||||||
"version": "4.17.21",
|
"version": "4.17.21",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"node_modules/lodash-es": {
|
||||||
|
"version": "4.17.21",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
|
||||||
|
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw=="
|
||||||
},
|
},
|
||||||
"node_modules/lodash._reinterpolate": {
|
"node_modules/lodash._reinterpolate": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"@electron-forge/maker-zip": "^6.1.1",
|
"@electron-forge/maker-zip": "^6.1.1",
|
||||||
"@electron-forge/plugin-vite": "^6.1.1",
|
"@electron-forge/plugin-vite": "^6.1.1",
|
||||||
"@tsconfig/node20": "^1.0.0",
|
"@tsconfig/node20": "^1.0.0",
|
||||||
|
"@types/lodash-es": "^4.17.7",
|
||||||
"@types/node": "^20.1.2",
|
"@types/node": "^20.1.2",
|
||||||
"@types/tail": "^2.2.1",
|
"@types/tail": "^2.2.1",
|
||||||
"electron": "24.2.0",
|
"electron": "24.2.0",
|
||||||
|
@ -32,12 +33,11 @@
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/lodash": "^4.14.194",
|
|
||||||
"bootstrap": "^5.3.0-alpha3",
|
"bootstrap": "^5.3.0-alpha3",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.5.3",
|
||||||
"electron-squirrel-startup": "^1.0.0",
|
"electron-squirrel-startup": "^1.0.0",
|
||||||
"glob": "^10.2.2",
|
"glob": "^10.2.2",
|
||||||
"lodash": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"reverse-line-reader": "^0.2.6",
|
"reverse-line-reader": "^0.2.6",
|
||||||
"tail": "^2.2.6"
|
"tail": "^2.2.6"
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ const chokidar = require('chokidar')
|
||||||
const EventEmitter = require('node:events')
|
const EventEmitter = require('node:events')
|
||||||
const fs = require('node:fs')
|
const fs = require('node:fs')
|
||||||
const { globSync } = require('glob')
|
const { globSync } = require('glob')
|
||||||
import { maxBy, findIndex, find } from 'lodash'
|
import * as _ from 'lodash-es'
|
||||||
const os = require('node:os')
|
const os = require('node:os')
|
||||||
const path = require('node:path')
|
const path = require('node:path')
|
||||||
const { readFile } = require('node:fs/promises')
|
const { readFile } = require('node:fs/promises')
|
||||||
|
@ -63,7 +63,7 @@ export class JournalInterface extends EventEmitter {
|
||||||
getLatestJournal(): string|undefined {
|
getLatestJournal(): string|undefined {
|
||||||
const journals = globSync(this.journalPattern)
|
const journals = globSync(this.journalPattern)
|
||||||
|
|
||||||
return maxBy(journals, file => fs.statSync(file).mtime)
|
return _.maxBy(journals, file => fs.statSync(file).mtime)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ getCurrentLocation ---- */
|
/* ------------------------------------------------------------------ getCurrentLocation ---- */
|
||||||
|
@ -87,6 +87,12 @@ export class JournalInterface extends EventEmitter {
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
reverseLineReader.eachLine(this.currentJournal, (raw: string, last: boolean) => {
|
reverseLineReader.eachLine(this.currentJournal, (raw: string, last: boolean) => {
|
||||||
|
// TODO: figure out if we can avoid entering eachLine() altogether? realyyy wish
|
||||||
|
// it returned a promise :(
|
||||||
|
if (this.location.name !== 'Unknown') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (raw) {
|
if (raw) {
|
||||||
const line = JSON.parse(raw)
|
const line = JSON.parse(raw)
|
||||||
|
|
||||||
|
@ -128,7 +134,7 @@ export class JournalInterface extends EventEmitter {
|
||||||
} else {
|
} else {
|
||||||
// Else, check that the body hasn't already been added (by a DSS scan line).
|
// Else, check that the body hasn't already been added (by a DSS scan line).
|
||||||
let dupChecker = {'BodyName': detailedScanLine.BodyName, 'BodyID': detailedScanLine.BodyID}
|
let dupChecker = {'BodyName': detailedScanLine.BodyName, 'BodyID': detailedScanLine.BodyID}
|
||||||
let r = find(this.location.bodies, dupChecker)
|
let r = _.find(this.location.bodies, dupChecker)
|
||||||
|
|
||||||
if (r === undefined) {
|
if (r === undefined) {
|
||||||
// Body was not already logged, so add to list.
|
// Body was not already logged, so add to list.
|
||||||
|
@ -156,7 +162,7 @@ export class JournalInterface extends EventEmitter {
|
||||||
// astroid, as we've already accounted for stars).
|
// astroid, as we've already accounted for stars).
|
||||||
if ('PlanetClass' in line) {
|
if ('PlanetClass' in line) {
|
||||||
let dupChecker = {'BodyName': (line as planetScan<'AutoScan'>).BodyName, 'BodyID': (line as planetScan<'AutoScan'>).BodyID}
|
let dupChecker = {'BodyName': (line as planetScan<'AutoScan'>).BodyName, 'BodyID': (line as planetScan<'AutoScan'>).BodyID}
|
||||||
let r = find(this.location.bodies, dupChecker)
|
let r = _.find(this.location.bodies, dupChecker)
|
||||||
|
|
||||||
if (r === undefined) {
|
if (r === undefined) {
|
||||||
this.location.bodies.push(new Body((line as autoScan)))
|
this.location.bodies.push(new Body((line as autoScan)))
|
||||||
|
@ -203,7 +209,7 @@ export class JournalInterface extends EventEmitter {
|
||||||
if (DSS) {
|
if (DSS) {
|
||||||
// Using findIndex() rather than find() so we can edit the body if found.
|
// Using findIndex() rather than find() so we can edit the body if found.
|
||||||
// @ts-ignore since it doesn't understand dupChecker is a valid predicate.
|
// @ts-ignore since it doesn't understand dupChecker is a valid predicate.
|
||||||
let bodyIndex: number = findIndex(this.location.bodies, dupChecker)
|
let bodyIndex: number = _.findIndex(this.location.bodies, dupChecker)
|
||||||
|
|
||||||
if (bodyIndex > -1) { // Body was found in list, so simply toggle the DSS flag.
|
if (bodyIndex > -1) { // Body was found in list, so simply toggle the DSS flag.
|
||||||
body = (this.location.bodies[bodyIndex] as Body)
|
body = (this.location.bodies[bodyIndex] as Body)
|
||||||
|
@ -215,7 +221,7 @@ export class JournalInterface extends EventEmitter {
|
||||||
|
|
||||||
} else { // Otherwise it's an FSS or auto scan, and needs to be added to the list.
|
} else { // Otherwise it's an FSS or auto scan, and needs to be added to the list.
|
||||||
// Probably overkill, but do a duplicate check just in case.
|
// Probably overkill, but do a duplicate check just in case.
|
||||||
let r = find(this.location.bodies, dupChecker)
|
let r = _.find(this.location.bodies, dupChecker)
|
||||||
|
|
||||||
if (r === undefined) {
|
if (r === undefined) {
|
||||||
body = new Body(line)
|
body = new Body(line)
|
||||||
|
@ -257,6 +263,20 @@ export class JournalInterface extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------- handleFsdJump ---- */
|
||||||
|
|
||||||
|
handleFsdJump(line: completeFsdJump): void {
|
||||||
|
this.location = new System((line as completeFsdJump))
|
||||||
|
log(`FSD Jump detected, current location updated to ${this.location.name}.`)
|
||||||
|
this.emit('ENTERED_NEW_SYSTEM')
|
||||||
|
|
||||||
|
if (this.navRoute.length > 0) {
|
||||||
|
_.remove(this.navRoute, (system) => {
|
||||||
|
system.SystemAddress === this.location.SystemAddress
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------- parseLine ---- */
|
/* --------------------------------------------------------------------------- parseLine ---- */
|
||||||
|
|
||||||
// Parse and handle journal lines.
|
// Parse and handle journal lines.
|
||||||
|
@ -267,9 +287,7 @@ export class JournalInterface extends EventEmitter {
|
||||||
switch (line.event) {
|
switch (line.event) {
|
||||||
// CMDR jumped to new system, so update current location.
|
// CMDR jumped to new system, so update current location.
|
||||||
case 'FSDJump': {
|
case 'FSDJump': {
|
||||||
this.location = new System((line as completeFsdJump))
|
this.handleFsdJump((line as completeFsdJump))
|
||||||
log(`FSD Jump detected, current location updated to ${this.location.name}.`)
|
|
||||||
this.emit('ENTERED_NEW_SYSTEM')
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue