UNPKG

xcom2charpool

Version:

Library for reading, manipulating, and managing XCOM 2 character pool binary files, supporting both browser and Node.js environments.

42 lines (41 loc) 1.9 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _StructProperty_codec; Object.defineProperty(exports, "__esModule", { value: true }); exports.StructProperty = void 0; const ObjectProperty_1 = require("../ObjectProperty"); const StructPropertyValue_1 = require("./StructPropertyValue"); const BaseCodec_1 = require("../../BaseCodec"); /** * Codec for UE StructProperty values. */ class StructProperty extends BaseCodec_1.BaseCodec { constructor() { super(...arguments); this.type = 'StructProperty'; _StructProperty_codec.set(this, new ObjectProperty_1.ObjectProperty()); } read(reader, length, ctx) { const type = reader.string(); reader.padding(); return this.readSized(reader, length, ctx, (payload) => { const obj = __classPrivateFieldGet(this, _StructProperty_codec, "f").read(payload, length, ctx); return new StructPropertyValue_1.StructPropertyValue(type, obj); }); } write(writer, value, ctx) { writer.string(value.type).padding(); const startPosition = writer.position; __classPrivateFieldGet(this, _StructProperty_codec, "f").write(writer, value.value, ctx); return writer.position - startPosition; } isSupported(value) { return value instanceof StructPropertyValue_1.StructPropertyValue; } } exports.StructProperty = StructProperty; _StructProperty_codec = new WeakMap();