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++; + } + } + } +} +--- +
{source instanceof SystemManager ? source.data.name : source?.name} | +{f.returning ? "<=" : "=>"} | +{destination instanceof SystemManager ? destination.data.name : destination?.name} | +{f.mission} | +{f.arrivalTime.toISOString()} | ++ |