ed-safari/src/models/Body.ts

88 lines
2.8 KiB
TypeScript
Raw Normal View History

2023-05-10 21:44:54 -07:00
import type { asteroidScan, autoScan, detailedScan, planetScan, starScan } from "../@types/journalLines"
2023-05-10 21:30:06 -07:00
2023-05-10 21:44:54 -07:00
export interface Body extends starScan<'AutoScan'|'DetailedScan'>, asteroidScan<'AutoScan'|'DetailedScan'>, planetScan<'AutoScan'|'DetailedScan'> {}
export class Body {
2023-05-10 21:30:06 -07:00
DSSDone: boolean
2023-05-10 21:44:54 -07:00
2023-05-10 21:30:06 -07:00
constructor(journalLine: autoScan|detailedScan|null = null, DSS: boolean = false) {
this.DSSDone = DSS
if (journalLine !== null) {
Object.assign(this, journalLine)
}
}
/* -------------------------------------------------------------------------- isAsteroid ---- */
2023-05-10 21:44:54 -07:00
isAsteroid(): boolean {
return this.BodyName.includes('Belt')
}
/* ---------------------------------------------------------------------------- isPlanet ---- */
2023-05-10 21:44:54 -07:00
isPlanet(): boolean {
return !!this.PlanetClass
}
/* ------------------------------------------------------------------------------ isStar ---- */
2023-05-10 21:44:54 -07:00
isStar(): boolean {
return !!this.StarType
}
/* ---------------------------------------------------------------------------- nameIcon ---- */
2023-05-10 21:44:54 -07:00
nameIcon(): string|null {
let nameIcon: string|null = null
if (this.isAsteroid()) {
nameIcon = 'asteroid-4'
} else if (this.isStar()) {
nameIcon = 'star'
} else if (this.isPlanet()) {
nameIcon = 'jupiter-3'
}
return nameIcon
}
/* -------------------------------------------------------------------------- simpleName ---- */
2023-05-10 21:44:54 -07:00
simpleName(): string {
return this.BodyName.replace(this.StarSystem, '')
}
/* ---------------------------------------------------------------------------- typeIcon ---- */
2023-05-10 21:44:54 -07:00
typeIcon(): string|null {
let typeIcon: string|null = null
if (this.isStar() || this.isAsteroid()) {
typeIcon = this.nameIcon()
} else {
2023-05-10 21:44:54 -07:00
const planetClass: string = this.PlanetClass.toLowerCase()
if (planetClass.includes('metal')) {
typeIcon = 'ingot'
} else if (planetClass.includes('icy')) {
typeIcon = 'snowflake'
} else if (planetClass.includes('earth')) {
typeIcon = 'earth'
} else if (planetClass.includes('gas giant')) {
typeIcon = 'jupiter-1'
} else if (planetClass.includes('rock')) {
typeIcon = 'asteroid-3'
} else if (planetClass.includes('water') || planetClass.includes('ammonia')) {
typeIcon = 'water-drops'
}
}
return typeIcon
}
/* ---------------------------------------------------------------------------- distance ---- */
2023-05-10 21:44:54 -07:00
distance(): string {
return Intl.NumberFormat().format(Math.round(this.DistanceFromArrivalLS))
}
}