2024-01-04 15:27:02 -05:00
|
|
|
import { Struct } from './struct';
|
2025-02-21 19:06:09 -05:00
|
|
|
import { load } from './loader';
|
2025-02-25 04:42:42 -05:00
|
|
|
import { extendErrorMessage } from './common';
|
2024-01-04 15:27:02 -05:00
|
|
|
|
|
|
|
// Store Loaded Structures
|
2025-02-21 19:06:09 -05:00
|
|
|
const structures: Record<string, Struct> = {};
|
2024-01-04 15:27:02 -05:00
|
|
|
|
|
|
|
// Get Or Load Structure
|
|
|
|
export function getStructure(name: string) {
|
2025-02-21 19:06:09 -05:00
|
|
|
if (structures[name]) {
|
2024-01-04 15:27:02 -05:00
|
|
|
// Already Loaded
|
2025-02-21 19:06:09 -05:00
|
|
|
return structures[name];
|
2024-01-04 15:27:02 -05:00
|
|
|
} 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) {
|
2025-02-25 04:42:42 -05:00
|
|
|
throw new Error(extendErrorMessage(e, 'Loading ' + name));
|
2024-01-04 15:27:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|