Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
988 B · 34 lines
TSX
at develop
1234567891011121314151617181920212223242526272829303132333435import { pubsub } from "@thorium/.server/init/pubsub";import { t } from "@thorium/.server/init/t";import z from "zod";
const alertLevelValues = z.union([ z.literal("5"), z.literal("4"), z.literal("3"), z.literal("2"), z.literal("1"), z.literal("p"),]);export const alertLevel = t.router({ update: t.procedure .meta({ action: true, event: true }) .input( z.object({ shipId: z.number(), alertLevel: alertLevelValues, }), ) .output(z.object({ alertLevel: alertLevelValues, shipId: z.number() })) .send(({ ctx, input }) => { const ship = ctx.ecs.getEntityById(input.shipId || -1); if (!ship?.components.isShip) throw new Error("Ship not found");
ship.updateComponent("isShip", { alertLevel: input.alertLevel }); pubsub.publish.ship.player({ shipId: ship.id }); pubsub.publish.ship.get({ shipId: ship.id }); pubsub.publish.starmapCore.object({ objectId: ship.id });
return { shipId: ship.id, alertLevel: input.alertLevel }; }),});