UNPKG

arx-convert

Version:

Converts various Arx Fatalis formats to JSON or YAML and back

60 lines 1.63 kB
import { ArxPolygonFlags } from './Polygon.js'; import { COORDS_THAT_ROUND_UP } from './constants.js'; export function isQuad({ flags }) { return (flags & ArxPolygonFlags.Quad) !== 0; } export function isTiled({ flags }) { return (flags & ArxPolygonFlags.Tiled) !== 0; } export function addLightIndex(polygons) { let idx = 0; return polygons.map((polygon) => { polygon.vertices[0].llfColorIdx = idx; polygon.vertices[1].llfColorIdx = idx + 1; polygon.vertices[2].llfColorIdx = idx + 2; idx = idx + 3; if (isQuad(polygon)) { polygon.vertices[3].llfColorIdx = idx; idx = idx + 1; } return polygon; }); } function doCoordsNeedToBeRoundedUp(coords) { const [a, b, c] = coords.sort((a, b) => { return a - b; }); return COORDS_THAT_ROUND_UP.some(([x, y, z]) => { return a === x && b === y && c === z; }); } export function getCellCoords([a, b, c]) { const x = (a.x + b.x + c.x) / 3; const z = (a.z + b.z + c.z) / 3; let cellX; if (doCoordsNeedToBeRoundedUp([a.x, b.x, c.x])) { cellX = Math.ceil(x / 100); } else { cellX = Math.floor(x / 100); } let cellY; if (doCoordsNeedToBeRoundedUp([a.z, b.z, c.z])) { cellY = Math.ceil(z / 100); } else { cellY = Math.floor(z / 100); } return [cellX, cellY]; } /** * inclusive: min <= n <= max */ export function isBetween(min, max, n) { if (min > max) { ; [max, min] = [min, max]; } return n >= min && n <= max; } //# sourceMappingURL=helpers.js.map