MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / loadPrefab

Function loadPrefab

src/world/prefab.ts:71–90  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

69// Load a single prefab file from disk, validate, migrate, and return it.
70// Throws on parse or validation error.
71export function loadPrefab(path: string): PrefabData {
72 const text = readFile(path);
73 if (!text || text.length === 0) {
74 throw new Error('loadPrefab: file is empty or missing: ' + path);
75 }
76
77 let raw: PrefabData;
78 try {
79 raw = JSON.parse(text) as PrefabData;
80 } catch (e) {
81 throw new Error('loadPrefab: invalid JSON in ' + path + ': ' + (e as Error).message);
82 }
83
84 const migrated = migratePrefabData(raw);
85 const check = validatePrefab(migrated);
86 if (!check.ok) {
87 throw new Error('loadPrefab: ' + path + '\n' + formatValidationErrors(check.errors));
88 }
89 return migrated;
90}
91
92// Recursively flatten a prefab into its leaf glb placements.
93//

Callers

nothing calls this directly

Calls 4

readFileFunction · 0.90
migratePrefabDataFunction · 0.90
validatePrefabFunction · 0.90
formatValidationErrorsFunction · 0.90

Tested by

no test coverage detected