mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-03-03 04:20:32 +00:00
add ifl helpers
This commit is contained in:
parent
a05153303e
commit
e9ccf22f54
3 changed files with 88 additions and 0 deletions
15
src/ifl.ts
Normal file
15
src/ifl.ts
Normal 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 };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue