Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142import type { Entity } from "@thorium/utils/ecs";
import { getInventoryTemplates } from "../getInventoryTemplates";import { getDeckNode } from "./getDeckNode";
/** * Get the inventory currently located in the room associated with this reactor * @param reactor - An ECS entity * @returns */export function getReactorInventory(reactor: Entity) { let systemShip: Entity | null = null; for (const system of reactor.ecs?.systems || []) { if (system.constructor.name === "FilterShipsWithReactors") { for (const [_, ship] of system.entities || []) { if (ship.components.shipSystems?.shipSystems.has(reactor.id)) { systemShip = ship; break; } } } }
if (!systemShip) return null;
const entityRoomId = systemShip.components.shipSystems?.shipSystems.get(reactor.id)?.roomId; const entityRoom = getDeckNode(entityRoomId, systemShip);
const inventoryTemplates = getInventoryTemplates(reactor.ecs); const roomInventory = Object.entries(entityRoom?.contents || {}).map(([key, { count }]) => { const inventoryItem = inventoryTemplates[key]; return { room: entityRoom, ...inventoryItem, count, name: key, }; });
return roomInventory;}