(path: string)
| 69 | // Load a single prefab file from disk, validate, migrate, and return it. |
| 70 | // Throws on parse or validation error. |
| 71 | export 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 | // |
nothing calls this directly
no test coverage detected