UNPKG

node-insim

Version:

An InSim library for NodeJS with TypeScript support

111 lines (110 loc) 4.67 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.NLP_MAX_CARS = exports.IS_NLP = void 0; var decorators_1 = require("../decorators"); var errors_1 = require("../errors"); var lfspack_1 = require("../lfspack"); var base_1 = require("./base"); var enums_1 = require("./enums"); var structs_1 = require("./structs"); /** * Node and Lap Packet - variable size * * To receive {@link IS_NLP} packets at a specified interval: * * - Set the Interval field in the {@link IS_ISI} (InSimInit) packet (10, 20, 30... 8000 ms) * - Set {@link ISF_NLP} flag in the {@link IS_ISI} packet * * If {@link ISF_NLP} flag is set, one {@link IS_NLP} packet is sent... */ var IS_NLP = /** @class */ (function (_super) { __extends(IS_NLP, _super); function IS_NLP() { var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this; /** 4 + NumP * 6 (PLUS 2 if needed to make it a multiple of 4) */ _this.Size = 4; _this.Type = enums_1.PacketType.ISP_NLP; /** 0 unless this is a reply to a {@link TINY_NLP} request */ _this.ReqI = 0; /** Number of players in race */ _this.NumP = 0; /** Node and lap of each player, 1 to {@link NLP_MAX_CARS} (NumP) */ _this.Info = []; return _this; } IS_NLP.prototype.unpack = function (buffer) { _super.prototype.unpack.call(this, buffer); var data = (0, lfspack_1.unpack)(this.getFormat(), buffer.buffer); if (!data) { throw new errors_1.InSimError('IS_MSO - Unpacked no data from buffer'); } var nodeLapLength = new structs_1.NodeLap().getFormatSize(); for (var i = 0; i < this.NumP; i++) { var start = data.length + nodeLapLength * i; var nodeLapBuffer = (0, lfspack_1.copyBuffer)(buffer.slice(start, start + nodeLapLength)); this.Info.push(new structs_1.NodeLap().unpack(nodeLapBuffer)); } return this; }; __decorate([ (0, decorators_1.byte)() ], IS_NLP.prototype, "Size", void 0); __decorate([ (0, decorators_1.byte)() ], IS_NLP.prototype, "Type", void 0); __decorate([ (0, decorators_1.byte)() ], IS_NLP.prototype, "ReqI", void 0); __decorate([ (0, decorators_1.byte)() ], IS_NLP.prototype, "NumP", void 0); return IS_NLP; }(base_1.Packet)); exports.IS_NLP = IS_NLP; exports.NLP_MAX_CARS = 40;