mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-21 18:09:54 +02:00
Moved v13 countdown migration over to a migrateData
This commit is contained in:
parent
2c1f52413d
commit
c5308617e1
2 changed files with 33 additions and 38 deletions
|
|
@ -28,6 +28,39 @@ export default class DhCountdowns extends foundry.abstract.DataModel {
|
|||
for (const countdownKey of changedCountdowns)
|
||||
foundry.ui.countdowns.changedCountdownsForAnimation.add(countdownKey);
|
||||
}
|
||||
|
||||
static migrateData(source) {
|
||||
const migrateOldCountdowns = (data, type) => {
|
||||
for (const key of Object.keys(data.countdowns)) {
|
||||
const countdown = data.countdowns[key];
|
||||
source.countdowns[key] = {
|
||||
...countdown,
|
||||
type: type,
|
||||
ownership: Object.keys(countdown.ownership.players).reduce((acc, key) => {
|
||||
acc[key] =
|
||||
countdown.ownership.players[key].type === 1 ? 2 : countdown.ownership.players[key].type;
|
||||
return acc;
|
||||
}, {}),
|
||||
progress: {
|
||||
...countdown.progress,
|
||||
type: countdown.progress.type.value
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
source[type] = null;
|
||||
};
|
||||
|
||||
if (source.narrative) {
|
||||
migrateOldCountdowns(source.narrative, 'narrative');
|
||||
}
|
||||
|
||||
if (source.encounter) {
|
||||
migrateOldCountdowns(source.encounter, 'encounter');
|
||||
}
|
||||
|
||||
return super.migrateData(source);
|
||||
}
|
||||
}
|
||||
|
||||
export class DhCountdown extends foundry.abstract.DataModel {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { defaultRestOptions } from '../config/generalConfig.mjs';
|
||||
import { RefreshType, socketEvent } from './socket.mjs';
|
||||
|
||||
export async function runMigrations() {
|
||||
let lastMigrationVersion = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion);
|
||||
|
|
@ -153,43 +152,6 @@ export async function runMigrations() {
|
|||
await pack.configure({ locked: true });
|
||||
}
|
||||
|
||||
/* Migrate old countdown structure */
|
||||
const countdownSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
|
||||
const getCountdowns = (data, type) => {
|
||||
return Object.keys(data.countdowns).reduce((acc, key) => {
|
||||
const countdown = data.countdowns[key];
|
||||
acc[key] = {
|
||||
...countdown,
|
||||
type: type,
|
||||
ownership: Object.keys(countdown.ownership.players).reduce((acc, key) => {
|
||||
acc[key] =
|
||||
countdown.ownership.players[key].type === 1 ? 2 : countdown.ownership.players[key].type;
|
||||
return acc;
|
||||
}, {}),
|
||||
progress: {
|
||||
...countdown.progress,
|
||||
type: countdown.progress.type.value
|
||||
}
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
await countdownSettings.updateSource({
|
||||
countdowns: {
|
||||
...getCountdowns(countdownSettings.narrative, 'narrative'),
|
||||
...getCountdowns(countdownSettings.encounter, 'encounter')
|
||||
}
|
||||
});
|
||||
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 });
|
||||
|
||||
lastMigrationVersion = '1.2.0';
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue