TheBrokenRail 3db1515ecf
All checks were successful
CI / Build (push) Successful in 15s
Improve Error Message
2025-02-25 04:42:42 -05:00

27 lines
741 B
TypeScript

import { Struct } from './struct';
import { load } from './loader';
import { extendErrorMessage } from './common';
// Store Loaded Structures
const structures: Record<string, Struct> = {};
// Get Or Load Structure
export function getStructure(name: string) {
if (structures[name]) {
// Already Loaded
return structures[name];
} else {
// Load Structure
try {
// Create Structure
const target = new Struct(name);
structures[name] = target;
// Parse File
load(target, name, false);
// Return
return target;
} catch (e) {
throw new Error(extendErrorMessage(e, 'Loading ' + name));
}
}
}