diff --git a/README.md b/README.md index 09efd21..28bd07f 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,7 @@ const { FTS } = require('arx-convert') import fs from 'node:fs' import path from 'node:path' import { DLF } from 'arx-convert' -import { ArxDLF } from 'arx-convert/dist/dlf/DLF' -// types are currently scattered around the project, -// but a good IDE, like vscode will find the types you're looking for with no issue +import { ArxDLF } from 'arx-convert/types' ;(async () => { // reads an unpacked dlf file into a buffer const binary = await fs.promises.readFile(path.resolve(__dirname, './level1.dlf.unpacked')) diff --git a/docs/minimum-arx-level/game/graph/levels/level1/fast.fts.json b/docs/minimum-arx-level/game/graph/levels/level1/fast.fts.json index 46d0081..9b266e8 100644 --- a/docs/minimum-arx-level/game/graph/levels/level1/fast.fts.json +++ b/docs/minimum-arx-level/game/graph/levels/level1/fast.fts.json @@ -25618,12 +25618,12 @@ { "x": 0, "y": 0, "z": 1, "u": 1, "v": 0, "llfColorIdx": 2 }, { "x": 1, "y": 0, "z": 1, "u": 1, "v": 1, "llfColorIdx": 3 } ], - "tex": 0, + "textureContainerId": 0, "norm": { "x": 0, "y": -1, "z": 0 }, "norm2": { "x": 0, "y": 1, "z": 0 }, "transval": 0, "area": 1, - "type": 524352, + "flags": 524352, "room": 1 } ], diff --git a/package.json b/package.json index f40b960..769bffc 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,20 @@ "bin": { "arx-convert": "dist/bin/convert.js" }, + "exports": { + ".": { + "default": "./dist/index.js", + "types": "./dist/index.d.ts" + }, + "./utils": { + "default": "./dist/utils.js", + "types": "./dist/utils.d.ts" + }, + "./types": { + "default": "./dist/types.js", + "types": "./dist/types.d.ts" + } + }, "scripts": { "build": "tsc", "dev": "tsc --watch", diff --git a/src/common/Color.ts b/src/common/Color.ts index acd049d..a87f5ab 100644 --- a/src/common/Color.ts +++ b/src/common/Color.ts @@ -3,12 +3,20 @@ import { BinaryIO } from './BinaryIO' type ColorMode = 'bgra' | 'rgb' | 'abgr' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsFormat.h#L29 */ +/** + * Color containing red, green, blue and alpha channels + * + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsFormat.h#L29 + */ export type ArxColor = { - r: number // between 0 and 255 - g: number // between 0 and 255 - b: number // between 0 and 255 - a: number // between 0.0 and 1.0 + /** red channel, integer between 0 and 255 */ + r: number + /** green channel, integer between 0 and 255 */ + g: number + /** blue channel, integer between 0 and 255 */ + b: number + /** alpha channel, float between 0.0 and 1.0 */ + a: number } export class Color { diff --git a/src/common/Light.ts b/src/common/Light.ts index 3b1f85d..7d4104e 100644 --- a/src/common/Light.ts +++ b/src/common/Light.ts @@ -3,7 +3,9 @@ import { ArxColor, Color } from './Color' import { repeat } from './helpers' import { ArxVector3 } from './types' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/Light.h#L80 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/Light.h#L80 + */ export enum ArxLightFlags { None = 0, SemiDynamic = 1 << 0, @@ -13,14 +15,18 @@ export enum ArxLightFlags { SpawnSmoke = 1 << 4, Off = 1 << 5, ColorLegacy = 1 << 6, - NoCasted = 1 << 7, // unused + /** unused */ + NoCasted = 1 << 7, FixFlareSize = 1 << 8, Fireplace = 1 << 9, - NoIgnit = 1 << 10, // block reacting to player casting ignite spell, but douse will still work! + /** blocks reacting to player casting ignite spell, but douse will still work! */ + NoIgnit = 1 << 10, Flare = 1 << 11, } -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L114 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L114 + */ export type ArxLight = { pos: ArxVector3 rgb: ArxColor diff --git a/src/common/constants.ts b/src/common/constants.ts index f021d0d..95f0f25 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -1,4 +1,8 @@ -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsTypes.h#L88 */ +import { TripleOf } from './types' + +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsTypes.h#L88 + */ export enum ArxPolygonFlags { None = 0, NoShadow = 1 << 0, @@ -8,7 +12,8 @@ export enum ArxPolygonFlags { Glow = 1 << 4, Ignore = 1 << 5, Quad = 1 << 6, - Tiled = 1 << 7, // unused + /** unused */ + Tiled = 1 << 7, Metal = 1 << 8, Hide = 1 << 9, Stone = 1 << 10, @@ -22,16 +27,24 @@ export enum ArxPolygonFlags { NoPath = 1 << 18, NoDraw = 1 << 19, PrecisePath = 1 << 20, - NoClimb = 1 << 21, // unused - Angular = 1 << 22, // unused - AngularIdx0 = 1 << 23, // unused - AngularIdx1 = 1 << 24, // unused - AngularIdx2 = 1 << 25, // unused - AngularIdx3 = 1 << 26, // unused + /** unused */ + NoClimb = 1 << 21, + /** unused */ + Angular = 1 << 22, + /** unused */ + AngularIdx0 = 1 << 23, + /** unused */ + AngularIdx1 = 1 << 24, + /** unused */ + AngularIdx2 = 1 << 25, + /** unused */ + AngularIdx3 = 1 << 26, LateMip = 1 << 27, } -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/ai/Paths.h#L65 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/ai/Paths.h#L65 + */ export enum ArxZoneFlags { None = 0, Ambiance = 1 << 1, @@ -79,7 +92,7 @@ export enum ArxZoneFlags { // 0.9999967447916589, // 0.9999967447916731, -export const COORDS_THAT_ROUND_UP: [number, number, number][] = [ +export const COORDS_THAT_ROUND_UP: TripleOf[] = [ [2550, 2600, 2649.999755859375], [2649.999755859375, 2700, 2749.999755859375], [3949.999755859375, 4000, 4050], diff --git a/src/common/helpers.ts b/src/common/helpers.ts index eed85ae..c8c1cf2 100644 --- a/src/common/helpers.ts +++ b/src/common/helpers.ts @@ -1,6 +1,7 @@ import { ArxPolygon } from '../fts/Polygon' import { ArxVertex } from '../fts/Vertex' import { COORDS_THAT_ROUND_UP } from './constants' +import { QuadrupleOf } from './types' export const maxAll = (arr: number[]) => { let i = arr.length @@ -17,7 +18,9 @@ export const isZeroVertex = ({ x, y, z }: { x: number; y: number; z: number }) = return Math.abs(x) < Number.EPSILON && Math.abs(y) < Number.EPSILON && Math.abs(z) < Number.EPSILON } -/** @see https://stackoverflow.com/a/14438954/1806628 */ +/** + * @see https://stackoverflow.com/a/14438954/1806628 + */ export const uniq = (values: T[]) => { return values.filter((value, index, self) => { return self.indexOf(value) === index @@ -54,7 +57,7 @@ export const addLightIndex = (polygons: ArxPolygon[]) => { }) } -export const getCellCoords = ([a, b, c]: [ArxVertex, ArxVertex, ArxVertex, ArxVertex]) => { +export const getCellCoords = ([a, b, c]: QuadrupleOf): [number, number] => { const x = (a.x + b.x + c.x) / 3 const z = (a.z + b.z + c.z) / 3 diff --git a/src/common/types.ts b/src/common/types.ts index e214493..b32884c 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -1,21 +1,31 @@ -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsFormat.h#L48 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsFormat.h#L48 + */ export type ArxVector3 = { x: number y: number z: number } -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsFormat.h#L65 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsFormat.h#L65 + */ export type ArxRotation = { a: number b: number g: number } -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L63 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L63 + */ export type ArxQuaternion = { x: number y: number z: number w: number } + +export type TripleOf = [T, T, T] + +export type QuadrupleOf = [T, T, T, T] diff --git a/src/dlf/DlfHeader.ts b/src/dlf/DlfHeader.ts index 5b25061..e3e1a53 100644 --- a/src/dlf/DlfHeader.ts +++ b/src/dlf/DlfHeader.ts @@ -5,7 +5,9 @@ import { repeat } from '../common/helpers' import { ArxRotation, ArxVector3 } from '../common/types' import { ArxDLF } from './DLF' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L58 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L58 + */ export type ArxDlfHeader = { lastUser: string time: number diff --git a/src/dlf/Fog.ts b/src/dlf/Fog.ts index 3231be6..0ebb770 100644 --- a/src/dlf/Fog.ts +++ b/src/dlf/Fog.ts @@ -4,7 +4,9 @@ import { ArxColor, Color } from '../common/Color' import { repeat } from '../common/helpers' import { ArxRotation, ArxVector3 } from '../common/types' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L132 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L132 + */ export type ArxFog = { pos: ArxVector3 rgb: ArxColor diff --git a/src/dlf/InteactiveObject.ts b/src/dlf/InteactiveObject.ts index 0982247..54d723b 100644 --- a/src/dlf/InteactiveObject.ts +++ b/src/dlf/InteactiveObject.ts @@ -3,7 +3,9 @@ import { BinaryIO } from '../common/BinaryIO' import { repeat } from '../common/helpers' import { ArxRotation, ArxVector3 } from '../common/types' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L193 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L193 + */ export type ArxInteractiveObject = { name: string pos: ArxVector3 diff --git a/src/dlf/PathHeader.ts b/src/dlf/PathHeader.ts index ccf2fcf..885a811 100644 --- a/src/dlf/PathHeader.ts +++ b/src/dlf/PathHeader.ts @@ -4,7 +4,9 @@ import { repeat } from '../common/helpers' import { ArxVector3 } from '../common/types' import { ArxPath } from './DLF' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L150 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L150 + */ export type ArxPathHeader = { name: string idx: number diff --git a/src/dlf/Pathway.ts b/src/dlf/Pathway.ts index c196bd4..4b592c6 100644 --- a/src/dlf/Pathway.ts +++ b/src/dlf/Pathway.ts @@ -3,7 +3,9 @@ import { BinaryIO } from '../common/BinaryIO' import { repeat } from '../common/helpers' import { ArxVector3 } from '../common/types' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L168 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L168 + */ export type ArxPathway = { rpos: ArxVector3 flag: number diff --git a/src/dlf/Scene.ts b/src/dlf/Scene.ts index d532bc1..94c8bea 100644 --- a/src/dlf/Scene.ts +++ b/src/dlf/Scene.ts @@ -2,7 +2,9 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' import { repeat } from '../common/helpers' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L88 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L88 + */ export type ArxScene = { levelIdx: number } diff --git a/src/fts/AnchorData.ts b/src/fts/AnchorData.ts index 4fa66c6..9a21a28 100644 --- a/src/fts/AnchorData.ts +++ b/src/fts/AnchorData.ts @@ -3,7 +3,9 @@ import { BinaryIO } from '../common/BinaryIO' import { ArxVector3 } from '../common/types' import { ArxAnchor } from './Anchor' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L117 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L117 + */ export type ArxAnchorData = { pos: ArxVector3 radius: number diff --git a/src/fts/EPData.ts b/src/fts/EPData.ts index 7d11d3d..19aead9 100644 --- a/src/fts/EPData.ts +++ b/src/fts/EPData.ts @@ -1,20 +1,25 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L161 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L161 + */ export type ArxEPData = { - px: number - py: number - idx: number + cellX: number + cellY: number + /** + * this number is a counter for polygons in the cell, it has no relation to the order of polygons globally + */ + polygonIdx: number } export class EPData { static readFrom(binary: BinaryIO): ArxEPData { const [px, py, idx] = binary.readInt16Array(4) - return { px, py, idx } + return { cellX: px, cellY: py, polygonIdx: idx } } - static accumulateFrom({ px, py, idx }: ArxEPData) { + static accumulateFrom({ cellX: px, cellY: py, polygonIdx: idx }: ArxEPData) { const buffer = Buffer.alloc(EPData.sizeOf()) const binary = new BinaryIO(buffer.buffer) diff --git a/src/fts/FtsHeader.ts b/src/fts/FtsHeader.ts index f02aff9..64a2e0f 100644 --- a/src/fts/FtsHeader.ts +++ b/src/fts/FtsHeader.ts @@ -4,7 +4,9 @@ import { FTS_VERSION } from '../common/constants' import { repeat } from '../common/helpers' import { ArxFTS } from './FTS' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L56 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L56 + */ export type ArxFtsHeader = { levelIdx: number numberOfUniqueHeaders: number diff --git a/src/fts/Polygon.ts b/src/fts/Polygon.ts index 6eded3d..e01387f 100644 --- a/src/fts/Polygon.ts +++ b/src/fts/Polygon.ts @@ -1,19 +1,26 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' import { ArxVertex, Vertex } from './Vertex' -import { ArxVector3 } from '../common/types' +import { ArxVector3, QuadrupleOf } from '../common/types' import { times } from '../common/helpers' +import { ArxPolygonFlags } from '../common/constants' +import { ArxTextureContainer } from './TextureContainer' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L81 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L81 + */ export type ArxPolygon = { - vertices: [ArxVertex, ArxVertex, ArxVertex, ArxVertex] - tex: number + vertices: QuadrupleOf + /** + * reference to {@link ArxTextureContainer.id} + */ + textureContainerId: number norm: ArxVector3 norm2: ArxVector3 - normals?: [ArxVector3, ArxVector3, ArxVector3, ArxVector3] + normals?: QuadrupleOf transval: number area: number - type: number + flags: ArxPolygonFlags room: number paddy?: number } @@ -21,14 +28,14 @@ export type ArxPolygon = { export class Polygon { static readFrom(binary: BinaryIO): ArxPolygon { return { - vertices: times(() => Vertex.readFrom(binary), 4) as [ArxVertex, ArxVertex, ArxVertex, ArxVertex], - tex: binary.readInt32(), + vertices: times(() => Vertex.readFrom(binary), 4) as QuadrupleOf, + textureContainerId: binary.readInt32(), norm: binary.readVector3(), norm2: binary.readVector3(), - normals: times(() => binary.readVector3(), 4) as [ArxVector3, ArxVector3, ArxVector3, ArxVector3], + normals: times(() => binary.readVector3(), 4) as QuadrupleOf, transval: binary.readFloat32(), area: binary.readFloat32(), - type: binary.readInt32(), + flags: binary.readInt32(), room: binary.readInt16(), paddy: binary.readInt16(), } @@ -39,13 +46,13 @@ export class Polygon { const binary = new BinaryIO(buffer.buffer) binary.writeBuffer(Buffer.concat(polygon.vertices.map(Vertex.accumulateFrom))) - binary.writeInt32(polygon.tex) + binary.writeInt32(polygon.textureContainerId) binary.writeVector3(polygon.norm) binary.writeVector3(polygon.norm2) binary.writeVector3Array(polygon.normals ?? [polygon.norm, polygon.norm, polygon.norm, polygon.norm2]) binary.writeFloat32(polygon.transval) binary.writeFloat32(polygon.area) - binary.writeInt32(polygon.type) + binary.writeInt32(polygon.flags) binary.writeInt16(polygon.room) binary.writeInt16(polygon.paddy ?? 0) diff --git a/src/fts/Portal.ts b/src/fts/Portal.ts index 72ad479..6aec789 100644 --- a/src/fts/Portal.ts +++ b/src/fts/Portal.ts @@ -2,7 +2,9 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' import { ArxPortalPolygon, PortalPolygon } from './PortalPolygon' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsTypes.h#L268 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsTypes.h#L268 + */ export type ArxPortal = { polygon: ArxPortalPolygon room1: number diff --git a/src/fts/PortalPolygon.ts b/src/fts/PortalPolygon.ts index 6e3f833..23cc1d7 100644 --- a/src/fts/PortalPolygon.ts +++ b/src/fts/PortalPolygon.ts @@ -1,19 +1,21 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' import { times } from '../common/helpers' -import { ArxVector3 } from '../common/types' +import { ArxVector3, QuadrupleOf } from '../common/types' import { ArxTextureVertex, TextureVertex } from './TextureVertex' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L136 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L136 + */ export type ArxPortalPolygon = { type: number min: ArxVector3 max: ArxVector3 norm: ArxVector3 norm2: ArxVector3 - v: [ArxTextureVertex, ArxTextureVertex, ArxTextureVertex, ArxTextureVertex] + v: QuadrupleOf unused: number[] // array holds 32*4 bytes of some data, but no idea what it is - nrml: [ArxVector3, ArxVector3, ArxVector3, ArxVector3] + nrml: QuadrupleOf tex: number center: ArxVector3 transval: number @@ -30,14 +32,9 @@ export class PortalPolygon { max: binary.readVector3(), norm: binary.readVector3(), norm2: binary.readVector3(), - v: times(() => TextureVertex.readFrom(binary), 4) as [ - ArxTextureVertex, - ArxTextureVertex, - ArxTextureVertex, - ArxTextureVertex, - ], + v: times(() => TextureVertex.readFrom(binary), 4) as QuadrupleOf, unused: binary.readUint8Array(32 * 4), - nrml: binary.readVector3Array(4) as [ArxVector3, ArxVector3, ArxVector3, ArxVector3], + nrml: binary.readVector3Array(4) as QuadrupleOf, tex: binary.readInt32(), center: binary.readVector3(), transval: binary.readFloat32(), @@ -47,24 +44,24 @@ export class PortalPolygon { } } - static accumulateFrom(polygon: ArxPortalPolygon) { + static accumulateFrom(portalPolygon: ArxPortalPolygon) { const buffer = Buffer.alloc(PortalPolygon.sizeOf()) const binary = new BinaryIO(buffer.buffer) - binary.writeInt32(polygon.type) - binary.writeVector3(polygon.min) - binary.writeVector3(polygon.max) - binary.writeVector3(polygon.norm) - binary.writeVector3(polygon.norm2) - binary.writeBuffer(Buffer.concat(polygon.v.map(TextureVertex.accumulateFrom))) - binary.writeUint8Array(polygon.unused) - binary.writeVector3Array(polygon.nrml) - binary.writeInt32(polygon.tex) - binary.writeVector3(polygon.center) - binary.writeFloat32(polygon.transval) - binary.writeFloat32(polygon.area) - binary.writeInt16(polygon.room) - binary.writeInt16(polygon.misc) + binary.writeInt32(portalPolygon.type) + binary.writeVector3(portalPolygon.min) + binary.writeVector3(portalPolygon.max) + binary.writeVector3(portalPolygon.norm) + binary.writeVector3(portalPolygon.norm2) + binary.writeBuffer(Buffer.concat(portalPolygon.v.map(TextureVertex.accumulateFrom))) + binary.writeUint8Array(portalPolygon.unused) + binary.writeVector3Array(portalPolygon.nrml) + binary.writeInt32(portalPolygon.tex) + binary.writeVector3(portalPolygon.center) + binary.writeFloat32(portalPolygon.transval) + binary.writeFloat32(portalPolygon.area) + binary.writeInt16(portalPolygon.room) + binary.writeInt16(portalPolygon.misc) return buffer } diff --git a/src/fts/RoomData.ts b/src/fts/RoomData.ts index c488773..13a0177 100644 --- a/src/fts/RoomData.ts +++ b/src/fts/RoomData.ts @@ -3,7 +3,9 @@ import { BinaryIO } from '../common/BinaryIO' import { repeat } from '../common/helpers' import { ArxRoom } from './Room' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L178 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L178 + */ export type ArxRoomData = { numberOfPortals: number numberOfPolygons: number diff --git a/src/fts/RoomDistance.ts b/src/fts/RoomDistance.ts index 3848cfa..3a59657 100644 --- a/src/fts/RoomDistance.ts +++ b/src/fts/RoomDistance.ts @@ -2,7 +2,9 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' import { ArxVector3 } from '../common/types' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L130 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L130 + */ export type ArxRoomDistance = { distance: number startPosition: ArxVector3 diff --git a/src/fts/SceneHeader.ts b/src/fts/SceneHeader.ts index 7c2c008..9efb680 100644 --- a/src/fts/SceneHeader.ts +++ b/src/fts/SceneHeader.ts @@ -5,7 +5,9 @@ import { maxAll, uniq } from '../common/helpers' import { ArxVector3 } from '../common/types' import { ArxFTS } from './FTS' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L94 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L94 + */ export type ArxSceneHeader = { numberOfTextures: number numberOfAnchors: number diff --git a/src/fts/SceneInfo.ts b/src/fts/SceneInfo.ts index 349d0d7..da61edc 100644 --- a/src/fts/SceneInfo.ts +++ b/src/fts/SceneInfo.ts @@ -2,7 +2,9 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' import { ArxCell } from './Cell' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L125 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L125 + */ export type ArxSceneInfo = { numberOfPolygons: number numberOfAnchors: number diff --git a/src/fts/TextureContainer.ts b/src/fts/TextureContainer.ts index 442e8d3..2c3cb01 100644 --- a/src/fts/TextureContainer.ts +++ b/src/fts/TextureContainer.ts @@ -1,19 +1,21 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L107 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L107 + */ export type ArxTextureContainer = { - tc: number + id: number temp: number - fic: string + filename: string } export class TextureContainer { static readFrom(binary: BinaryIO): ArxTextureContainer { return { - tc: binary.readInt32(), + id: binary.readInt32(), temp: binary.readInt32(), - fic: binary.readString(256), + filename: binary.readString(256), } } @@ -21,9 +23,9 @@ export class TextureContainer { const buffer = Buffer.alloc(TextureContainer.sizeOf()) const binary = new BinaryIO(buffer.buffer) - binary.writeInt32(textureContainer.tc) + binary.writeInt32(textureContainer.id) binary.writeInt32(textureContainer.temp) - binary.writeString(textureContainer.fic, 256) + binary.writeString(textureContainer.filename, 256) return buffer } diff --git a/src/fts/TextureVertex.ts b/src/fts/TextureVertex.ts index c1b424f..d9b4b9c 100644 --- a/src/fts/TextureVertex.ts +++ b/src/fts/TextureVertex.ts @@ -3,7 +3,9 @@ import { BinaryIO } from '../common/BinaryIO' import { ArxColor, Color } from '../common/Color' import { ArxVector3 } from '../common/types' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsFormat.h#L82 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/GraphicsFormat.h#L82 + */ export type ArxTextureVertex = { pos: ArxVector3 rhw: number diff --git a/src/fts/UniqueHeader.ts b/src/fts/UniqueHeader.ts index 5defcd3..b961adb 100644 --- a/src/fts/UniqueHeader.ts +++ b/src/fts/UniqueHeader.ts @@ -1,7 +1,9 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L68 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L68 + */ export type ArxUniqueHeader = { path: string check: number[] // 512 bytes diff --git a/src/fts/Vertex.ts b/src/fts/Vertex.ts index f10b937..b1ae78d 100644 --- a/src/fts/Vertex.ts +++ b/src/fts/Vertex.ts @@ -1,7 +1,9 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L73 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/graphics/data/FastSceneFormat.h#L73 + */ export type ArxVertex = { x: number y: number diff --git a/src/index.ts b/src/index.ts index 3506b09..3b69fbc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,5 @@ -import { DLF } from './dlf/DLF' -import { FTS } from './fts/FTS' -import { LLF } from './llf/LLF' -import { FTL } from './ftl/FTL' -import { TEA } from './tea/TEA' - -export { DLF, FTS, LLF, FTL, TEA } +export { DLF } from './dlf/DLF' +export { FTS } from './fts/FTS' +export { LLF } from './llf/LLF' +export { FTL } from './ftl/FTL' +export { TEA } from './tea/TEA' diff --git a/src/llf/LlfHeader.ts b/src/llf/LlfHeader.ts index 884c03c..ee8d54f 100644 --- a/src/llf/LlfHeader.ts +++ b/src/llf/LlfHeader.ts @@ -4,7 +4,9 @@ import { DANAE_VERSION } from '../common/constants' import { repeat } from '../common/helpers' import { ArxLLF } from './LLF' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L178 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/scene/LevelFormat.h#L178 + */ export type ArxLlfHeader = { lastUser: string time: number diff --git a/src/tea/NewKeyFrame.ts b/src/tea/NewKeyFrame.ts index fd34f4d..a12f974 100644 --- a/src/tea/NewKeyFrame.ts +++ b/src/tea/NewKeyFrame.ts @@ -4,7 +4,9 @@ import { BinaryIO } from '../common/BinaryIO' import { ArxTEA } from './TEA' import { ArxOldKeyFrame, OldKeyFrame } from './OldKeyFrame' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L102 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L102 + */ export type ArxNewKeyFrame = ArxOldKeyFrame & { info_frame: string } diff --git a/src/tea/OldKeyFrame.ts b/src/tea/OldKeyFrame.ts index ffbd42a..a4887f4 100644 --- a/src/tea/OldKeyFrame.ts +++ b/src/tea/OldKeyFrame.ts @@ -2,7 +2,9 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' import { ArxTEA } from './TEA' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L91 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L91 + */ export type ArxOldKeyFrame = { num_frame: number flag_frame: number diff --git a/src/tea/TEA.ts b/src/tea/TEA.ts index 5805585..4d21e92 100644 --- a/src/tea/TEA.ts +++ b/src/tea/TEA.ts @@ -11,7 +11,9 @@ export type ArxTEA = { keyframes: ArxKeyFrame[] } -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L124 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L124 + */ export type ArxTheaSample = { name: string size: number diff --git a/src/tea/TeaHeader.ts b/src/tea/TeaHeader.ts index 4d4f918..e821d14 100644 --- a/src/tea/TeaHeader.ts +++ b/src/tea/TeaHeader.ts @@ -3,7 +3,9 @@ import { Buffer } from 'node:buffer' import { BinaryIO } from '../common/BinaryIO' import { ArxTEA } from './TEA' -/** @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L82 */ +/** + * @see https://github.com/arx/ArxLibertatis/blob/1.2.1/src/animation/AnimationFormat.h#L82 + */ export type ArxTeaHeader = { ident: string version: number diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..170e51a --- /dev/null +++ b/src/types.ts @@ -0,0 +1,53 @@ +// ---------------- +// types +// ---------------- + +export type { ArxColor } from './common/Color' +export type { ArxLight } from './common/Light' +export type { ArxVector3, ArxRotation, ArxQuaternion } from './common/types' + +export type { ArxPath, ArxDLF } from './dlf/DLF' +export type { ArxDlfHeader } from './dlf/DlfHeader' +export type { ArxFog } from './dlf/Fog' +export type { ArxInteractiveObject } from './dlf/InteactiveObject' +export type { ArxPathHeader } from './dlf/PathHeader' +export type { ArxPathway } from './dlf/Pathway' +export type { ArxScene } from './dlf/Scene' + +// export type { ArxFTL } from './ftl/FTL' +// export type { ArxFtlHeader } from './ftl/FtlHeader' + +export type { ArxAnchor } from './fts/Anchor' +export type { ArxAnchorData } from './fts/AnchorData' +export type { ArxCell } from './fts/Cell' +export type { ArxEPData } from './fts/EPData' +export type { ArxFTS } from './fts/FTS' +export type { ArxFtsHeader } from './fts/FtsHeader' +export type { ArxPolygon } from './fts/Polygon' +export type { ArxPortal } from './fts/Portal' +export type { ArxPortalPolygon } from './fts/PortalPolygon' +export type { ArxRoom } from './fts/Room' +export type { ArxRoomData } from './fts/RoomData' +export type { ArxRoomDistance } from './fts/RoomDistance' +export type { ArxSceneHeader } from './fts/SceneHeader' +export type { ArxSceneInfo } from './fts/SceneInfo' +export type { ArxTextureContainer } from './fts/TextureContainer' +export type { ArxTextureVertex } from './fts/TextureVertex' +export type { ArxUniqueHeader } from './fts/UniqueHeader' +export type { ArxVertex } from './fts/Vertex' + +export type { ArxLLF } from './llf/LLF' +export type { ArxLightingHeader } from './llf/LightingHeader' +export type { ArxLlfHeader } from './llf/LlfHeader' + +// export type { ArxNewKeyFrame } from './tea/NewKeyFrame' +// export type { ArxOldKeyFrame } from './tea/OldKeyFrame' +// export type { ArxKeyFrame, ArxTEA, ArxTheaSample } from './tea/TEA' +// export type { ArxTeaHeader } from './tea/TeaHeader' + +// ---------------- +// enums +// ---------------- + +export { ArxPolygonFlags, ArxZoneFlags } from './common/constants' +export { ArxLightFlags } from './common/Light' diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..5343246 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,5 @@ +export { getCellCoords } from './common/helpers' + +export type { TripleOf, QuadrupleOf } from './common/types' + +export { MAP_WIDTH_IN_CELLS, MAP_DEPTH_IN_CELLS } from './common/constants'