(path: string, world: WorldData)
| 19 | // On validation failure, returns the errors without touching the filesystem. |
| 20 | // On write failure (disk full, permissions), returns `{ ok: false, errors: [...] }`. |
| 21 | export function saveWorld(path: string, world: WorldData): SaveResult { |
| 22 | // Always stamp the current schema version on save so stale copies don't |
| 23 | // drift across editor sessions. |
| 24 | world.schemaVersion = WORLD_SCHEMA_VERSION; |
| 25 | |
| 26 | const check = validateWorld(world); |
| 27 | if (!check.ok) { |
| 28 | return { ok: false, errors: check.errors }; |
| 29 | } |
| 30 | |
| 31 | const json = JSON.stringify(world, null, 2); |
| 32 | const ok = writeFile(path, json); |
| 33 | if (!ok) { |
| 34 | return { ok: false, errors: ['writeFile failed for path: ' + path] }; |
| 35 | } |
| 36 | return { ok: true, errors: [] }; |
| 37 | } |
| 38 | |
| 39 | // Write a prefab file. Same semantics as `saveWorld` but for prefabs. |
| 40 | export function savePrefab(path: string, prefab: PrefabData): SaveResult { |
nothing calls this directly
no test coverage detected