xcom2charpool
Version:
Library for reading, manipulating, and managing XCOM 2 character pool binary files, supporting both browser and Node.js environments.
49 lines (48 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CodecRegistry = void 0;
const BoolProperty_1 = require("./Properties/BoolProperty");
const IntProperty_1 = require("./Properties/Int/IntProperty");
const NameProperty_1 = require("./Properties/Name/NameProperty");
const StrProperty_1 = require("./Properties/StrProperty");
const ByteProperty_1 = require("./Properties/Byte/ByteProperty");
const StructProperty_1 = require("./Properties/Struct/StructProperty");
const ArrayProperty_1 = require("./Properties/Array/ArrayProperty");
/**
* Central registry for property codecs and array element codecs used by readers/writers.
*/
class CodecRegistry {
constructor() {
this.types = new Map();
this.arrays = new Map();
this.registerType(new BoolProperty_1.BoolProperty());
this.registerType(new IntProperty_1.IntProperty());
this.registerType(new NameProperty_1.NameProperty());
this.registerType(new StrProperty_1.StrProperty());
this.registerType(new ByteProperty_1.ByteProperty());
this.registerType(new StructProperty_1.StructProperty());
this.registerType(new ArrayProperty_1.ArrayProperty());
}
registerArray(name, codec) {
this.arrays.set(name, codec);
return this;
}
registerType(codec) {
this.types.set(codec.type, codec);
return this;
}
getArray(name) {
return this.arrays.get(name);
}
get(type, name) {
return this.types.get(type);
}
resolveByValue(value) {
for (const type of this.types.values()) {
if (type.isSupported(value)) {
return type;
}
}
}
}
exports.CodecRegistry = CodecRegistry;