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

Function loadWorld

src/world/loader.ts:95–115  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

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.
95export 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

Callers

nothing calls this directly

Calls 4

readFileFunction · 0.90
migrateWorldDataFunction · 0.90
validateWorldFunction · 0.90
formatValidationErrorsFunction · 0.90

Tested by

no test coverage detected