30 lines
809 B
TypeScript
Raw Normal View History

2024-01-04 15:27:02 -05:00
import { Struct } from './struct';
2025-02-21 19:06:09 -05:00
import { load } from './loader';
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-21 19:06:09 -05:00
let message = 'Error Loading ' + name;
if (e instanceof Error) {
message += ': ' + e.message;
2024-01-04 15:27:02 -05:00
}
2025-02-21 19:06:09 -05:00
throw new Error(message);
2024-01-04 15:27:02 -05:00
}
}
}