xcom2charpool
Version:
Library for reading, manipulating, and managing XCOM 2 character pool binary files, supporting both browser and Node.js environments.
41 lines (40 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StructProperty = void 0;
const NoneProperty_1 = require("./NoneProperty");
class StructProperty {
constructor(type, value) {
this.type = type;
this.value = value;
}
static from(reader, name, size, factory) {
let type;
// size равен нулю, если парсинг происходит внутри массива таких объектов
if (size > 0) {
type = reader.string();
reader.padding();
}
else {
type = name;
}
const des = factory(reader);
const value = des.properties();
return new this(type, value);
}
static to(target, value, packer, isArrayElement = false) {
if (!isArrayElement) {
target.string(value.type).padding();
}
// Record the start position for size calculation
const startPosition = target.position;
packer.writeProperties(value.value);
if (Object.keys(value.value).length > 0) {
NoneProperty_1.NoneProperty.to(target);
}
// Record the end position
const endPosition = target.position;
// Return the size for the size field
return endPosition - startPosition;
}
}
exports.StructProperty = StructProperty;