--- import { ObjectId } from 'mongodb'; import { Image } from 'astro:assets'; import { getHighestWeightedLanguage, getLocales, getName } from '../lib/utils/langDriver'; 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(); const lang = await getLocales(Astro.cookies.get('language')?.value ?? await getHighestWeightedLanguage(Astro.request.headers.get('accept-language'))); const planetId = new ObjectId(Astro.cookies.get('currentPlanet')?.value ?? ''); const planet = locationManager.findId(planetId); if(!planet) return; await planet.resources.calculateCurrentAvailableResources(); const resourceArray: (Resource & { capacity: number })[] = []; for(const key of planet.resources.resources) { resourceArray.push({ ...key, capacity: 10_000 }); } if(!(planet instanceof SystemManager)) { const mapStorageToResource: { [key: string]: string } = { "coal-storage": "coal", "iron-storage": "iron", "gold-storage": "gold", "water-tank": "water", "acid-tank": "sulfuric-acid", "nitrogen-tank": "liquid-nitrogen", "hydrogen-tank": "hydrogen", "oxygen-tank": "oxygen", "helium3-tank": "helium-3", } resourceArray.forEach(res => { res.capacity = 10_000; }); for(const building of planet.buildings.buildings) { if(building.data.category === 'storage') { const resource = mapStorageToResource[building.data.id]; if(resource) { const res = resourceArray.find(x => x.id === resource); if(res) res.capacity += building.level * 10_000; } } } } ---
energy
Energy planet.energy.production ? "prod-full" : planet.energy.consumption >= (planet.energy.production * 0.9) ? "prod-almost-full" : ""}`}>{planet.energy.consumption}/{planet.energy.production}
{getName(lang, 'general', 'production')}{planet.energy.production} {getName(lang, 'general', 'consumption')}{planet.energy.consumption} {getName(lang, 'general', 'balance')} planet.energy.production ? "prod-full" : planet.energy.consumption >= (planet.energy.production * 0.9) ? "prod-almost-full" : ""}`}>{planet.energy.production - planet.energy.consumption}
{resourceArray.map(res =>
x.id === res.id)?.type ?? "solid"} data-res-id={res.id} data-res-amount={res.amount} data-res-mining-rate={res.amount >= res.capacity ? 0 : res.perHourMiningRate} data-res-capacity={res.capacity} > x.id === res.id)?.icon ?? "#"} alt={res.id} class="icon" width={32} height={32} />
{getName(lang, 'resources', res.id)} = res.capacity ? "prod-full" : res.amount >= (res.capacity * 0.9) ? "prod-almost-full" : ""}`}>
{getName(lang, 'general', 'avaliable')}{Math.floor(res.amount).toString()} {getName(lang, 'general', 'production')}= res.capacity ? "prod-full" : res.amount >= (res.capacity * 0.9) ? "prod-almost-full" : ""}`}>{res.amount >= res.capacity ? "0" : res.perHourMiningRate.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") ?? "0"} {getName(lang, 'general', 'capacity')}{res.capacity.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}
)}