| 12 | // input is from a future version — in that case we proceed anyway and hope |
| 13 | // the extra fields are ignored, since we can't forward-migrate. |
| 14 | export function migrateWorldData(raw: WorldData): WorldData { |
| 15 | const from = raw.schemaVersion | 0; |
| 16 | |
| 17 | if (from === WORLD_SCHEMA_VERSION) { |
| 18 | return raw; |
| 19 | } |
| 20 | |
| 21 | if (from > WORLD_SCHEMA_VERSION) { |
| 22 | // Future version — we may be missing fields. Warn and continue. |
| 23 | return raw; |
| 24 | } |
| 25 | |
| 26 | // from < WORLD_SCHEMA_VERSION. Apply migration steps in order. |
| 27 | // When bumping WORLD_SCHEMA_VERSION, add a step here of the form: |
| 28 | // if (raw.schemaVersion < N) { migrateWorldV(N-1, N, raw); raw.schemaVersion = N; } |
| 29 | |
| 30 | raw.schemaVersion = WORLD_SCHEMA_VERSION; |
| 31 | return raw; |
| 32 | } |
| 33 | |
| 34 | export function migratePrefabData(raw: PrefabData): PrefabData { |
| 35 | const from = raw.schemaVersion | 0; |