(path: string, prefab: PrefabData)
| 38 | |
| 39 | // Write a prefab file. Same semantics as `saveWorld` but for prefabs. |
| 40 | export function savePrefab(path: string, prefab: PrefabData): SaveResult { |
| 41 | prefab.schemaVersion = WORLD_SCHEMA_VERSION; |
| 42 | |
| 43 | const check = validatePrefab(prefab); |
| 44 | if (!check.ok) { |
| 45 | return { ok: false, errors: check.errors }; |
| 46 | } |
| 47 | |
| 48 | const json = JSON.stringify(prefab, null, 2); |
| 49 | const ok = writeFile(path, json); |
| 50 | if (!ok) { |
| 51 | return { ok: false, errors: ['writeFile failed for path: ' + path] }; |
| 52 | } |
| 53 | return { ok: true, errors: [] }; |
| 54 | } |
| 55 | |
| 56 | // Convenience: format a SaveResult's errors as a single human-readable string. |
| 57 | // The editor uses this for status bar / dialog messages. |
nothing calls this directly
no test coverage detected