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