diff --git a/src/@types/journalLines.d.ts b/src/@types/journalLines.d.ts new file mode 100644 index 0000000..ad6bdf9 --- /dev/null +++ b/src/@types/journalLines.d.ts @@ -0,0 +1,183 @@ +interface journalEntry { + timestamp: string, + event: eventType, +} + +export interface discoveryHonk extends journalEntry<'FSSDiscoveryScan'> { + Progress: number, + BodyCount: number, + NonBodyCount: number, + SystemName: string, + SystemAddress: number, +} + +export interface completedSystemFSSScan extends journalEntry<'FSSAllBodiesFound'> { + event: 'FSSAllBodiesFound', + SystemName: string, + SystemAddress: number, + Count: number, +} + +export interface dssIndicator extends journalEntry<'SAAScanComplete'> { + BodyName: string, + SystemAddress: number, + BodyID: number, + ProbesUsed: number, + EfficiencyTarget: number, +} + +interface bodyParent { + [index: string]: number, +} + +interface bodyAtmosphere { + Name: string, + Percent: number, +} + +interface bodyMaterials { + Name: string, + Percent: number, +} + +interface bodyRings { + Name: string, + RingClass: string, + MassMT: number, + InnerRad: number, + OuterRad: number, +} + +export interface starScan extends journalEntry<'Scan'> { + ScanType: scanType, + BodyName: string, + BodyID: number, + Parents: bodyParent[], + StarSystem: string, + SystemAddress: number, + DistanceFromArrivalLS: number, + StarType: string, + Subclass: number, + StellarMass: number, + Radius: number, + AbsoluteMagnitude: number, + Age_MY: number, + SurfaceTemperature: number, + Luminosity: string, + SemiMajorAxis: number, + Eccentricity: number, + OrbitalInclination: number, + Periapsis: number, + OrbitalPeriod: number, + AscendingNode: number, + MeanAnomaly: number, + RotationPeriod: number, + AxialTilt: number, + WasDiscovered: boolean, + WasMapped: false, +} + +export interface asteroidScan extends journalEntry<'Scan'> { + ScanType: scanType, + BodyName: string, + BodyID: number, + Parents: bodyParent[], + StarSystem: string, + SystemAddress: number, + DistanceFromArrivalLS: number, + WasDiscovered: boolean, + WasMapped: false, +} + +export interface planetScan extends journalEntry<'Scan'> { + ScanType: scanType, + BodyName: string, + BodyID: number, + Parents: bodyParent[], + StarSystem: string, + SystemAddress: number, + DistanceFromArrivalLS: number, + TidalLock: boolean, + TerraformState: string, + PlanetClass: string, + Atmosphere: string, + AtmosphereType: string, + AtmosphereComposition?: bodyAtmosphere[] + Volcanism: string, + MassEM: number, + Radius: number, + SurfaceGravity: number, + SurfaceTemperature: number, + SurfacePressure: number, + Landable: boolean, + Materials: bodyMaterials[], + Composition: { + Ice: number, + Rock: number, + Metal: number, + }, + SemiMajorAxis: number, + Eccentricity: number, + OrbitalInclination: number, + Periapsis: number, + OrbitalPeriod: number, + AscendingNode: number, + MeanAnomaly: number, + RotationPeriod: number, + AxialTilt: number, + Rings?: bodyRings[], + ReserveLevel?: string, + WasDiscovered: boolean, + WasMapped: boolean, +} + +export type autoScan = starScan<'AutoScan'> & asteroidScan<'AutoScan'> & planetScan<'AutoScan'> +export type discoveryScan = starScan<'Detailed'> & asteroidScan<'Detailed'> & planetScan<'Detailed'> +export type fssScan = starScan<'Detailed'> & asteroidScan<'Detailed'> & planetScan<'Detailed'> +export type dssScan = starScan<'Detailed'> & asteroidScan<'Detailed'> & planetScan<'Detailed'> + +export interface startFsdJump extends journalEntry<'StartJump'> { + JumpType: 'Hyperspace', + StarSystem: string, + SystemAddress: number, + StarClass: string, +} + +interface faction { + Name: string, + FactionState: string, + Government: string, + Influence: number, + Allegiance: string, + Happiness: string, + Happiness_Localized: string, + MyReputation: number, + RecoveringStates?: {State: string, Trend: number}[], + ActiveStates?: {State: string}[], +} + +export interface completeFsdJump extends journalEntry<'FSDJump'> { + Taxi: boolean, + Multicrew: boolean, + StarSystem: string, + SystemAddress: number, + StarPos: [number, number, number], + SystemAllegiance: string, + SystemEconomy: string, + SystemEconomy_Localised: string, + SystemSecondEconomy: string, + SystemSecondEconomy_Localised: string, + SystemGovernment: string, + SystemGovernment_Localised: string, + SystemSecurity: string, + SystemSecurity_Localised: string, + Population: number, + Body: string, + BodyID: number, + BodyType: string, + JumpDist: number, + FuelUsed: number, + FuelLevel: number, + Factions: faction[], + SystemFaction: {Name: string}, +} \ No newline at end of file diff --git a/src/interfaces/JournalInterface.js b/src/interfaces/JournalInterface.ts similarity index 97% rename from src/interfaces/JournalInterface.js rename to src/interfaces/JournalInterface.ts index 5f0dd07..49086b9 100644 --- a/src/interfaces/JournalInterface.js +++ b/src/interfaces/JournalInterface.ts @@ -18,7 +18,13 @@ const findIndex = require('lodash/findIndex') const log = console.log.bind(console) export class JournalInterface extends EventEmitter { - constructor(isPackaged) { + journalDir: null|string + journalPattern: string + currentJournal: string + location: null|System + + + constructor(isPackaged: boolean) { super() this.journalDir = null @@ -35,6 +41,7 @@ export class JournalInterface extends EventEmitter { this.journalPattern = this.journalDir + "Journal.*.log" this.currentJournal = this.getLatestJournal() + log(`New journal file found, now watching ${path.basename(this.currentJournal)}.`) // LineReader seems to be async, so start async processes here. this.location = null @@ -46,22 +53,20 @@ export class JournalInterface extends EventEmitter { /* -------------------------------------------------------------------- getLatestJournal ---- */ // https://stackoverflow.com/questions/15696218/get-the-most-recent-file-in-a-directory-node-js - getLatestJournal() { + getLatestJournal(): string { const journals = globSync(this.journalPattern) return max(journals, file => { const fullPath = path.join(this.journalDir, file) return fs.statSync(fullPath).mtime }) - - log(`New journal file found, now watching ${path.basename(this.currentJournal)}.`) } /* ------------------------------------------------------------------ getCurrentLocation ---- */ // Get current location on setup, so if app is restarted, user can pick up where they left off // Rather than waiting til they jump to the next system to use the program again. - getCurrentLocation() { + getCurrentLocation(): void { lineReader.eachLine(this.currentJournal, (raw, last) => { if (raw) { // skip blank line at end of file const line = JSON.parse(raw) @@ -85,8 +90,8 @@ export class JournalInterface extends EventEmitter { /* -------------------------------------------------------------------- getScannedBodies ---- */ // Look for all scanned bodies before last FSDJump, for same reasons as getCurrentLocation(). - getScannedBodies() { - let detailedScanLine = null + getScannedBodies(): void { + let detailedScanLine: Object|null = null lineReader.eachLine(this.currentJournal, (raw, last) => {