Start js -> ts; define journal line types.
This commit is contained in:
parent
ab1fede12a
commit
84ec21161f
2 changed files with 195 additions and 7 deletions
183
src/@types/journalLines.d.ts
vendored
Normal file
183
src/@types/journalLines.d.ts
vendored
Normal file
|
@ -0,0 +1,183 @@
|
||||||
|
interface journalEntry<eventType = string> {
|
||||||
|
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<scanType> 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<scanType> extends journalEntry<'Scan'> {
|
||||||
|
ScanType: scanType,
|
||||||
|
BodyName: string,
|
||||||
|
BodyID: number,
|
||||||
|
Parents: bodyParent[],
|
||||||
|
StarSystem: string,
|
||||||
|
SystemAddress: number,
|
||||||
|
DistanceFromArrivalLS: number,
|
||||||
|
WasDiscovered: boolean,
|
||||||
|
WasMapped: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface planetScan<scanType> 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},
|
||||||
|
}
|
|
@ -18,7 +18,13 @@ const findIndex = require('lodash/findIndex')
|
||||||
const log = console.log.bind(console)
|
const log = console.log.bind(console)
|
||||||
|
|
||||||
export class JournalInterface extends EventEmitter {
|
export class JournalInterface extends EventEmitter {
|
||||||
constructor(isPackaged) {
|
journalDir: null|string
|
||||||
|
journalPattern: string
|
||||||
|
currentJournal: string
|
||||||
|
location: null|System
|
||||||
|
|
||||||
|
|
||||||
|
constructor(isPackaged: boolean) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this.journalDir = null
|
this.journalDir = null
|
||||||
|
@ -35,6 +41,7 @@ export class JournalInterface extends EventEmitter {
|
||||||
this.journalPattern = this.journalDir + "Journal.*.log"
|
this.journalPattern = this.journalDir + "Journal.*.log"
|
||||||
|
|
||||||
this.currentJournal = this.getLatestJournal()
|
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.
|
// LineReader seems to be async, so start async processes here.
|
||||||
this.location = null
|
this.location = null
|
||||||
|
@ -46,22 +53,20 @@ export class JournalInterface extends EventEmitter {
|
||||||
/* -------------------------------------------------------------------- getLatestJournal ---- */
|
/* -------------------------------------------------------------------- getLatestJournal ---- */
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/15696218/get-the-most-recent-file-in-a-directory-node-js
|
// https://stackoverflow.com/questions/15696218/get-the-most-recent-file-in-a-directory-node-js
|
||||||
getLatestJournal() {
|
getLatestJournal(): string {
|
||||||
const journals = globSync(this.journalPattern)
|
const journals = globSync(this.journalPattern)
|
||||||
|
|
||||||
return max(journals, file => {
|
return max(journals, file => {
|
||||||
const fullPath = path.join(this.journalDir, file)
|
const fullPath = path.join(this.journalDir, file)
|
||||||
return fs.statSync(fullPath).mtime
|
return fs.statSync(fullPath).mtime
|
||||||
})
|
})
|
||||||
|
|
||||||
log(`New journal file found, now watching ${path.basename(this.currentJournal)}.`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ getCurrentLocation ---- */
|
/* ------------------------------------------------------------------ getCurrentLocation ---- */
|
||||||
|
|
||||||
// Get current location on setup, so if app is restarted, user can pick up where they left off
|
// 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.
|
// Rather than waiting til they jump to the next system to use the program again.
|
||||||
getCurrentLocation() {
|
getCurrentLocation(): void {
|
||||||
lineReader.eachLine(this.currentJournal, (raw, last) => {
|
lineReader.eachLine(this.currentJournal, (raw, last) => {
|
||||||
if (raw) { // skip blank line at end of file
|
if (raw) { // skip blank line at end of file
|
||||||
const line = JSON.parse(raw)
|
const line = JSON.parse(raw)
|
||||||
|
@ -85,8 +90,8 @@ export class JournalInterface extends EventEmitter {
|
||||||
/* -------------------------------------------------------------------- getScannedBodies ---- */
|
/* -------------------------------------------------------------------- getScannedBodies ---- */
|
||||||
|
|
||||||
// Look for all scanned bodies before last FSDJump, for same reasons as getCurrentLocation().
|
// Look for all scanned bodies before last FSDJump, for same reasons as getCurrentLocation().
|
||||||
getScannedBodies() {
|
getScannedBodies(): void {
|
||||||
let detailedScanLine = null
|
let detailedScanLine: Object|null = null
|
||||||
|
|
||||||
lineReader.eachLine(this.currentJournal, (raw, last) => {
|
lineReader.eachLine(this.currentJournal, (raw, last) => {
|
||||||
|
|
Loading…
Reference in a new issue