xcom2charpool
Version:
Library for reading, manipulating, and managing XCOM 2 character pool binary files, supporting both browser and Node.js environments.
37 lines (36 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntProperty = void 0;
const BaseCodec_1 = require("../../BaseCodec");
const CodecError_1 = require("../../Errors/CodecError");
/**
* Codec for UE IntProperty values.
*/
class IntProperty extends BaseCodec_1.BaseCodec {
constructor() {
super(...arguments);
this.type = 'IntProperty';
}
read(reader, length, ctx) {
if (length !== 4) {
throw new CodecError_1.CodecError(`IntProperty should have length 4, got ${length}`, this.fullPath(ctx));
}
return this.readSized(reader, length, ctx, (p) => p.int32());
}
write(writer, value, ctx) {
this.assertValue(value, ctx);
writer.int32(value);
}
assertValue(value, ctx) {
if (Number.isNaN(value) || !Number.isInteger(value)) {
throw new CodecError_1.CodecError('Value is not an integer', this.fullPath(ctx));
}
if (value < -0x80000000 || value > 0x7fffffff) {
throw new CodecError_1.CodecError('Value is out of range', this.fullPath(ctx));
}
}
isSupported(value) {
return typeof value === 'number';
}
}
exports.IntProperty = IntProperty;