(path: string)
| 93 | // Read, parse, migrate, and validate a world file. Throws on parse error or |
| 94 | // validation failure — the caller can catch and present the error message. |
| 95 | export function loadWorld(path: string): WorldData { |
| 96 | const text = readFile(path); |
| 97 | if (!text || text.length === 0) { |
| 98 | throw new Error('loadWorld: file is empty or missing: ' + path); |
| 99 | } |
| 100 | |
| 101 | let raw: WorldData; |
| 102 | try { |
| 103 | raw = JSON.parse(text) as WorldData; |
| 104 | } catch (e) { |
| 105 | throw new Error('loadWorld: invalid JSON in ' + path + ': ' + (e as Error).message); |
| 106 | } |
| 107 | |
| 108 | const migrated = migrateWorldData(raw); |
| 109 | const check = validateWorld(migrated); |
| 110 | if (!check.ok) { |
| 111 | throw new Error('loadWorld: ' + path + '\n' + formatValidationErrors(check.errors)); |
| 112 | } |
| 113 | |
| 114 | return migrated; |
| 115 | } |
| 116 | |
| 117 | // Spawn scene nodes for every entity in the world and apply environment |
| 118 | // settings (lighting, shadows). Terrain, water, and rivers are also spawned |
nothing calls this directly
no test coverage detected