Add indicators for fleet origin
This commit is contained in:
parent
f9c5506267
commit
3d55f7060c
|
@ -3,6 +3,7 @@ import { ObjectId } from 'mongodb';
|
||||||
import locationManager from '../lib/classes/managers/LocationManager';
|
import locationManager from '../lib/classes/managers/LocationManager';
|
||||||
import { getAllFleetByUser } from '../lib/db/fleet';
|
import { getAllFleetByUser } from '../lib/db/fleet';
|
||||||
import SystemManager from '../lib/classes/managers/SystemManager';
|
import SystemManager from '../lib/classes/managers/SystemManager';
|
||||||
|
import DBFleet from '../types/db/DBFleet';
|
||||||
|
|
||||||
const userId = new ObjectId(Astro.cookies.get('userid')?.value ?? '');
|
const userId = new ObjectId(Astro.cookies.get('userid')?.value ?? '');
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ let own = 0;
|
||||||
let friendly = 0;
|
let friendly = 0;
|
||||||
let enemy = 0;
|
let enemy = 0;
|
||||||
|
|
||||||
const filteredFleet = fleet.filter(f => {
|
const filteredFleet: (DBFleet & { which?: "own" | "friendly" | "enemy" })[] = fleet.filter(f => {
|
||||||
const source = locationManager.findId(f.source);
|
const source = locationManager.findId(f.source);
|
||||||
if(source !== null) {
|
if(source !== null) {
|
||||||
if(source instanceof SystemManager) return source.data.ownedBy.id.equals(userId)
|
if(source instanceof SystemManager) return source.data.ownedBy.id.equals(userId)
|
||||||
|
@ -26,16 +27,34 @@ for(const f of filteredFleet) {
|
||||||
const source = locationManager.findId(f.source);
|
const source = locationManager.findId(f.source);
|
||||||
if(source !== null) {
|
if(source !== null) {
|
||||||
if(source instanceof SystemManager) {
|
if(source instanceof SystemManager) {
|
||||||
if(source.data.ownedBy.id.equals(userId)) own++;
|
if(source.data.ownedBy.id.equals(userId)) {
|
||||||
|
own++;
|
||||||
|
f.which = "own";
|
||||||
|
}
|
||||||
else if(!f.returning) {
|
else if(!f.returning) {
|
||||||
if(f.mission === "SPY" || f.mission === "ATTACK") enemy++;
|
if(f.mission === "SPY" || f.mission === "ATTACK") {
|
||||||
else friendly++;
|
enemy++;
|
||||||
|
f.which = "enemy";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
friendly++;
|
||||||
|
f.which = "friendly";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(source.system.data.ownedBy.id.equals(userId)) own++;
|
if(source.system.data.ownedBy.id.equals(userId)) {
|
||||||
|
own++;
|
||||||
|
f.which = "own";
|
||||||
|
}
|
||||||
else if(!f.returning) {
|
else if(!f.returning) {
|
||||||
if(f.mission === "SPY" || f.mission === "ATTACK") enemy++;
|
if(f.mission === "SPY" || f.mission === "ATTACK") {
|
||||||
else friendly++;
|
enemy++;
|
||||||
|
f.which = "enemy";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
friendly++;
|
||||||
|
f.which = "friendly";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +70,7 @@ for(const f of filteredFleet) {
|
||||||
<td class="fleet-item-text source">{source instanceof SystemManager ? source.data.name : source?.name}</td>
|
<td class="fleet-item-text source">{source instanceof SystemManager ? source.data.name : source?.name}</td>
|
||||||
<td class="fleet-item-text">{f.returning ? "<=" : "=>"}</td>
|
<td class="fleet-item-text">{f.returning ? "<=" : "=>"}</td>
|
||||||
<td class="fleet-item-text destination">{destination instanceof SystemManager ? destination.data.name : destination?.name}</td>
|
<td class="fleet-item-text destination">{destination instanceof SystemManager ? destination.data.name : destination?.name}</td>
|
||||||
<td class="fleet-item-text mission">{f.mission}</td>
|
<td class={`fleet-item-text mission fleet-count-${f.which}`}>{f.mission}</td>
|
||||||
<td class="fleet-item-text arrival">{f.arrivalTime.toISOString()}</td>
|
<td class="fleet-item-text arrival">{f.arrivalTime.toISOString()}</td>
|
||||||
<td class="fleet-item-text eta"></td>
|
<td class="fleet-item-text eta"></td>
|
||||||
</tr>)
|
</tr>)
|
||||||
|
|
Loading…
Reference in New Issue