diff --git a/package-lock.json b/package-lock.json index d522dec..6f445d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,12 +9,11 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@types/lodash": "^4.14.194", "bootstrap": "^5.3.0-alpha3", "chokidar": "^3.5.3", "electron-squirrel-startup": "^1.0.0", "glob": "^10.2.2", - "lodash": "^4.17.21", + "lodash-es": "^4.17.21", "reverse-line-reader": "^0.2.6", "tail": "^2.2.6" }, @@ -26,6 +25,7 @@ "@electron-forge/maker-zip": "^6.1.1", "@electron-forge/plugin-vite": "^6.1.1", "@tsconfig/node20": "^1.0.0", + "@types/lodash-es": "^4.17.7", "@types/node": "^20.1.2", "@types/tail": "^2.2.1", "electron": "24.2.0", @@ -1232,7 +1232,17 @@ "node_modules/@types/lodash": { "version": "4.14.194", "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": { "version": "5.1.2", @@ -4252,7 +4262,13 @@ "node_modules/lodash": { "version": "4.17.21", "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": { "version": "3.0.0", diff --git a/package.json b/package.json index 9679a40..1f93862 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@electron-forge/maker-zip": "^6.1.1", "@electron-forge/plugin-vite": "^6.1.1", "@tsconfig/node20": "^1.0.0", + "@types/lodash-es": "^4.17.7", "@types/node": "^20.1.2", "@types/tail": "^2.2.1", "electron": "24.2.0", @@ -32,12 +33,11 @@ "typescript": "^5.0.4" }, "dependencies": { - "@types/lodash": "^4.14.194", "bootstrap": "^5.3.0-alpha3", "chokidar": "^3.5.3", "electron-squirrel-startup": "^1.0.0", "glob": "^10.2.2", - "lodash": "^4.17.21", + "lodash-es": "^4.17.21", "reverse-line-reader": "^0.2.6", "tail": "^2.2.6" } diff --git a/src/interfaces/JournalInterface.ts b/src/interfaces/JournalInterface.ts index 76b8bc2..178b5eb 100644 --- a/src/interfaces/JournalInterface.ts +++ b/src/interfaces/JournalInterface.ts @@ -5,7 +5,7 @@ const chokidar = require('chokidar') const EventEmitter = require('node:events') const fs = require('node:fs') const { globSync } = require('glob') -import { maxBy, findIndex, find } from 'lodash' +import * as _ from 'lodash-es' const os = require('node:os') const path = require('node:path') const { readFile } = require('node:fs/promises') @@ -63,7 +63,7 @@ export class JournalInterface extends EventEmitter { getLatestJournal(): string|undefined { const journals = globSync(this.journalPattern) - return maxBy(journals, file => fs.statSync(file).mtime) + return _.maxBy(journals, file => fs.statSync(file).mtime) } /* ------------------------------------------------------------------ getCurrentLocation ---- */ @@ -87,6 +87,12 @@ export class JournalInterface extends EventEmitter { } }).then(() => { 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) { const line = JSON.parse(raw) @@ -128,7 +134,7 @@ export class JournalInterface extends EventEmitter { } else { // Else, check that the body hasn't already been added (by a DSS scan line). 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) { // 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). if ('PlanetClass' in line) { 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) { this.location.bodies.push(new Body((line as autoScan))) @@ -203,7 +209,7 @@ export class JournalInterface extends EventEmitter { if (DSS) { // 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. - 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. 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. // 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) { 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 ---- */ // Parse and handle journal lines. @@ -267,9 +287,7 @@ export class JournalInterface extends EventEmitter { switch (line.event) { // CMDR jumped to new system, so update current location. case 'FSDJump': { - this.location = new System((line as completeFsdJump)) - log(`FSD Jump detected, current location updated to ${this.location.name}.`) - this.emit('ENTERED_NEW_SYSTEM') + this.handleFsdJump((line as completeFsdJump)) break }