Fix: Welten-Config auto-merge neuer Default-Chips — Läufigkeit erscheint automatisch (SW by-v918)
This commit is contained in:
parent
85864d8ef2
commit
3a3002aff3
5 changed files with 25 additions and 11 deletions
|
|
@ -569,24 +569,38 @@ window.Worlds = (() => {
|
|||
// _cfgCache: wird beim Init aus DB geladen, Fallback localStorage → Default
|
||||
let _cfgCache = null;
|
||||
|
||||
function _mergeDefaults(cfg) {
|
||||
// Neue Default-Chips die noch nicht in der gespeicherten Config sind → anhängen
|
||||
const result = JSON.parse(JSON.stringify(cfg));
|
||||
for (const world of ['jetzt', 'hund', 'welt']) {
|
||||
const def = _DEFAULT_CONFIG[world] || [];
|
||||
const saved = result[world] || [];
|
||||
for (const page of def) {
|
||||
if (!saved.includes(page)) saved.push(page);
|
||||
}
|
||||
result[world] = saved;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
async function _loadConfigFromServer() {
|
||||
try {
|
||||
const res = await API.get('/profile/world-config');
|
||||
if (res?.config) {
|
||||
_cfgCache = res.config;
|
||||
_cfgCache = _mergeDefaults(res.config);
|
||||
try { localStorage.setItem('world_chips', JSON.stringify(_cfgCache)); } catch {}
|
||||
return;
|
||||
}
|
||||
// Noch nichts in DB: lokale Config hochladen (einmalige Migration)
|
||||
const local = (() => { try { return JSON.parse(localStorage.getItem('world_chips') || 'null'); } catch { return null; } })();
|
||||
if (local) {
|
||||
_cfgCache = local;
|
||||
API.put('/profile/world-config', { config: local }).catch(() => {});
|
||||
_cfgCache = _mergeDefaults(local);
|
||||
API.put('/profile/world-config', { config: _cfgCache }).catch(() => {});
|
||||
return;
|
||||
}
|
||||
} catch {}
|
||||
// Fallback: localStorage → Default
|
||||
try { _cfgCache = JSON.parse(localStorage.getItem('world_chips') || 'null') || _DEFAULT_CONFIG; }
|
||||
try { _cfgCache = _mergeDefaults(JSON.parse(localStorage.getItem('world_chips') || 'null') || _DEFAULT_CONFIG); }
|
||||
catch { _cfgCache = _DEFAULT_CONFIG; }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue