diff --git a/src/components/ResourceBar.astro b/src/components/ResourceBar.astro index 4441e37..61dcfc1 100644 --- a/src/components/ResourceBar.astro +++ b/src/components/ResourceBar.astro @@ -4,6 +4,7 @@ import { getHighestWeightedLanguage, getLocales, getName } from '../lib/utils/la import { getAllResources } from '../lib/db/resources'; import locationManager from '../lib/classes/managers/LocationManager'; import { Resource } from '../lib/classes/managers/abstract/ResourceManager'; +import SystemManager from '../lib/classes/managers/SystemManager'; const resourceTypes = await getAllResources(); @@ -11,7 +12,7 @@ const lang = await getLocales(Astro.cookies.get('language')?.value ?? await getH const planetId = new ObjectId(Astro.cookies.get('currentPlanet')?.value ?? ''); -const planet = locationManager.getPlanet(planetId); +const planet = locationManager.findId(planetId); if(!planet) return; @@ -27,7 +28,7 @@ for(const key of planet.resources.resources) {
- {planet.name} + {planet instanceof SystemManager ? {planet.data.name} : planet.name}
{resourceArray.map(res => @@ -148,8 +149,8 @@ for(const key of planet.resources.resources) { function numWithPrefix(x: number) { x = Math.floor(x); if(x < 1_000) return x.toString(); - if(x < 1_000_000) return (x / 1_000).toFixed(2) + "k"; - if(x < 1_000_000_000) return (x / 1_000_000).toFixed(2) + "M"; + if(x < 1_000_000) return (x / 1_000).toFixed(3) + "k"; + if(x < 1_000_000_000) return (x / 1_000_000).toFixed(3) + "M"; return x.toString(); } diff --git a/src/pages/game/fleet.astro b/src/pages/game/fleet.astro index a657325..9281c44 100644 --- a/src/pages/game/fleet.astro +++ b/src/pages/game/fleet.astro @@ -23,7 +23,7 @@ if(!user) return Astro.redirect('/logout'); const planetId = Astro.cookies.get('currentPlanet')?.value ?? ""; if(planetId === "") return "No planet selected"; -const planet = locationManager.getPlanet(new ObjectId(planetId)); +const planet = locationManager.findId(new ObjectId(planetId)); if(!planet) return "Planet not found"; const ships = await getAllShips(); @@ -47,7 +47,7 @@ if(Astro.request.method === "POST") { }); const fleetData = { - source: planet._id, + source: planet instanceof SystemManager ? planet.data._id : planet._id, destination: form.get('toSystem') ? form.get('destination-system')?.toString() : form.get('destination-planet')?.toString(), mission: form.get('mission')?.toString() ?? "NULL", ships: ships.map(ship => { @@ -86,28 +86,41 @@ let own = 0; let friendly = 0; let enemy = 0; -for(const system of userSystems) { - for(const planet of system.planets) { - for(const f of fleet) { - if(f.source.equals(planet._id) || f.source.equals(system.data._id)) own++; - else if(f.destination.equals(planet._id) || f.destination.equals(system.data._id)) { - if(f.mission === 'ATTACK') enemy++; - else { - const sourceObj = locationManager.findId(f.source); - const destinationObj = locationManager.findId(f.destination); - - if(!sourceObj || !destinationObj) continue; - - const source = sourceObj instanceof SystemManager ? sourceObj.data.ownedBy.id : sourceObj.system.data.ownedBy.id; - const destination = destinationObj instanceof SystemManager ? destinationObj.data.ownedBy.id : destinationObj.system.data.ownedBy.id; - - if(!source?.equals(destination)) friendly++; - } - } +for(const f of fleet) { + const source = locationManager.findId(f.source); + if(source !== null) { + if(source instanceof SystemManager) { + if(source.data.ownedBy.id.equals(user.id)) own++; + else enemy++; + } else { + if(source.system.data.ownedBy.id.equals(user.id)) own++; + else enemy++; } } } +// for(const system of userSystems) { +// for(const planet of system.planets) { +// for(const f of fleet) { +// if(f.source.equals(planet._id) || f.source.equals(system.data._id)) own++; +// else if(f.destination.equals(planet._id) || f.destination.equals(system.data._id)) { +// if(f.mission === 'ATTACK') enemy++; +// else { +// const sourceObj = locationManager.findId(f.source); +// const destinationObj = locationManager.findId(f.destination); + +// if(!sourceObj || !destinationObj) continue; + +// const source = sourceObj instanceof SystemManager ? sourceObj.data.ownedBy.id : sourceObj.system.data.ownedBy.id; +// const destination = destinationObj instanceof SystemManager ? destinationObj.data.ownedBy.id : destinationObj.system.data.ownedBy.id; + +// if(!source?.equals(destination)) friendly++; +// } +// } +// } +// } +// } + const sectorsList = galaxies.map(galaxy => { return { _id: galaxy._id, @@ -166,7 +179,7 @@ const lang = await getLocales(Astro.cookies.get('language')?.value ?? await getH
-

Sending fleet from {planet.name}

+

Sending fleet from {planet instanceof SystemManager ? planet.data.name : planet.name}


Ships

diff --git a/src/pages/game/systemManager/index.astro b/src/pages/game/systemManager/index.astro index e32610d..c792f66 100644 --- a/src/pages/game/systemManager/index.astro +++ b/src/pages/game/systemManager/index.astro @@ -35,6 +35,8 @@ if(Astro.request.method === "POST") { secure: true }); } + + return Astro.redirect('/game/systemManager'); } --- @@ -48,10 +50,22 @@ if(Astro.request.method === "POST") { Space stations Asteroids
-
-

Resources: {currentSystem.resources.resources.map(r => `${r.id}: ${r.amount}`).join(", ")}

-
+
+

{currentSystem.data.name}

+

Resources:

+
+ {currentSystem.resources.resources.length === 0 ? None : currentSystem.resources.resources.map(res => ( +

{res.data.id} - {res.amount}

+ ))} +
+

Ships:

+
+ {currentSystem.ships.ships.length === 0 ? None : currentSystem.ships.ships.map(ship => ( +

{ship.data.id} - {ship.amount}

+ ))} +
+
{currentSystem.planets.length === 0 ? No planets in this sector : currentSystem.planets.map(planet => (

{planet.name}

@@ -109,6 +123,13 @@ if(Astro.request.method === "POST") { margin-bottom: 1rem; } + .ships { + display: flex; + flex-direction: row; + justify-content: center; + margin-bottom: 1rem; + } + .planet-list { display: flex; flex-direction: row;