node-insim
Version:
An InSim library for NodeJS with TypeScript support
202 lines (201 loc) • 9.4 kB
JavaScript
;
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.PMOFlags = exports.PMOAction = exports.IS_AXM = void 0;
var decorators_1 = require("../decorators");
var lfspack_1 = require("../lfspack");
var base_1 = require("./base");
var enums_1 = require("./enums");
var structs_1 = require("./structs");
/**
* AutoX Multiple objects - variable size
*
* Set the {@link ISF_AXM_LOAD} flag in the {@link IS_ISI} for info about objects when
* a layout is loaded.
*
* Set the {@link ISF_AXM_EDIT} flag in the {@link IS_ISI} for info about objects
* edited by user or InSim.
*/
var IS_AXM = /** @class */ (function (_super) {
__extends(IS_AXM, _super);
function IS_AXM(data) {
var _this = _super.call(this) || this;
/** 8 + NumO * 8 */
_this.Size = 8;
_this.Type = enums_1.PacketType.ISP_AXM;
/** 0 unless this is a reply to a {@link TINY_AXM} request */
_this.ReqI = 0;
/** Number of objects in this packet */
_this.NumO = 0;
/** Unique id of the connection that sent the packet */
_this.UCID = 0;
_this.PMOAction = PMOAction.PMO_LOADING_FILE;
_this.PMOFlags = 0;
_this.Sp3 = 0;
_this.Info = [];
_this.objectInfoOffset = 8;
_this.initialize(data);
return _this;
}
IS_AXM.prototype.unpack = function (buffer) {
_super.prototype.unpack.call(this, buffer);
var objectInfoLength = new structs_1.ObjectInfo().getFormatSize();
for (var i = 0; i < this.NumO; i++) {
var start = this.objectInfoOffset + objectInfoLength * i;
var objectInfoBuffer = (0, lfspack_1.copyBuffer)(buffer.slice(start, start + objectInfoLength));
this.Info.push(new structs_1.ObjectInfo().unpack(objectInfoBuffer));
}
return this;
};
IS_AXM.prototype.pack = function () {
if (this.Info.length > IS_AXM.MAX_OBJECTS) {
throw new RangeError("IS_AXM - Too many objects set (max is ".concat(IS_AXM.MAX_OBJECTS));
}
var objectInfoLength = new structs_1.ObjectInfo().getFormatSize();
this.Size = this.objectInfoOffset + this.Info.length * objectInfoLength;
var dataBuffer = _super.prototype.pack.call(this);
var objectInfoBuffer = this.Info.reduce(function (acc, objectInfo) { return new Uint8Array(__spreadArray(__spreadArray([], __read(acc), false), __read(objectInfo.pack()), false)); }, new Uint8Array());
return new Uint8Array(__spreadArray(__spreadArray([], __read(dataBuffer), false), __read(objectInfoBuffer), false));
};
IS_AXM.MAX_OBJECTS = 60;
__decorate([
(0, decorators_1.byte)()
], IS_AXM.prototype, "Size", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_AXM.prototype, "Type", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_AXM.prototype, "ReqI", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_AXM.prototype, "NumO", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_AXM.prototype, "UCID", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_AXM.prototype, "PMOAction", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_AXM.prototype, "PMOFlags", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_AXM.prototype, "Sp3", void 0);
return IS_AXM;
}(base_1.SendablePacket));
exports.IS_AXM = IS_AXM;
var PMOAction;
(function (PMOAction) {
/** Sent by the layout loading system only */
PMOAction[PMOAction["PMO_LOADING_FILE"] = 0] = "PMO_LOADING_FILE";
/** Adding objects (from InSim or editor) */
PMOAction[PMOAction["PMO_ADD_OBJECTS"] = 1] = "PMO_ADD_OBJECTS";
/** Delete objects (from InSim or editor) */
PMOAction[PMOAction["PMO_DEL_OBJECTS"] = 2] = "PMO_DEL_OBJECTS";
/** Clear all objects (NumO must be zero) */
PMOAction[PMOAction["PMO_CLEAR_ALL"] = 3] = "PMO_CLEAR_ALL";
/** A reply to a {@link TINY_AXM} request */
PMOAction[PMOAction["PMO_TINY_AXM"] = 4] = "PMO_TINY_AXM";
/** A reply to a {@link TTC_SEL} request */
PMOAction[PMOAction["PMO_TTC_SEL"] = 5] = "PMO_TTC_SEL";
/** Set a connection's layout editor selection */
PMOAction[PMOAction["PMO_SELECTION"] = 6] = "PMO_SELECTION";
/**
* User pressed O without anything selected
*
* An {@link IS_AXM} with PMO_POSITION is sent with a single object in the packet if a user
* presses O without any object type selected. Information only - no object is added.
* The only valid values in Info are X, Y, Zbyte and Heading.
*/
PMOAction[PMOAction["PMO_POSITION"] = 7] = "PMO_POSITION";
/**
* Request Z values / reply with Z values
*
* `PMO_GET_Z` can be used to request the resulting Zbyte values for given X, Y, Zbyte
* positions listed in the {@link IS_AXM}. A similar reply (information only) will be sent
* with adjusted Zbyte values. Index and Heading are ignored and set to zero in the
* reply. Flags is set to 0x80 if Zbyte was successfully adjusted, zero if not.
* Suggested input values for Zbyte are either 240 to get the highest point at X, Y
* or you may use the approximate altitude (see layout file format).
*/
PMOAction[PMOAction["PMO_GET_Z"] = 8] = "PMO_GET_Z";
})(PMOAction || (exports.PMOAction = PMOAction = {}));
var PMOFlags;
(function (PMOFlags) {
/**
* If PMO_FILE_END is set in a {@link PMO_LOADING_FILE} packet, LFS has reached
* the end of a layout file which it is loading.
*/
PMOFlags[PMOFlags["PMO_FILE_END"] = 1] = "PMO_FILE_END";
/**
* When objects are moved or modified in the layout editor, two {@link IS_AXM} packets
* are sent. A {@link PMO_DEL_OBJECTS} followed by a {@link PMO_ADD_OBJECTS}. In this
* case the flag {@link PMO_MOVE_MODIFY} is set in the {@link PMOFlags} byte of both
* packets.
*/
PMOFlags[PMOFlags["PMO_MOVE_MODIFY"] = 2] = "PMO_MOVE_MODIFY";
/**
* If you send an {@link IS_AXM} with {@link PMOAction} of {@link PMO_SELECTION} it is
* possible for it to be either a selection of real objects (as if the user selected
* several objects while holding the CTRL key) or a clipboard selection (as if the user
* pressed CTRL+C after selecting objects). Clipboard is the default selection mode.
* A real selection can be set by using the {@link PMO_SELECTION_REAL} bit in the
* {@link PMOFlags} byte.
*/
PMOFlags[PMOFlags["PMO_SELECTION_REAL"] = 4] = "PMO_SELECTION_REAL";
/**
* If you send an {@link IS_AXM} with {@link PMOAction} of {@link PMO_ADD_OBJECTS}
* you may wish to set the UCID to one of the guest connections (for example if that
* user's action caused the objects to be added). In this case some validity checks
* are done on the guest's computer which may report "invalid position" or
* "intersecting object" and delete the objects. This can be avoided by setting the
* {@link PMO_AVOID_CHECK} bit.
*/
PMOFlags[PMOFlags["PMO_AVOID_CHECK"] = 8] = "PMO_AVOID_CHECK";
})(PMOFlags || (exports.PMOFlags = PMOFlags = {}));