UNPKG

node-insim

Version:

An InSim library for NodeJS with TypeScript support

287 lines (286 loc) 12.6 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AICInput = exports.AICLook = exports.AICGear = exports.AICIndicators = exports.AICHeadlights = exports.AICSteering = exports.AICToggleValue = exports.AIInputVal = exports.IS_AIC = void 0; var decorators_1 = require("../decorators"); var base_1 = require("./base"); var enums_1 = require("./enums"); /** * AI Control */ var IS_AIC = /** @class */ (function (_super) { __extends(IS_AIC, _super); function IS_AIC(data) { var _this = _super.call(this) || this; /** 4 + 4 * (number of inputs) */ _this.Size = 4; _this.Type = enums_1.PacketType.ISP_AIC; /** Optional - returned in any immediate response e.g. reply to {@link CS_SEND_AI_INFO} */ _this.ReqI = 0; /** Unique ID of AI player to control */ _this.PLID = 0; /** * Inputs in {@link AIInputVal} marked 'hold' must be set back to zero after some time. * This can be done either by use of the Time field or by sending a later packet with Value = 0. * * E.g. Set Time to 10 when issuing a {@link CS_CHUP} - hold shift up lever for 0.1 sec. * * E.g. Set Time to 50 when issuing a {@link CS_HORN} - sound horn for 0.5 sec. */ _this.Inputs = []; _this.inputsOffset = 4; _this.initialize(data); return _this; } IS_AIC.prototype.pack = function () { if (this.Inputs.length > IS_AIC.MAX_INPUTS) { throw new RangeError("IS_AIC - Too many inputs set (max is ".concat(IS_AIC.MAX_INPUTS)); } var inputLength = new AIInputVal().getFormatSize(); this.Size = this.inputsOffset + this.Inputs.length * inputLength; var dataBuffer = _super.prototype.pack.call(this); var objectInfoBuffer = this.Inputs.reduce(function (acc, input) { return new Uint8Array(__spreadArray(__spreadArray([], __read(acc), false), __read(input.pack()), false)); }, new Uint8Array()); return new Uint8Array(__spreadArray(__spreadArray([], __read(dataBuffer), false), __read(objectInfoBuffer), false)); }; IS_AIC.MAX_INPUTS = 20; // NOTE: Increase if CS_NUM is increased __decorate([ (0, decorators_1.byte)() ], IS_AIC.prototype, "Size", void 0); __decorate([ (0, decorators_1.byte)() ], IS_AIC.prototype, "Type", void 0); __decorate([ (0, decorators_1.byte)() ], IS_AIC.prototype, "ReqI", void 0); __decorate([ (0, decorators_1.byte)() ], IS_AIC.prototype, "PLID", void 0); return IS_AIC; }(base_1.SendablePacket)); exports.IS_AIC = IS_AIC; var AIInputVal = /** @class */ (function (_super) { __extends(AIInputVal, _super); function AIInputVal(data) { var _this = _super.call(this) || this; /** Select input value to set * * Inputs marked 'hold' must be set back to zero after some time. * This can be done either by use of the Time field or by sending a later packet with Value = 0. * * E.g. Set Time to 10 when issuing a {@link CS_CHUP} - hold shift up lever for 0.1 sec. * * E.g. Set Time to 50 when issuing a {@link CS_HORN} - sound horn for 0.5 sec. */ _this.Input = 0; /** * Time to hold (optional, hundredths of a second) * * If the Time value is set, that input will return to default after that time. * This is probably most useful for {@link CS_CHUP} / {@link CS_CHDN} / {@link CS_FLASH} / {@link CS_HORN} inputs. * If you don't use Time then you should send another packet to zero the input. */ _this.Time = 0; /** Value to set */ _this.Value = 0; _this.initialize(data); return _this; } __decorate([ (0, decorators_1.byte)() ], AIInputVal.prototype, "Input", void 0); __decorate([ (0, decorators_1.byte)() ], AIInputVal.prototype, "Time", void 0); __decorate([ (0, decorators_1.word)() ], AIInputVal.prototype, "Value", void 0); return AIInputVal; }(base_1.SendableStruct)); exports.AIInputVal = AIInputVal; var AICToggleValue; (function (AICToggleValue) { AICToggleValue[AICToggleValue["TOGGLE"] = 1] = "TOGGLE"; AICToggleValue[AICToggleValue["SWITCH_OFF"] = 2] = "SWITCH_OFF"; AICToggleValue[AICToggleValue["SWITCH_ON"] = 3] = "SWITCH_ON"; })(AICToggleValue || (exports.AICToggleValue = AICToggleValue = {})); var AICSteering; (function (AICSteering) { AICSteering[AICSteering["HARD_LEFT"] = 1] = "HARD_LEFT"; AICSteering[AICSteering["CENTRE"] = 32768] = "CENTRE"; AICSteering[AICSteering["HARD_RIGHT"] = 65535] = "HARD_RIGHT"; })(AICSteering || (exports.AICSteering = AICSteering = {})); var AICHeadlights; (function (AICHeadlights) { /** All lights off */ AICHeadlights[AICHeadlights["OFF"] = 1] = "OFF"; /** Sidelights on */ AICHeadlights[AICHeadlights["SIDE"] = 2] = "SIDE"; /** Low beam on */ AICHeadlights[AICHeadlights["LOW"] = 3] = "LOW"; /** High beam on */ AICHeadlights[AICHeadlights["HIGH"] = 4] = "HIGH"; })(AICHeadlights || (exports.AICHeadlights = AICHeadlights = {})); var AICIndicators; (function (AICIndicators) { /** All indicators off */ AICIndicators[AICIndicators["CANCEL"] = 1] = "CANCEL"; /** Left indicators on */ AICIndicators[AICIndicators["LEFT"] = 2] = "LEFT"; /** Right indicators on */ AICIndicators[AICIndicators["RIGHT"] = 3] = "RIGHT"; /** All indicators on */ AICIndicators[AICIndicators["HAZARD"] = 4] = "HAZARD"; })(AICIndicators || (exports.AICIndicators = AICIndicators = {})); var AICGear; (function (AICGear) { AICGear[AICGear["REVERSE"] = 0] = "REVERSE"; AICGear[AICGear["NEUTRAL"] = 1] = "NEUTRAL"; AICGear[AICGear["FIRST"] = 2] = "FIRST"; AICGear[AICGear["SECOND"] = 3] = "SECOND"; AICGear[AICGear["THIRD"] = 4] = "THIRD"; AICGear[AICGear["FOURTH"] = 5] = "FOURTH"; AICGear[AICGear["FIFTH"] = 6] = "FIFTH"; AICGear[AICGear["SIXTH"] = 7] = "SIXTH"; AICGear[AICGear["SEVENTH"] = 8] = "SEVENTH"; /** Use sequential shift control */ AICGear[AICGear["SEQUENTIAL"] = 255] = "SEQUENTIAL"; })(AICGear || (exports.AICGear = AICGear = {})); var AICLook; (function (AICLook) { AICLook[AICLook["NONE"] = 0] = "NONE"; /** Look left */ AICLook[AICLook["LEFT"] = 4] = "LEFT"; /** Look left more */ AICLook[AICLook["LEFT_PLUS"] = 5] = "LEFT_PLUS"; /** Look right */ AICLook[AICLook["RIGHT"] = 6] = "RIGHT"; /** Look right more */ AICLook[AICLook["RIGHT_PLUS"] = 7] = "RIGHT_PLUS"; })(AICLook || (exports.AICLook = AICLook = {})); /** * Inputs marked 'hold' must be set back to zero after some time. * This can be done either by use of the Time field or by sending a later packet with Value = 0. * * E.g. Set Time to 10 when issuing a {@link CS_CHUP} - hold shift up lever for 0.1 sec. * * E.g. Set Time to 50 when issuing a {@link CS_HORN} - sound horn for 0.5 sec. */ var AICInput; (function (AICInput) { /** Steer: 1 hard left / 32768 centre / 65535 hard right */ AICInput[AICInput["CS_MSX"] = 0] = "CS_MSX"; /** Throttle */ AICInput[AICInput["CS_THROTTLE"] = 1] = "CS_THROTTLE"; /** Brake */ AICInput[AICInput["CS_BRAKE"] = 2] = "CS_BRAKE"; /** Hold shift up lever */ AICInput[AICInput["CS_CHUP"] = 3] = "CS_CHUP"; /** Hold shift down lever */ AICInput[AICInput["CS_CHDN"] = 4] = "CS_CHDN"; /** Ignition: 1 toggle / 2 switch off / 3 switch on */ AICInput[AICInput["CS_IGNITION"] = 5] = "CS_IGNITION"; /** Extra light: 1 toggle / 2 switch off / 3 switch on */ AICInput[AICInput["CS_EXTRALIGHT"] = 6] = "CS_EXTRALIGHT"; /** Headlights: 1: off / 2: side / 3: low / 4: high */ AICInput[AICInput["CS_HEADLIGHTS"] = 7] = "CS_HEADLIGHTS"; /** Siren */ AICInput[AICInput["CS_SIREN"] = 8] = "CS_SIREN"; /** Hold horn - 1 to 5 */ AICInput[AICInput["CS_HORN"] = 9] = "CS_HORN"; /** Hold flash */ AICInput[AICInput["CS_FLASH"] = 10] = "CS_FLASH"; /** Clutch */ AICInput[AICInput["CS_CLUTCH"] = 11] = "CS_CLUTCH"; /** Handbrake */ AICInput[AICInput["CS_HANDBRAKE"] = 12] = "CS_HANDBRAKE"; /** 1: cancel / 2: left / 3: right / 4: hazard */ AICInput[AICInput["CS_INDICATORS"] = 13] = "CS_INDICATORS"; /** Gear for shifter (leave at 255 for sequential control) */ AICInput[AICInput["CS_GEAR"] = 14] = "CS_GEAR"; /** Look: 0: none / 4: left / 5: left+ / 6: right / 7: right+ */ AICInput[AICInput["CS_LOOK"] = 15] = "CS_LOOK"; /** Pit speed limiter: 1 toggle / 2 switch off / 3 switch on */ AICInput[AICInput["CS_PITSPEED"] = 16] = "CS_PITSPEED"; /** Traction control disable: 1 toggle / 2 switch off / 3 switch on */ AICInput[AICInput["CS_TCDISABLE"] = 17] = "CS_TCDISABLE"; /** Rear fog light: 1 toggle / 2 switch off / 3 switch on */ AICInput[AICInput["CS_FOGREAR"] = 18] = "CS_FOGREAR"; /** Front fog light: 1 toggle / 2 switch off / 3 switch on */ AICInput[AICInput["CS_FOGFRONT"] = 19] = "CS_FOGFRONT"; AICInput[AICInput["CS_NUM"] = 20] = "CS_NUM"; /** Send an {@link IS_AII} (AI Info) packet */ AICInput[AICInput["CS_SEND_AI_INFO"] = 240] = "CS_SEND_AI_INFO"; /** * Start or stop sending regular {@link IS_AII} packets * Time = time interval in hundredths of a second (0 : stop) */ AICInput[AICInput["CS_REPEAT_AI_INFO"] = 241] = "CS_REPEAT_AI_INFO"; /** Set help flags. * * Value can be any combination of * - {@link PIF_AUTOGEARS} * - {@link PIF_HELP_B} * - {@link PIF_AUTOCLUTCH} * * Default value for an AI driver is {@link PIF_AUTOCLUTCH} only. * If you set {@link PIF_AUTOGEARS} you don't need to set {@link PIF_AUTOCLUTCH}. */ AICInput[AICInput["CS_SET_HELP_FLAGS"] = 253] = "CS_SET_HELP_FLAGS"; /** * Reset all inputs * * Most inputs are zero / {@link CS_MSX} is 32768 / {@link CS_GEAR} is 255 */ AICInput[AICInput["CS_RESET_INPUTS"] = 254] = "CS_RESET_INPUTS"; /** * Stop control * * The AI driver will stop the car. */ AICInput[AICInput["CS_STOP_CONTROL"] = 255] = "CS_STOP_CONTROL"; })(AICInput || (exports.AICInput = AICInput = {}));