UNPKG

node-insim

Version:

An InSim library for NodeJS with TypeScript support

150 lines (149 loc) 6.38 kB
import { __decorate } from "tslib"; import { byte } from '../decorators'; import { copyBuffer } from '../lfspack'; import { SendablePacket } from './base'; import { PacketType } from './enums'; import { ObjectInfo } from './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. */ export class IS_AXM extends SendablePacket { constructor(data) { super(); /** 8 + NumO * 8 */ this.Size = 8; this.Type = 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); } unpack(buffer) { super.unpack(buffer); const objectInfoLength = new ObjectInfo().getFormatSize(); for (let i = 0; i < this.NumO; i++) { const start = this.objectInfoOffset + objectInfoLength * i; const objectInfoBuffer = copyBuffer(buffer.slice(start, start + objectInfoLength)); this.Info.push(new ObjectInfo().unpack(objectInfoBuffer)); } return this; } pack() { if (this.Info.length > IS_AXM.MAX_OBJECTS) { throw new RangeError(`IS_AXM - Too many objects set (max is ${IS_AXM.MAX_OBJECTS}`); } const objectInfoLength = new ObjectInfo().getFormatSize(); this.Size = this.objectInfoOffset + this.Info.length * objectInfoLength; const dataBuffer = super.pack(); const objectInfoBuffer = this.Info.reduce((acc, objectInfo) => new Uint8Array([...acc, ...objectInfo.pack()]), new Uint8Array()); return new Uint8Array([...dataBuffer, ...objectInfoBuffer]); } } IS_AXM.MAX_OBJECTS = 60; __decorate([ byte() ], IS_AXM.prototype, "Size", void 0); __decorate([ byte() ], IS_AXM.prototype, "Type", void 0); __decorate([ byte() ], IS_AXM.prototype, "ReqI", void 0); __decorate([ byte() ], IS_AXM.prototype, "NumO", void 0); __decorate([ byte() ], IS_AXM.prototype, "UCID", void 0); __decorate([ byte() ], IS_AXM.prototype, "PMOAction", void 0); __decorate([ byte() ], IS_AXM.prototype, "PMOFlags", void 0); __decorate([ byte() ], IS_AXM.prototype, "Sp3", void 0); export 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 || (PMOAction = {})); export 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 || (PMOFlags = {}));