node-insim
Version:
An InSim library for NodeJS with TypeScript support
47 lines (46 loc) • 1.46 kB
JavaScript
import { __decorate } from "tslib";
import { byte } from '../decorators';
import { copyBuffer } from '../lfspack';
import { Packet } from './base';
import { PacketType } from './enums';
import { CompCar } from './structs';
/**
* Multi Car Info - if more than {@link MCI_MAX_CARS} in race then more than one is sent
*/
export class IS_MCI extends Packet {
constructor() {
super(...arguments);
/** 4 + NumC * 28 */
this.Size = 4;
this.Type = PacketType.ISP_MCI;
/** 0 unless this is a reply to an {@link TINY_MCI} request */
this.ReqI = 0;
/** Number of valid CompCar structs in this packet */
this.NumC = 0;
/** Car info for each player, 1 to {@link MCI_MAX_CARS} (NumC) */
this.Info = [];
}
unpack(buffer) {
super.unpack(buffer);
const compCarSize = new CompCar().getFormatSize();
for (let i = 0; i < this.NumC; i++) {
const start = 4 + compCarSize * i;
const compCarBuffer = copyBuffer(buffer.slice(start, start + compCarSize));
this.Info.push(new CompCar().unpack(compCarBuffer));
}
return this;
}
}
__decorate([
byte()
], IS_MCI.prototype, "Size", void 0);
__decorate([
byte()
], IS_MCI.prototype, "Type", void 0);
__decorate([
byte()
], IS_MCI.prototype, "ReqI", void 0);
__decorate([
byte()
], IS_MCI.prototype, "NumC", void 0);
export const MCI_MAX_CARS = 16;