add ifl helpers

This commit is contained in:
Brian Beck 2025-11-16 15:59:30 -08:00
parent a05153303e
commit e9ccf22f54
3 changed files with 88 additions and 0 deletions

15
src/ifl.ts Normal file
View file

@ -0,0 +1,15 @@
export function parseImageFrameList(source: string) {
const lines = source
.split(/(?:\r\n|\r|\n)/g)
.map((line) => line.trim())
.filter(Boolean);
return lines.map((line) => {
const fileWithCount = line.match(/^(.+)\s(\d+)$/);
if (fileWithCount) {
const frameCount = parseInt(fileWithCount[2], 10);
return { name: fileWithCount[1], frameCount };
} else {
return { name: line, frameCount: 1 };
}
});
}

View file

@ -1,3 +1,4 @@
import { parseImageFrameList } from "./ifl";
import { getActualResourcePath, getSource } from "./manifest";
import { parseMissionScript } from "./mission";
import { parseTerrainBuffer } from "./terrain";
@ -45,6 +46,10 @@ export function interiorTextureToUrl(name: string, fallbackUrl?: string) {
return getUrlForPath(`textures/${name}.png`, fallbackUrl);
}
export function textureFrameToUrl(fileName: string) {
return getUrlForPath(`textures/skins/${fileName}`);
}
export function shapeTextureToUrl(name: string, fallbackUrl?: string) {
name = name.replace(/\.\d+$/, "");
return getUrlForPath(`textures/skins/${name}.png`, fallbackUrl);
@ -82,3 +87,10 @@ export async function loadTerrain(fileName: string) {
const terrainBuffer = await res.arrayBuffer();
return parseTerrainBuffer(terrainBuffer);
}
export async function loadImageFrameList(iflPath: string) {
const url = getUrlForPath(iflPath);
const res = await fetch(url);
const source = await res.text();
return parseImageFrameList(source);
}