Body/System js -> ts

This commit is contained in:
punkfairie 2023-05-10 21:44:54 -07:00
parent ad2786d735
commit fd4f072bde
2 changed files with 15 additions and 14 deletions

View file

@ -74,7 +74,7 @@ export interface starScan<scanType> extends journalEntry<'Scan'> {
RotationPeriod: number, RotationPeriod: number,
AxialTilt: number, AxialTilt: number,
WasDiscovered: boolean, WasDiscovered: boolean,
WasMapped: false, WasMapped: boolean,
} }
export interface asteroidScan<scanType> extends journalEntry<'Scan'> { export interface asteroidScan<scanType> extends journalEntry<'Scan'> {
@ -86,7 +86,7 @@ export interface asteroidScan<scanType> extends journalEntry<'Scan'> {
SystemAddress: number, SystemAddress: number,
DistanceFromArrivalLS: number, DistanceFromArrivalLS: number,
WasDiscovered: boolean, WasDiscovered: boolean,
WasMapped: false, WasMapped: boolean,
} }
export interface planetScan<scanType> extends journalEntry<'Scan'> { export interface planetScan<scanType> extends journalEntry<'Scan'> {

View file

@ -1,5 +1,6 @@
import type { autoScan, detailedScan } from "../@types/journalLines" import type { asteroidScan, autoScan, detailedScan, planetScan, starScan } from "../@types/journalLines"
export interface Body extends starScan<'AutoScan'|'DetailedScan'>, asteroidScan<'AutoScan'|'DetailedScan'>, planetScan<'AutoScan'|'DetailedScan'> {}
export class Body { export class Body {
DSSDone: boolean DSSDone: boolean
@ -13,26 +14,26 @@ export class Body {
/* -------------------------------------------------------------------------- isAsteroid ---- */ /* -------------------------------------------------------------------------- isAsteroid ---- */
isAsteroid() { isAsteroid(): boolean {
return this.BodyName.includes('Belt') return this.BodyName.includes('Belt')
} }
/* ---------------------------------------------------------------------------- isPlanet ---- */ /* ---------------------------------------------------------------------------- isPlanet ---- */
isPlanet() { isPlanet(): boolean {
return !!this.PlanetClass return !!this.PlanetClass
} }
/* ------------------------------------------------------------------------------ isStar ---- */ /* ------------------------------------------------------------------------------ isStar ---- */
isStar() { isStar(): boolean {
return !!this.StarType return !!this.StarType
} }
/* ---------------------------------------------------------------------------- nameIcon ---- */ /* ---------------------------------------------------------------------------- nameIcon ---- */
nameIcon() { nameIcon(): string|null {
let nameIcon = null let nameIcon: string|null = null
if (this.isAsteroid()) { if (this.isAsteroid()) {
nameIcon = 'asteroid-4' nameIcon = 'asteroid-4'
@ -47,19 +48,19 @@ export class Body {
/* -------------------------------------------------------------------------- simpleName ---- */ /* -------------------------------------------------------------------------- simpleName ---- */
simpleName() { simpleName(): string {
return this.BodyName.replace(this.StarSystem, '') return this.BodyName.replace(this.StarSystem, '')
} }
/* ---------------------------------------------------------------------------- typeIcon ---- */ /* ---------------------------------------------------------------------------- typeIcon ---- */
typeIcon() { typeIcon(): string|null {
let typeIcon = null let typeIcon: string|null = null
if (this.isStar() || this.isAsteroid()) { if (this.isStar() || this.isAsteroid()) {
typeIcon = this.nameIcon() typeIcon = this.nameIcon()
} else { } else {
const planetClass = this.PlanetClass.toLowerCase() const planetClass: string = this.PlanetClass.toLowerCase()
if (planetClass.includes('metal')) { if (planetClass.includes('metal')) {
typeIcon = 'ingot' typeIcon = 'ingot'
@ -81,7 +82,7 @@ export class Body {
/* ---------------------------------------------------------------------------- distance ---- */ /* ---------------------------------------------------------------------------- distance ---- */
distance() { distance(): string {
return Intl.NumberFormat().format(Math.round(this.DistanceFromArrivalLS)) return Intl.NumberFormat().format(Math.round(this.DistanceFromArrivalLS))
} }
} }