UNPKG

@battle-racing/br-common-lib

Version:

Common library for all Battle Racing Repositorios

142 lines (141 loc) 7.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.allCommandsConfigSchema = exports.steeringWheelModuleCommandSchema = exports.screenModuleCommandSchema = exports.rightStarFrontLaserModuleCommandSchema = exports.leftStarBackLaserModuleCommandSchema = exports.rgbModuleCommandSchema = exports.flagModuleCommandSchema = exports.diskSensorBallShooterModuleCommandSchema = exports.ballSensorDiskThrowerModuleCommandSchema = exports.soundModuleCommandSchema = exports.playSoundActionCommandOptionsSchema = exports.speedModuleCommandSchema = exports.changeSpeedActionCommandOptionsSchema = void 0; const zod_1 = require("zod"); const hardware_1 = require("../hardware"); const utils_1 = require("../utils"); // Helper for arithmetic expressions const arithmeticOrNumberSchema = zod_1.z.union([zod_1.z.number(), utils_1.arithmeticExpressionSchema]); // --- Speed Commands --- exports.changeSpeedActionCommandOptionsSchema = hardware_1.speedChangeOptionsSchema.omit({ speed: true }).extend({ speed: arithmeticOrNumberSchema, }); exports.speedModuleCommandSchema = zod_1.z.union([ zod_1.z.object({ module: zod_1.z.literal('speed'), action: zod_1.z.literal('activate') }), zod_1.z.object({ module: zod_1.z.literal('speed'), action: zod_1.z.literal('deactivate') }), zod_1.z.object({ module: zod_1.z.literal('speed'), action: zod_1.z.literal('change'), params: exports.changeSpeedActionCommandOptionsSchema }), zod_1.z.object({ module: zod_1.z.literal('speed'), action: zod_1.z.literal('configure'), params: hardware_1.speedConfigurationSchema }), ]); // --- Sound Commands --- exports.playSoundActionCommandOptionsSchema = hardware_1.playSoundOptionsSchema.omit({ durationMs: true }).extend({ durationMs: arithmeticOrNumberSchema.optional(), }); exports.soundModuleCommandSchema = zod_1.z.object({ module: zod_1.z.literal('sound'), action: zod_1.z.literal('play'), params: exports.playSoundActionCommandOptionsSchema, }); // --- Ball Sensor / Disk Thrower --- exports.ballSensorDiskThrowerModuleCommandSchema = zod_1.z.union([ zod_1.z.object({ module: zod_1.z.literal('ballSensorDiskThrower'), action: zod_1.z.literal('activateSensor') }), zod_1.z.object({ module: zod_1.z.literal('ballSensorDiskThrower'), action: zod_1.z.literal('deactivateSensor') }), zod_1.z.object({ module: zod_1.z.literal('ballSensorDiskThrower'), action: zod_1.z.literal('configureModule'), params: hardware_1.configureBallSensorDiskThrowerModuleOptionsSchema, }), zod_1.z.object({ module: zod_1.z.literal('ballSensorDiskThrower'), action: zod_1.z.literal('throwDisk') }), zod_1.z.object({ module: zod_1.z.literal('ballSensorDiskThrower'), action: zod_1.z.literal('activateDiskThrower') }), zod_1.z.object({ module: zod_1.z.literal('ballSensorDiskThrower'), action: zod_1.z.literal('deactivateDiskThrower') }), ]); // --- Disk Sensor / Ball Shooter --- exports.diskSensorBallShooterModuleCommandSchema = zod_1.z.union([ zod_1.z.object({ module: zod_1.z.literal('diskSensorBallShooter'), action: zod_1.z.literal('configure'), params: hardware_1.configDiskSensorBallShooterModuleOptionsSchema, }), zod_1.z.object({ module: zod_1.z.literal('diskSensorBallShooter'), action: zod_1.z.literal('prepareShooter') }), zod_1.z.object({ module: zod_1.z.literal('diskSensorBallShooter'), action: zod_1.z.literal('shootBall') }), zod_1.z.object({ module: zod_1.z.literal('diskSensorBallShooter'), action: zod_1.z.literal('activateSensor') }), zod_1.z.object({ module: zod_1.z.literal('diskSensorBallShooter'), action: zod_1.z.literal('deactivateSensor') }), zod_1.z.object({ module: zod_1.z.literal('diskSensorBallShooter'), action: zod_1.z.literal('calibrateSensor') }), ]); // --- Flag --- exports.flagModuleCommandSchema = zod_1.z.union([ zod_1.z.object({ module: zod_1.z.literal('flag'), action: zod_1.z.literal('activate') }), zod_1.z.object({ module: zod_1.z.literal('flag'), action: zod_1.z.literal('deactivate') }), zod_1.z.object({ module: zod_1.z.literal('flag'), action: zod_1.z.literal('configure'), params: hardware_1.flagConfigurationOptionsSchema }), zod_1.z.object({ module: zod_1.z.literal('flag'), action: zod_1.z.literal('showMediaIndefinitely'), params: hardware_1.flagShowMediaOptionsSchema, }), zod_1.z.object({ module: zod_1.z.literal('flag'), action: zod_1.z.literal('showMediaTemporarily'), params: hardware_1.flagShowMediaOptionsSchema, }), ]); // --- RGB --- exports.rgbModuleCommandSchema = zod_1.z.union([ zod_1.z.object({ module: zod_1.z.literal('rgb'), action: zod_1.z.literal('configure'), params: hardware_1.rgbConfigurationOptionsSchema }), zod_1.z.object({ module: zod_1.z.literal('rgb'), action: zod_1.z.literal('showEffect'), params: hardware_1.rgbShowEffectOptionsSchema }), ]); // --- Star Laser --- exports.leftStarBackLaserModuleCommandSchema = zod_1.z.union([ zod_1.z.object({ module: zod_1.z.literal('leftStarBackLaser'), action: zod_1.z.literal('action'), params: hardware_1.starLaserSendActionsOptionsSchema, }), zod_1.z.object({ module: zod_1.z.literal('leftStarBackLaser'), action: zod_1.z.literal('configure'), params: hardware_1.starLaserConfigureModuleOptionsSchema, }), ]); exports.rightStarFrontLaserModuleCommandSchema = zod_1.z.union([ zod_1.z.object({ module: zod_1.z.literal('rightStarFrontLaser'), action: zod_1.z.literal('action'), params: hardware_1.starLaserSendActionsOptionsSchema, }), zod_1.z.object({ module: zod_1.z.literal('rightStarFrontLaser'), action: zod_1.z.literal('configure'), params: hardware_1.starLaserConfigureModuleOptionsSchema, }), ]); // --- Screen (New) --- exports.screenModuleCommandSchema = zod_1.z.union([ zod_1.z.object({ module: zod_1.z.literal('screen'), action: zod_1.z.literal('showHomeView') }), zod_1.z.object({ module: zod_1.z.literal('screen'), action: zod_1.z.literal('showCountdownView'), params: hardware_1.screenCountdownParamsSchema, }), zod_1.z.object({ module: zod_1.z.literal('screen'), action: zod_1.z.literal('updateGameView'), params: hardware_1.screenUpdateGameViewInputSchema, }), zod_1.z.object({ module: zod_1.z.literal('screen'), action: zod_1.z.literal('showScreenVictoryView'), params: hardware_1.screenFinishViewInputSchema, }), zod_1.z.object({ module: zod_1.z.literal('screen'), action: zod_1.z.literal('showScreenDefeatView'), params: hardware_1.screenFinishViewInputSchema, }), ]); // --- Steering Wheel --- exports.steeringWheelModuleCommandSchema = zod_1.z.union([ zod_1.z.object({ module: zod_1.z.literal('steeringWheel'), action: zod_1.z.literal('turnLedOn') }), zod_1.z.object({ module: zod_1.z.literal('steeringWheel'), action: zod_1.z.literal('turnLedOff') }), ]); // --- All Commands Union --- exports.allCommandsConfigSchema = zod_1.z.union([ exports.ballSensorDiskThrowerModuleCommandSchema, exports.diskSensorBallShooterModuleCommandSchema, exports.flagModuleCommandSchema, exports.rgbModuleCommandSchema, exports.speedModuleCommandSchema, exports.leftStarBackLaserModuleCommandSchema, exports.rightStarFrontLaserModuleCommandSchema, exports.screenModuleCommandSchema, exports.steeringWheelModuleCommandSchema, exports.soundModuleCommandSchema, ]);