UNPKG

wise-eyes-core

Version:

Web server to monitor the status of owlcms

149 lines (148 loc) 5.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var athlete_1 = __importDefault(require("./athlete")); var clock_1 = __importDefault(require("./clock")); var Platform = /** @class */ (function () { function Platform(_a) { var name = _a.name; this.athletes = new Map(); this.breakType = null; this.centerReferee = null; this.ceremonyType = null; this.currentAthlete = null; this.currentSession = null; this.downSignal = false; this.fopState = 'INACTIVE'; this.leftReferee = null; this.liftingOrder = []; this.liftType = null; this.liftTypeKey = null; this.mode = 'WAIT'; this.rightReferee = null; this.athleteClock = new clock_1.default(); this.breakClock = new clock_1.default(); this.name = name; } Platform.getPlatform = function (name) { var platform = this.platforms.get(name); if (!platform) { platform = new Platform({ name: name, }); this.platforms.set(name, platform); } return platform; }; Platform.getPlatforms = function () { return Array.from(this.platforms.keys()); }; Platform.prototype.getAthleteClock = function () { return this.athleteClock; }; Platform.prototype.getBreakClock = function () { return this.breakClock; }; Platform.prototype.getCurrentAthlete = function () { return this.currentAthlete || null; }; Platform.prototype.getLiftingOrder = function () { var _this = this; return this.liftingOrder.map(function (startNumber) { return _this.athletes.get(startNumber); }); }; Platform.prototype.getState = function () { var _a, _b, _c, _d; return { athlete: ((_a = this.currentAthlete) === null || _a === void 0 ? void 0 : _a.getState()) || null, athleteClock: this.athleteClock.getState(), breakClock: this.breakClock.getState(), breakType: this.breakType, centerReferee: this.centerReferee, ceremonyType: this.ceremonyType, downSignal: this.downSignal, fopState: this.fopState, leftReferee: this.leftReferee, liftType: this.liftType, liftTypeKey: this.liftTypeKey, mode: this.mode, name: this.name, rightReferee: this.rightReferee, sessionDescription: ((_b = this.currentSession) === null || _b === void 0 ? void 0 : _b.description) || null, sessionInfo: ((_c = this.currentSession) === null || _c === void 0 ? void 0 : _c.info) || null, sessionName: ((_d = this.currentSession) === null || _d === void 0 ? void 0 : _d.name) || null, }; }; Platform.prototype.resetDecisions = function () { this.centerReferee = null; this.downSignal = false; this.leftReferee = null; this.rightReferee = null; }; Platform.prototype.setBreakType = function (breakType) { this.breakType = breakType; }; Platform.prototype.setCeremonyType = function (ceremonyType) { this.ceremonyType = ceremonyType; }; Platform.prototype.setFopState = function (fopState) { this.fopState = fopState; }; Platform.prototype.setLiftType = function (_a) { var key = _a.key, name = _a.name; this.liftTypeKey = (key === null || key === void 0 ? void 0 : key.toUpperCase()) || null; this.liftType = name; }; Platform.prototype.setMode = function (mode) { this.mode = mode; }; Platform.prototype.setCurrentAthlete = function (startNumber) { this.currentAthlete = this.athletes.get(startNumber) || null; }; Platform.prototype.setDecisions = function (_a) { var centerReferee = _a.centerReferee, leftReferee = _a.leftReferee, rightReferee = _a.rightReferee; this.downSignal = false; this.centerReferee = centerReferee; this.leftReferee = leftReferee; this.rightReferee = rightReferee; }; Platform.prototype.setDownSignal = function (state) { this.downSignal = state; if (state) { this.centerReferee = null; this.leftReferee = null; this.rightReferee = null; } }; Platform.prototype.setSession = function (session) { this.currentSession = session; }; Platform.prototype.updateAthlete = function (data) { var startNumber = parseInt(data.startNumber); var athlete = this.athletes.get(startNumber); if (!athlete) { athlete = new athlete_1.default(data); } else { athlete.update(data); } this.athletes.set(startNumber, athlete); return athlete; }; Platform.prototype.updateAthletes = function (athletes) { var _this = this; var realAthletes = athletes.filter(function (athlete) { return !('isSpacer' in athlete); }); this.liftingOrder = realAthletes.map(function (athleteData) { var athlete = _this.updateAthlete(athleteData); return athlete.getState().startNumber; }); }; Platform.platforms = new Map(); return Platform; }()); exports.default = Platform;