arx-convert
Version:
Converts various Arx Fatalis formats to JSON or YAML and back
40 lines • 1.59 kB
JavaScript
import { BinaryIO } from '../common/BinaryIO.js';
import { repeat } from '../common/helpers.js';
import { VERSION } from './constants.js';
export class FtsHeader {
static readFrom(binary) {
const path = binary.readString(256);
const data = {
levelIdx: FtsHeader.pathToLevelIdx(path),
numberOfUniqueHeaders: binary.readInt32(),
};
binary.readFloat32(); // version - always 0.14100000262260437
binary.readInt32(); // uncompressed size in bytes
binary.readUint32Array(3); // pad - ?
return data;
}
static accumulateFrom(json, uncompressedSize) {
const buffer = new ArrayBuffer(FtsHeader.sizeOf());
const binary = new BinaryIO(buffer);
binary.writeString(FtsHeader.levelIdxToPath(json.header.levelIdx), 256);
binary.writeInt32(json.uniqueHeaders.length);
binary.writeFloat32(VERSION);
binary.writeInt32(uncompressedSize);
binary.writeUint32Array(repeat(0, 3)); // pad
return buffer;
}
static pathToLevelIdx(path) {
return Number.parseInt(path.toLowerCase().replace('c:\\arx\\game\\graph\\levels\\level', '').replace('\\', ''), 10);
}
static levelIdxToPath(levelIdx) {
return `C:\\ARX\\Game\\Graph\\Levels\\level${levelIdx}\\`;
}
static sizeOf() {
return (BinaryIO.sizeOfString(256) +
BinaryIO.sizeOfInt32() +
BinaryIO.sizeOfFloat32() +
BinaryIO.sizeOfInt32() +
BinaryIO.sizeOfUint32Array(3));
}
}
//# sourceMappingURL=FtsHeader.js.map