From ab1fede12a58b0dbd86b8a43da0677d5cdb7964c Mon Sep 17 00:00:00 2001 From: punkfairie Date: Tue, 9 May 2023 20:13:25 -0700 Subject: [PATCH] Moved Object.assign() to inside Body constructor. --- src/interfaces/JournalInterface.js | 25 ++++++++++++++++++------- src/models/Body.js | 6 +++++- src/renderer.js | 6 +++++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/interfaces/JournalInterface.js b/src/interfaces/JournalInterface.js index 8066eae..5f0dd07 100644 --- a/src/interfaces/JournalInterface.js +++ b/src/interfaces/JournalInterface.js @@ -98,14 +98,14 @@ export class JournalInterface extends EventEmitter { if (line.event === 'SAAScanComplete') { // This was a DSS, so set the DSS flag to true and add to list. detailedScanLine.DSSDone = true - this.location.bodies.push(Object.assign(new Body, detailedScanLine)) + this.location.bodies.push(new Body(detailedScanLine)) } else { // Else, check that the body hasn't already been added (by a DSS scan line). let r = find(this.location.bodies, {'BodyName': detailedScanLine.BodyName, 'BodyID': detailedScanLine.BodyID}) if (r === undefined) { // Body was not already logged, so add to list. - this.location.bodies.push(Object.assign(new Body, detailedScanLine)) + this.location.bodies.push(new Body(detailedScanLine)) } } @@ -122,7 +122,7 @@ export class JournalInterface extends EventEmitter { detailedScanLine = line } else if (line.StarType !== undefined) { // Save stars to bodies list. - this.location.bodies.push(Object.assign(new Body, line)) + this.location.bodies.push(new Body(line)) } else if (line.ScanType === 'AutoScan') { // Save auto/discovery scan bodies. // Check if planet, and then do the duplicate check (otherwise it's an @@ -131,11 +131,11 @@ export class JournalInterface extends EventEmitter { let r = find(this.location.bodies, ['BodyID', line.BodyID]) if (r === undefined) { - this.location.bodies.push(Object.assign(new Body, line)) + this.location.bodies.push(new Body(line)) } } else { // Asteroids. - this.location.bodies.push(Object.assign(new Body, line)) + this.location.bodies.push(new Body(line)) } } } else if (line.event === 'FSDJump') { @@ -180,7 +180,7 @@ export class JournalInterface extends EventEmitter { body.DSSDone = true } else { // Body was missed on initial journal scan, so add it to the list. line.DSSDone = true - body = Object.assign(new Body, line) + body = new Body(line) this.location.bodies.push(body) } @@ -189,7 +189,7 @@ export class JournalInterface extends EventEmitter { let r = find(this.location.bodies, dupChecker) if (r === undefined) { - body = Object.assign(new Body, line) + body = new Body(line) this.location.bodies.push(body) } } @@ -198,6 +198,12 @@ export class JournalInterface extends EventEmitter { this.emit('BODY_SCANNED', body, DSS) } + /* ------------------------------------------------------------------------- getNavRoute ---- */ + + getNavRoute() { + + } + /* --------------------------------------------------------------------------- parseLine ---- */ // Parse and handle journal lines. @@ -228,6 +234,11 @@ export class JournalInterface extends EventEmitter { DSSFlag = false break } + + case 'NavRoute': { + this.getNavRoute() + break + } } } diff --git a/src/models/Body.js b/src/models/Body.js index 4a423a0..57edb28 100644 --- a/src/models/Body.js +++ b/src/models/Body.js @@ -1,6 +1,10 @@ export class Body { - constructor() { + constructor(journalLine = null) { this.DSSDone = false + + if (journalLine !== null) { + Object.assign(this, journalLine) + } } /* -------------------------------------------------------------------------- isAsteroid ---- */ diff --git a/src/renderer.js b/src/renderer.js index d1cf327..f084f8b 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -33,6 +33,7 @@ import './icons/flaticon.css' const { app } = require('electron') import { JournalInterface } from './interfaces/JournalInterface' import { createBodyRow } from './ui' +import { Body } from './models/Body' // Grab app.isPackaged from main process let isPackaged = false @@ -53,6 +54,9 @@ if (journal.journalDir === null) { journal.watchDirectory() journal.watchJournal() +const test = {name: 'Test', ID: 'TestID'} +console.log(new Body(test)) + /* --------------------------------------------------------------------------- init complete ---- */ journal.once('INIT_COMPLETE', () => { @@ -66,7 +70,7 @@ journal.once('INIT_COMPLETE', () => { $('#currentSystemIcon').removeClass('hidden') } - if (journal.location.bodies.length > 0) { + if (journal.location?.bodies?.length > 0) { journal.location.bodies.forEach((body) => { const row = createBodyRow(body) // TODO APPRAISAL DATA