UNPKG

arx-convert

Version:

Converts various Arx Fatalis formats to JSON or YAML and back

45 lines 2.26 kB
import { BinaryIO } from '../common/BinaryIO.js'; import { MAP_DEPTH_IN_CELLS, MAP_WIDTH_IN_CELLS } from '../common/constants.js'; import { maxAll, uniq } from '../common/helpers.js'; import { FTS_VERSION } from './constants.js'; export class SceneHeader { static readFrom(binary) { binary.readFloat32(); // version - always FTS_VERSION binary.readInt32(); // sizeX - always MAP_WIDTH_IN_CELLS binary.readInt32(); // sizeZ - always MAP_DEPTH_IN_CELLS const numberOfTextures = binary.readInt32(); binary.readInt32(); // number of polygons - we calculate that by summing cell.numberOfPolygon values const numberOfAnchors = binary.readInt32(); binary.readVector3(); // player position - overwritten by dlf.header.player.position + fts.sceneHeader.mScenePosition since Arx Fatalis >= 1.21 return { numberOfTextures, numberOfAnchors, mScenePosition: binary.readVector3(), numberOfPortals: binary.readInt32(), numberOfRooms: binary.readInt32() + 1, // rooms are 1 indexed, because an empty room is reserved for room #0 }; } static accumulateFrom(json) { const roomIds = json.polygons.map(({ room }) => { return room; }); const numberOfRooms = maxAll(uniq(roomIds)); const buffer = new ArrayBuffer(SceneHeader.sizeOf()); const binary = new BinaryIO(buffer); binary.writeFloat32(FTS_VERSION); binary.writeInt32(MAP_WIDTH_IN_CELLS); binary.writeInt32(MAP_DEPTH_IN_CELLS); binary.writeInt32(json.textureContainers.length); binary.writeInt32(json.polygons.length); binary.writeInt32(json.anchors.length); binary.writeVector3({ x: 0, y: 0, z: 0 }); // player position (should be dlf.header.player.position + fts.sceneHeader.mScenePosition for Arx Fatalis < 1.21) binary.writeVector3(json.header.mScenePosition); binary.writeInt32(json.portals.length); binary.writeInt32(numberOfRooms); return buffer; } static sizeOf() { return BinaryIO.sizeOfFloat32() + BinaryIO.sizeOfInt32Array(5 + 2) + BinaryIO.sizeOfVector3Array(2); } } //# sourceMappingURL=SceneHeader.js.map