@battle-racing/br-common-lib
Version:
Common library for all Battle Racing Repositorios
121 lines (120 loc) • 6.77 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.powerUpCommandSchema = exports.steeringWheelModuleCommandSchema = 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 to allow ArithmeticExpression in place of number for specific fields
const withArithmeticExpression = (schema, field) => {
// This is a simplification. For strict Zod schemas derived from others,
// we often need to redefine or use omit().extend()
return schema;
};
// --- Speed Commands ---
exports.changeSpeedActionCommandOptionsSchema = hardware_1.speedChangeOptionsSchema.omit({ speed: true }).extend({
speed: utils_1.arithmeticExpressionSchema,
});
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: utils_1.arithmeticExpressionSchema.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,
}),
]);
// --- 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.powerUpCommandSchema = zod_1.z.union([
exports.ballSensorDiskThrowerModuleCommandSchema,
exports.diskSensorBallShooterModuleCommandSchema,
exports.flagModuleCommandSchema,
exports.rgbModuleCommandSchema,
exports.speedModuleCommandSchema,
exports.leftStarBackLaserModuleCommandSchema,
exports.rightStarFrontLaserModuleCommandSchema,
exports.steeringWheelModuleCommandSchema,
exports.soundModuleCommandSchema,
]);