Migrate old separate config/state format to collection
()
| 196 | |
| 197 | /** Migrate old separate config/state format to collection */ |
| 198 | function migrateOldFormat(): ModCollection | null { |
| 199 | try { |
| 200 | const cfgRaw = localStorage.getItem('openroom_mod_config'); |
| 201 | const stRaw = localStorage.getItem('openroom_mod_state'); |
| 202 | if (cfgRaw) { |
| 203 | const cfg = JSON.parse(cfgRaw) as ModConfig; |
| 204 | if (cfg.mod_name && !cfg.id) { |
| 205 | const migrated: ModConfig = { ...cfg, id: DEFAULT_MOD_ID }; |
| 206 | const st = stRaw ? (JSON.parse(stRaw) as ModState) : defaultState(migrated); |
| 207 | const collection: ModCollection = { |
| 208 | activeId: DEFAULT_MOD_ID, |
| 209 | items: { [DEFAULT_MOD_ID]: { config: migrated, state: st } }, |
| 210 | }; |
| 211 | localStorage.setItem(STORAGE_KEY, JSON.stringify(collection)); |
| 212 | localStorage.removeItem('openroom_mod_config'); |
| 213 | localStorage.removeItem('openroom_mod_state'); |
| 214 | return collection; |
| 215 | } |
| 216 | } |
| 217 | } catch { |
| 218 | // ignore |
| 219 | } |
| 220 | return null; |
| 221 | } |
| 222 | |
| 223 | export async function loadModCollection(): Promise<ModCollection | null> { |
| 224 | try { |
no test coverage detected