Added some safety for missing things if someone was on a REALLY old system version and then updated all the way

This commit is contained in:
WBHarry 2026-06-27 21:12:12 +02:00
parent 453054c0e4
commit f47ec012ea

View file

@ -155,61 +155,65 @@ export async function runMigrations() {
/* Migrate old countdown structure */ /* Migrate old countdown structure */
const countdownSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns); const countdownSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
const getCountdowns = (data, type) => { if (!countdownSettings.narrative || !countdownSettings.encounter) {
return Object.keys(data.countdowns).reduce((acc, key) => { const getCountdowns = (data, type) => {
const countdown = data.countdowns[key]; return Object.keys(data.countdowns).reduce((acc, key) => {
acc[key] = { const countdown = data.countdowns[key];
...countdown, acc[key] = {
type: type, ...countdown,
ownership: Object.keys(countdown.ownership.players).reduce((acc, key) => { type: type,
acc[key] = ownership: Object.keys(countdown.ownership.players).reduce((acc, key) => {
countdown.ownership.players[key].type === 1 ? 2 : countdown.ownership.players[key].type; acc[key] =
return acc; countdown.ownership.players[key].type === 1 ? 2 : countdown.ownership.players[key].type;
}, {}), return acc;
progress: { }, {}),
...countdown.progress, progress: {
type: countdown.progress.type.value ...countdown.progress,
} type: countdown.progress.type.value
}; }
};
return acc; return acc;
}, {}); }, {});
}; };
await countdownSettings.updateSource({ await countdownSettings.updateSource({
countdowns: { countdowns: {
...getCountdowns(countdownSettings.narrative, 'narrative'), ...getCountdowns(countdownSettings.narrative, 'narrative'),
...getCountdowns(countdownSettings.encounter, 'encounter') ...getCountdowns(countdownSettings.encounter, 'encounter')
} }
}); });
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, countdownSettings); await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, countdownSettings);
game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.Refresh,
data: { refreshType: RefreshType.Countdown }
});
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Countdown });
game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.Refresh,
data: { refreshType: RefreshType.Countdown }
});
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Countdown });
}
lastMigrationVersion = '1.2.0'; lastMigrationVersion = '1.2.0';
} }
if (foundry.utils.isNewerVersion('1.2.7', lastMigrationVersion)) { if (foundry.utils.isNewerVersion('1.2.7', lastMigrationVersion)) {
const tagTeam = game.settings.get(CONFIG.DH.id, 'TagTeamRoll'); try {
const initatorMissing = tagTeam.initiator && !game.actors.some(actor => actor.id === tagTeam.initiator); const tagTeam = game.settings.get(CONFIG.DH.id, 'TagTeamRoll');
const missingMembers = Object.keys(tagTeam.members).reduce((acc, id) => { const initatorMissing = tagTeam.initiator && !game.actors.some(actor => actor.id === tagTeam.initiator);
if (!game.actors.some(actor => actor.id === id)) { const missingMembers = Object.keys(tagTeam.members).reduce((acc, id) => {
acc[id] = _del; if (!game.actors.some(actor => actor.id === id)) {
} acc[id] = _del;
return acc; }
}, {}); return acc;
}, {});
await tagTeam.updateSource({ await tagTeam.updateSource({
initiator: initatorMissing ? null : tagTeam.initiator, initiator: initatorMissing ? null : tagTeam.initiator,
members: missingMembers members: missingMembers
}); });
await game.settings.set(CONFIG.DH.id, 'TagTeamRoll', tagTeam); await game.settings.set(CONFIG.DH.id, 'TagTeamRoll', tagTeam);
} finally {
lastMigrationVersion = '1.2.7'; lastMigrationVersion = '1.2.7';
}
} }
if (foundry.utils.isNewerVersion('1.5.5', lastMigrationVersion)) { if (foundry.utils.isNewerVersion('1.5.5', lastMigrationVersion)) {