diff --git a/src/components/StatusBar.astro b/src/components/StatusBar.astro new file mode 100644 index 0000000..ce596a4 --- /dev/null +++ b/src/components/StatusBar.astro @@ -0,0 +1,137 @@ +--- +import { ObjectId } from 'mongodb'; +import locationManager from '../lib/classes/managers/LocationManager'; +import { getAllFleetByUser } from '../lib/db/fleet'; +import SystemManager from '../lib/classes/managers/SystemManager'; + +const userId = new ObjectId(Astro.cookies.get('userid')?.value ?? ''); + +await locationManager.updateFleet(); +const fleet = (await getAllFleetByUser(userId)).filter(f => new Date().getTime() - f.arrivalTime.getTime() < 0); +fleet.sort((a, b) => a.arrivalTime.getTime() - b.arrivalTime.getTime()); + +let own = 0; +let friendly = 0; +let enemy = 0; + +for(const f of fleet) { + const source = locationManager.findId(f.source); + if(source !== null) { + if(source instanceof SystemManager) { + if(source.data.ownedBy.id.equals(userId)) own++; + else if(!f.returning) { + if(f.mission === "SPY" || f.mission === "ATTACK") enemy++; + else friendly++; + } + } else { + if(source.system.data.ownedBy.id.equals(userId)) own++; + else if(!f.returning) { + if(f.mission === "SPY" || f.mission === "ATTACK") enemy++; + else friendly++; + } + } + } +} +--- +
+ + {fleet.map(f => { + const source = locationManager.findId(f.source); + const destination = locationManager.findId(f.destination); + + return ( + + + + + + + ) + })} +
{source instanceof SystemManager ? source.data.name : source?.name}{f.returning ? "<=" : "=>"}{destination instanceof SystemManager ? destination.data.name : destination?.name}{f.mission}{f.arrivalTime.toISOString()}
+
+
{own}
+
+
{friendly}
+
+
{enemy}
+
+
+ + \ No newline at end of file diff --git a/src/layouts/LoggedIn.astro b/src/layouts/LoggedIn.astro index 66340be..b174c4e 100644 --- a/src/layouts/LoggedIn.astro +++ b/src/layouts/LoggedIn.astro @@ -1,6 +1,7 @@ --- import NavBar from '../components/NavBar.astro'; import ResourceBar from '../components/ResourceBar.astro'; +import StatusBar from '../components/StatusBar.astro'; interface Props { id: string; @@ -23,6 +24,7 @@ const { title } = Astro.props;
+