Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127import { pubsub } from "@thorium/.server/init/pubsub";import { t } from "@thorium/.server/init/t";import { getShipSystem } from "@thorium/utils/.server/ship/getShipSystem";import { shipPubsubFilter } from "@thorium/utils/.server/shipPubsubFilter";import z from "zod";
export const thrusters = t.router({ get: t.procedure .input(z.object({ shipId: z.number() })) .filter(shipPubsubFilter) .autoPublish( ["isThrusters"], (entity) => entity.components.isShipSystem && { shipId: entity.components.isShipSystem?.shipId, }, ) .request(({ ctx, input }) => { const thrusters = getShipSystem(ctx.ecs, { systemType: "thrusters", shipId: input.shipId, }); const ship = ctx.ecs.getEntityById(input.shipId); const rotation = ship?.components.rotation; if (!thrusters) throw new Error( `No thrusters assigned to ship ${ship?.components.identity?.name || input.shipId}`, ); return { id: thrusters.id, rotation: { yaw: rotation?.yaw || 0, pitch: rotation?.pitch || 0, roll: rotation?.roll || 0, }, direction: thrusters.components.isThrusters!.direction, requiredRotation: thrusters.components.isThrusters!.requiredRotation, rotationSpeed: thrusters.components.isThrusters!.rotationMaxSpeed, directionSpeed: thrusters.components.isThrusters!.directionMaxSpeed, }; }), setRequiredRotation: t.procedure .input( z.object({ shipId: z.number(), rotation: z .object({ yaw: z.number(), pitch: z.number(), roll: z.number(), }) .partial(), }), ) .send(({ ctx, input }) => { const thrusters = getShipSystem(ctx.ecs, { systemType: "thrusters", shipId: input.shipId, }); const ship = ctx.ecs.getEntityById(input.shipId);
if (!thrusters) throw new Error( `No thrusters assigned to ship ${ship?.components.identity?.name || input.shipId}`, );
thrusters.updateComponent("isThrusters", { requiredRotation: { yaw: 0, pitch: 0, roll: 0, ...thrusters.components.isThrusters?.requiredRotation, ...input.rotation, }, }); pubsub.publish.legacy.thrusters.get({ shipId: input.shipId }); }), setRotationSpeed: t.procedure .input( z.object({ shipId: z.number(), rotationSpeed: z.number(), }), ) .send(({ ctx, input }) => { const thrusters = getShipSystem(ctx.ecs, { systemType: "thrusters", shipId: input.shipId, }); const ship = ctx.ecs.getEntityById(input.shipId);
if (!thrusters) throw new Error( `No thrusters assigned to ship ${ship?.components.identity?.name || input.shipId}`, );
thrusters.updateComponent("isThrusters", { rotationMaxSpeed: input.rotationSpeed, }); pubsub.publish.legacy.thrusters.get({ shipId: input.shipId }); }), setDirectionSpeed: t.procedure .input( z.object({ shipId: z.number(), directionSpeed: z.number(), }), ) .send(({ ctx, input }) => { const thrusters = getShipSystem(ctx.ecs, { systemType: "thrusters", shipId: input.shipId, }); const ship = ctx.ecs.getEntityById(input.shipId);
if (!thrusters) throw new Error( `No thrusters assigned to ship ${ship?.components.identity?.name || input.shipId}`, );
thrusters.updateComponent("isThrusters", { directionMaxSpeed: input.directionSpeed, }); pubsub.publish.legacy.thrusters.get({ shipId: input.shipId }); }),});