Add ability to choose system as active
This commit is contained in:
parent
40499415be
commit
8f7ca6b9d2
|
@ -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) {
|
|||
<div class="resourcebar-circle-id" data-type="solid"></div>
|
||||
</div>
|
||||
<div class="resourcebar-planetname">
|
||||
{planet.name}
|
||||
{planet instanceof SystemManager ? <span style="color: red;">{planet.data.name}</span> : planet.name}
|
||||
</div>
|
||||
<div id="resourcebar-elements" class="resourcebar-elements">
|
||||
{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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|||
</label>
|
||||
<div class="fleet-send-container">
|
||||
<form method="post">
|
||||
<h1>Sending fleet from {planet.name}</h1>
|
||||
<h1>Sending fleet from {planet instanceof SystemManager ? planet.data.name : planet.name}</h1>
|
||||
<hr />
|
||||
<h2>Ships</h2>
|
||||
<div class="fleet-send-ships">
|
||||
|
|
|
@ -35,6 +35,8 @@ if(Astro.request.method === "POST") {
|
|||
secure: true
|
||||
});
|
||||
}
|
||||
|
||||
return Astro.redirect('/game/systemManager');
|
||||
}
|
||||
---
|
||||
<Layout title="System Manager">
|
||||
|
@ -48,10 +50,22 @@ if(Astro.request.method === "POST") {
|
|||
<a href="/game/systemManager/spaceStations">Space stations</a>
|
||||
<a href="/game/systemManager/asteroids">Asteroids</a>
|
||||
</div>
|
||||
<div class="resources">
|
||||
<p>Resources: {currentSystem.resources.resources.map(r => `${r.id}: ${r.amount}`).join(", ")}</p>
|
||||
</div>
|
||||
<div class="planet-list">
|
||||
<div class="system-card">
|
||||
<h2 style="color: red;">{currentSystem.data.name}<div><form method="post"><input type="hidden" name="planetId" value={currentSystem.data._id.toString()} /><input type="submit" value="Select" /></form></div></h2>
|
||||
<h3>Resources:</h3>
|
||||
<div>
|
||||
{currentSystem.resources.resources.length === 0 ? <span>None</span> : currentSystem.resources.resources.map(res => (
|
||||
<p>{res.data.id} - {res.amount}</p>
|
||||
))}
|
||||
</div>
|
||||
<h3>Ships: </h3>
|
||||
<div>
|
||||
{currentSystem.ships.ships.length === 0 ? <span>None</span> : currentSystem.ships.ships.map(ship => (
|
||||
<p>{ship.data.id} - {ship.amount}</p>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{currentSystem.planets.length === 0 ? <span>No planets in this sector</span> : currentSystem.planets.map(planet => (
|
||||
<div class="planet-card">
|
||||
<h2>{planet.name}<div><form method="post"><input type="hidden" name="planetId" value={planet._id.toString()} /><input type="submit" value="Select" /></form></div></h2>
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue