node-insim
Version:
An InSim library for NodeJS with TypeScript support
77 lines (76 loc) • 2.8 kB
JavaScript
import { __decorate } from "tslib";
import { byte } from '../decorators';
import { SendablePacket } from './base';
import { PacketType } from './enums';
import { IS_BTN } from './IS_BTN';
/**
* Button FunctioN - delete buttons / receive button requests
*
* NOTE: {@link BFN_REQUEST} allows the user to bring up buttons with SHIFT+B or SHIFT+I
*
* - SHIFT+I clears all host buttons if any - or sends a {@link BFN_REQUEST} to host instances
* - SHIFT+B is the same but for local buttons and local instances
*/
export class IS_BFN extends SendablePacket {
constructor(data) {
super();
this.Size = 8;
this.Type = PacketType.ISP_BFN;
this.ReqI = 0;
/** Subtype */
this.SubT = 0;
/** Connection to send to or received from (0 = local / 255 = all) */
this.UCID = 0;
/** If SubT is {@link BFN_DEL_BTN}: ID of single button to delete or first button in range */
this.ClickID = 0;
/** If SubT is {@link BFN_DEL_BTN}: ID of last button in range (if greater than ClickID) */
this.ClickMax = 0;
/** Used internally by InSim */
this.Inst = 0;
this.initialize(data);
}
pack() {
if (this.ClickID > IS_BTN.MAX_CLICK_ID) {
throw new RangeError(`IS_BFN - Invalid ClickID: ${this.ClickID} - must be less than or equal to ${IS_BTN.MAX_CLICK_ID}`);
}
if (this.ClickMax > IS_BTN.MAX_CLICK_ID) {
throw new RangeError(`IS_BFN - Invalid ClickMax: ${this.ClickMax} - must be less than or equal to ${IS_BTN.MAX_CLICK_ID}`);
}
return super.pack();
}
}
__decorate([
byte()
], IS_BFN.prototype, "Size", void 0);
__decorate([
byte()
], IS_BFN.prototype, "Type", void 0);
__decorate([
byte()
], IS_BFN.prototype, "ReqI", void 0);
__decorate([
byte()
], IS_BFN.prototype, "SubT", void 0);
__decorate([
byte()
], IS_BFN.prototype, "UCID", void 0);
__decorate([
byte()
], IS_BFN.prototype, "ClickID", void 0);
__decorate([
byte()
], IS_BFN.prototype, "ClickMax", void 0);
__decorate([
byte()
], IS_BFN.prototype, "Inst", void 0);
export var ButtonFunction;
(function (ButtonFunction) {
/** Instruction: delete one button or range of buttons (must set ClickID) */
ButtonFunction[ButtonFunction["BFN_DEL_BTN"] = 0] = "BFN_DEL_BTN";
/** Instruction: clear all buttons made by this insim instance */
ButtonFunction[ButtonFunction["BFN_CLEAR"] = 1] = "BFN_CLEAR";
/** Info: user cleared this insim instance's buttons */
ButtonFunction[ButtonFunction["BFN_USER_CLEAR"] = 2] = "BFN_USER_CLEAR";
/** User request: SHIFT+B or SHIFT+I - request for buttons */
ButtonFunction[ButtonFunction["BFN_REQUEST"] = 3] = "BFN_REQUEST";
})(ButtonFunction || (ButtonFunction = {}));