2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-03 17:13:43 -04:00

Update Status Fuel Display

Start working on Explorer Panel
Backend now uses polymorphic de/serialization (net9)
This commit is contained in:
2024-05-17 23:40:36 +10:00
parent d4f3476ad3
commit 337a9d5ea0
14 changed files with 684 additions and 538 deletions

View File

@ -17,6 +17,7 @@
let loading = $state(true);
let alert: JournalBase[] = $state([]);
let fuelDown = $state(false);
onMount(async () => {
@ -39,17 +40,19 @@
last.push(message.fuel?.fuelMain ?? 0);
const change = [];
for (let i = last.length - 1; i === 0; i--) {
for (let i = last.length - 1; i > 0; i--) {
change.push(last[i] - last[i - 1]);
}
const avg = change.length ? change.reduce((a, b) => a + b, 0) / change.length : 0;
const max = 32;
if ($statusStore.fuel?.fuelMain && avg) {
timeToMax = (max - $statusStore.fuel?.fuelMain) / avg;
const currentEmpty = (max - message.fuel?.fuelMain);
if (message.fuel?.fuelMain && !Number.isNaN(avg) && avg) {
fuelDown = avg < 0;
timeToMax = fuelDown ? (message.fuel?.fuelMain / -avg) : currentEmpty / avg ;
}
console.log($statusStore);
console.log(message);
});
$connection.on("JournalUpdated", (message) => {
@ -97,7 +100,7 @@
<div>
{#if $statusStore}
<span
>Fuel%: {(($statusStore.fuel?.fuelMain ?? 0) / 32) * 100}% est: {timeToMax}s</span
>Fuel%: {((($statusStore.fuel?.fuelMain ?? 0) / 32) * 100).toFixed(2)}% est{fuelDown ? ' REMAINING' : ' to fill'}: {timeToMax.toFixed(2 )}s</span
>
<div class="power">
<div class="sys">
@ -148,6 +151,7 @@
height: 100%;
flex-direction: column-reverse;
align-items: center;
min-width: 2vw;
div.pip {
min-width: 2vw;
min-height: 1vh;

View File

@ -1,29 +1,91 @@
<script lang="ts">
const data: unknown[] = [{}, {}, {}, {}];
// number of scans completed
const scanned = 2;
import connection from "$lib/stores/Connection.store";
import type { FSSDiscoveryScan } from "../../types/api/FSSDiscoveryScan";
import type { Scan } from "../../types/api/Scan";
import type JournalBase from "../../types/api/JournalBase";
const data: Partial<Scan>[] = [{}, {}, {}, {}];
// total bodies in the current system (FSSDiscovery event)
const totalBodies = 12;
let totalBodies = $state(0);
let currentSystem = $state("");
// accumulated list of bodies in the current system (Scan events)
const bodies = $state([
{ value: 50 },
{ value: 1000 },
{ value: 800000 },
{ value: 800000 },
]);
let scans = $state([] as Scan[]);
const targetEvents = ["Scan", "FSSScanBaryCenter", "FSSDiscoveryScan"];
$connection.on("JournalUpdated", (messages: JournalBase[]) => {
const filtered = messages.filter((message) =>
targetEvents.includes(message.event)
);
if (!filtered.length) return;
for (let i = 0; i < filtered.length; i++) {
const message = filtered[i];
switch (message.event) {
case "FSSDiscoveryScan": {
// initial scan when jumping into a system
const scan = message as FSSDiscoveryScan;
totalBodies = scan.bodyCount;
if (currentSystem !== scan.systemName) {
scans = [];
currentSystem = scan.systemName;
}
break;
}
case "Scan": {
// contains all information about a scanned body (resources, biology, mapping/discovery status, body type, etc.)
const scan = message as Scan;
if (currentSystem !== scan.starSystem) {
currentSystem = scan.starSystem;
scans = [];
}
scans.push(scan);
break;
}
case "FSSAllBodiesFound": {
// when all bodies in a system have been scanned
break;
}
default:
console.log(message);
break;
}
}
});
const toShortPlanetClass = (planetClass?: string) => {
switch (planetClass) {
case "High metal content":
case "High metal content body":
return "HMC";
case "Sudarsky class I gas giant":
case "Sudarsky class II gas giant":
case "Sudarsky class III gas giant":
case "Sudarsky class IV gas giant":
return "GAS";
default:
return planetClass;
}
};
</script>
<section>
<div class="title">
<h1>Explorer</h1>
</div>
Current System: {currentSystem}
<!-- summary & high value targets -->
<h1>Bodies</h1>
Scan:&nbsp;<span>{scanned}</span>/<span>{totalBodies}</span>
Scan:&nbsp;<span>{scans.length}</span>/<span>{totalBodies}</span>
<div class="title">High Value (>500kcr)</div>
<ol>
{#each bodies.filter((b) => b.value > 500000) as body}
<li>[HMC/WW/ELT/ELN] $body.name - {body.value}cr</li>
<li>example</li>
{#each scans as body}
<li>
[HMC/WW/ELT/ELN] {toShortPlanetClass(body.planetClass)}
{body.bodyName} - 0cr
</li>
{/each}
</ol>
<br />
@ -78,7 +140,7 @@
<style lang="scss">
section {
margin-top: 5px;
max-height: 500px;
max-height: 300px;
overflow-y: scroll;
}

View File

@ -0,0 +1,11 @@
import type JournalBase from "./JournalBase";
export interface FSSDiscoveryScan extends JournalBase {
event: "FSSDiscoveryScan";
systemName: string;
systemAddress: number;
progress: number;
bodyCount: number;
nonBodyCount: number;
timestamp: string | Date;
}

View File

@ -1,4 +1,4 @@
export default interface JournalBase {
event: string;
timestamp: Date;
timestamp: Date | string;
}

View File

@ -0,0 +1,62 @@
import type JournalBase from "./JournalBase";
export interface Scan extends JournalBase {
event: "Scan";
/** may include "Detailed" = via FSS, "AutoScan" = via proximity, "NavBeaconDetail", etc. */
scanType: string;
bodyName: string;
distanceFromArrivalLS: number;
tidalLock: boolean;
massEM: number;
radius: number;
surfaceGravity: number;
surfaceTemperature: number;
surfacePressure: number;
landable: boolean;
rotationPeriod: number;
axialTilt: number;
/** if the body is a star, the star class */
starType?: string;
subclass: number;
stellarMass: number;
absoluteMagnitude: number;
age_MY: number;
luminosity: string;
wasDiscovered: boolean;
wasMapped: boolean;
starSystem: string;
systemAddress: number;
bodyID: number;
semiMajorAxis: number;
eccentricity: number;
orbitalInclination: number;
periapsis: number;
orbitalPeriod: number;
ascendingNode: number;
meanAnomaly: number;
timestamp: Date | string;
parents?: Parent[];
terraformState?: string;
/** if the body is a planet, the planet class */
planetClass?: string;
atmosphere?: string;
atmosphereType?: string;
atmosphereComposition?: AtmosphereComposition[];
volcanism?: string;
composition?: Composition;
}
export interface AtmosphereComposition {
name: string;
percent: number;
}
export interface Composition {
ice: number;
rock: number;
metal: number;
}
export interface Parent {
star: number;
}