node-insim
Version:
An InSim library for NodeJS with TypeScript support
231 lines (230 loc) • 9.28 kB
JavaScript
import { __decorate } from "tslib";
import { byte, word } from '../decorators';
import { SendablePacket, SendableStruct } from './base';
import { PacketType } from './enums';
/**
* AI Control
*/
export class IS_AIC extends SendablePacket {
constructor(data) {
super();
/** 4 + 4 * (number of inputs) */
this.Size = 8;
this.Type = 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);
}
pack() {
if (this.Inputs.length > IS_AIC.MAX_INPUTS) {
throw new RangeError(`IS_AIC - Too many inputs set (max is ${IS_AIC.MAX_INPUTS}`);
}
const inputLength = new AIInputVal().getFormatSize();
this.Size = this.inputsOffset + this.Inputs.length * inputLength;
const dataBuffer = super.pack();
const objectInfoBuffer = this.Inputs.reduce((acc, input) => new Uint8Array([...acc, ...input.pack()]), new Uint8Array());
return new Uint8Array([...dataBuffer, ...objectInfoBuffer]);
}
}
IS_AIC.MAX_INPUTS = 20; // NOTE: Increase if CS_NUM is increased
__decorate([
byte()
], IS_AIC.prototype, "Size", void 0);
__decorate([
byte()
], IS_AIC.prototype, "Type", void 0);
__decorate([
byte()
], IS_AIC.prototype, "ReqI", void 0);
__decorate([
byte()
], IS_AIC.prototype, "PLID", void 0);
export class AIInputVal extends SendableStruct {
constructor(data) {
super();
/** 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);
}
}
__decorate([
byte()
], AIInputVal.prototype, "Input", void 0);
__decorate([
byte()
], AIInputVal.prototype, "Time", void 0);
__decorate([
word()
], AIInputVal.prototype, "Value", void 0);
export var AICToggleValue;
(function (AICToggleValue) {
AICToggleValue[AICToggleValue["TOGGLE"] = 1] = "TOGGLE";
AICToggleValue[AICToggleValue["SWITCH_OFF"] = 2] = "SWITCH_OFF";
AICToggleValue[AICToggleValue["SWITCH_ON"] = 3] = "SWITCH_ON";
})(AICToggleValue || (AICToggleValue = {}));
export var AICSteering;
(function (AICSteering) {
AICSteering[AICSteering["HARD_LEFT"] = 1] = "HARD_LEFT";
AICSteering[AICSteering["CENTRE"] = 32768] = "CENTRE";
AICSteering[AICSteering["HARD_RIGHT"] = 65535] = "HARD_RIGHT";
})(AICSteering || (AICSteering = {}));
export 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 || (AICHeadlights = {}));
export 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 || (AICIndicators = {}));
export 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 || (AICGear = {}));
export 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 || (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.
*/
export 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 || (AICInput = {}));