diff --git a/src/components/ResourceBar.astro b/src/components/ResourceBar.astro
index c4d367e..bd2eb53 100644
--- a/src/components/ResourceBar.astro
+++ b/src/components/ResourceBar.astro
@@ -67,7 +67,7 @@ if(!(planet instanceof SystemManager)) {
{resourceArray.map(res =>
-
x.id === res.id)?.type ?? "solid"}
data-res-id={res.id}
data-res-amount={res.amount}
diff --git a/src/pages/api/fleet/getDistance.ts b/src/pages/api/fleet/getDistance.ts
new file mode 100644
index 0000000..2803355
--- /dev/null
+++ b/src/pages/api/fleet/getDistance.ts
@@ -0,0 +1,50 @@
+import { APIRoute } from "astro";
+import parseParams from "../../../lib/utils/parseParams";
+import locationManager, { Sector } from "../../../lib/classes/managers/LocationManager";
+import SystemManager from "../../../lib/classes/managers/SystemManager";
+import { Planet } from "../../../lib/classes/managers/PlanetManager";
+import getDistanceBetween from "../../../lib/utils/getDistanceBetween";
+
+export const GET: APIRoute = async({ request }) => {
+ const URLParams = parseParams(request.url);
+ if(!URLParams.source || !URLParams.destination) {
+ return new Response(
+ JSON.stringify({
+ code: 400,
+ message: "Bad Request",
+ error: "Missing parameters"
+ }), { status: 400 }
+ );
+ }
+
+ const source = locationManager.findId(URLParams.source);
+ if(source === null) {
+ return new Response(
+ JSON.stringify({
+ code: 404,
+ message: "Not Found",
+ error: "Source not found"
+ }), { status: 404 }
+ );
+ }
+
+ let destination: Planet | SystemManager | Sector | null = locationManager.findId(URLParams.destination);
+ if(destination === null) destination = locationManager.getSector(URLParams.destination) ?? null;
+ if(destination === null) {
+ return new Response(
+ JSON.stringify({
+ code: 404,
+ message: "Not Found",
+ error: "Destination not found"
+ }), { status: 404 }
+ );
+ }
+
+ return new Response(
+ JSON.stringify({
+ code: 200,
+ message: "OK",
+ distance: getDistanceBetween(source, destination)
+ }), { status: 200 }
+ )
+}
\ No newline at end of file
diff --git a/src/pages/game/fleet.astro b/src/pages/game/fleet.astro
index 394a81b..36e8f96 100644
--- a/src/pages/game/fleet.astro
+++ b/src/pages/game/fleet.astro
@@ -11,6 +11,7 @@ import { getName } from '../../lib/utils/langDriver';
const { token, user, lang } = Astro.locals;
const active: SystemManager | Planet = Astro.locals.active;
+const activeId = active instanceof SystemManager ? active.data._id : active._id;
const ships = await getAllShips();
const url = Astro.url.origin;
@@ -82,10 +83,10 @@ for(const f of fleet) {
if(source !== null) {
if(source instanceof SystemManager) {
if(source.data.ownedBy.id.equals(user.id)) own++;
- else enemy++;
+ else if(!f.returning) enemy++;
} else {
if(source.system.data.ownedBy.id.equals(user.id)) own++;
- else enemy++;
+ else if(!f.returning) enemy++;
}
}
}
@@ -152,14 +153,14 @@ const sectorsList = galaxies.map(galaxy => {