Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
1.5 kB · 46 lines
TypeScript
at develop
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import { t } from "@thorium/.server/init/t";import type { Entity } from "@thorium/utils/ecs";import z from "zod";
export const viewscreen = t.router({ system: t.procedure .input(z.object({ clientId: z.string() })) .autoPublish([], () => null) .request(({ ctx, input }) => { const systemId = ctx.getPlayerShip(input.clientId)?.components.position?.parentId; if (typeof systemId !== "number") return null; const system = ctx.flight?.ecs.getEntityById(systemId); if (!system) return null;
return { id: system.id, name: system.components.identity?.name, skyboxKey: system.components.isSolarSystem?.skyboxKey, }; }), stream: t.procedure.input(z.object({ shipId: z.number() })).dataStream(({ ctx, input }) => { const set = new Set<Entity>(); const ship = ctx.ecs.getEntityById(input.shipId); const systemId = ship?.components.position?.parentId; if (typeof systemId === "undefined") { return set; } for (const entity of ctx.ecs.componentCache.get("isImpulseEngines") || []) { if (entity.components.isShipSystem?.shipId === input.shipId) { set.add(entity); } } for (const entity of ctx.ecs.componentCache.get("isWarpEngines") || []) { if (entity.components.isShipSystem?.shipId === input.shipId) { set.add(entity); } }
for (const entity of ctx.ecs.componentCache.get("position") || []) { if (entity.components.position?.parentId === systemId) { set.add(entity); } } return set; }),});