mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-22 02:19:54 +02:00
[Fix] V13 Migration Fixes (#2044)
* Fixed so that damageParts without an applyTo field is assumed to be hitPoints * Added the applyTo field to the basic attack for Adversaries and Companions * Tentative blindfix to issues of entities being null. Can't replicate it * Added some safety for missing things if someone was on a REALLY old system version and then updated all the way * Moved v13 countdown migration over to a migrateData * .
This commit is contained in:
parent
1ebbad4797
commit
9c58f7058e
6 changed files with 61 additions and 51 deletions
|
|
@ -451,7 +451,15 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
||||||
|
|
||||||
static migrateData(source) {
|
static migrateData(source) {
|
||||||
if (source.damage?.parts && Array.isArray(source.damage.parts)) {
|
if (source.damage?.parts && Array.isArray(source.damage.parts)) {
|
||||||
|
let hitPointsExists = source.damage.parts.some(x => x.applyTo === 'hitPoints');
|
||||||
source.damage.parts = source.damage.parts.reduce((acc, part) => {
|
source.damage.parts = source.damage.parts.reduce((acc, part) => {
|
||||||
|
if (!part.applyTo && hitPointsExists) return acc;
|
||||||
|
|
||||||
|
if (!part.applyTo) {
|
||||||
|
hitPointsExists = true;
|
||||||
|
part.applyTo = 'hitPoints';
|
||||||
|
}
|
||||||
|
|
||||||
acc[part.applyTo] = part;
|
acc[part.applyTo] = part;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ export default class DhpAdversary extends DhCreature {
|
||||||
parts: {
|
parts: {
|
||||||
hitPoints: {
|
hitPoints: {
|
||||||
type: ['physical'],
|
type: ['physical'],
|
||||||
|
applyTo: 'hitPoints',
|
||||||
value: {
|
value: {
|
||||||
multiplier: 'flat'
|
multiplier: 'flat'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@ export default class DhCharacter extends DhCreature {
|
||||||
parts: {
|
parts: {
|
||||||
hitPoints: {
|
hitPoints: {
|
||||||
type: ['physical'],
|
type: ['physical'],
|
||||||
|
applyTo: 'hitPoints',
|
||||||
value: {
|
value: {
|
||||||
custom: {
|
custom: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ export default class DhCompanion extends DhCreature {
|
||||||
parts: {
|
parts: {
|
||||||
hitPoints: {
|
hitPoints: {
|
||||||
type: ['physical'],
|
type: ['physical'],
|
||||||
|
applyTo: 'hitPoints',
|
||||||
value: {
|
value: {
|
||||||
dice: 'd6',
|
dice: 'd6',
|
||||||
multiplier: 'prof'
|
multiplier: 'prof'
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,39 @@ export default class DhCountdowns extends foundry.abstract.DataModel {
|
||||||
for (const countdownKey of changedCountdowns)
|
for (const countdownKey of changedCountdowns)
|
||||||
foundry.ui.countdowns.changedCountdownsForAnimation.add(countdownKey);
|
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 {
|
export class DhCountdown extends foundry.abstract.DataModel {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { defaultRestOptions } from '../config/generalConfig.mjs';
|
import { defaultRestOptions } from '../config/generalConfig.mjs';
|
||||||
import { RefreshType, socketEvent } from './socket.mjs';
|
|
||||||
|
|
||||||
export async function runMigrations() {
|
export async function runMigrations() {
|
||||||
let lastMigrationVersion = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion);
|
let lastMigrationVersion = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion);
|
||||||
|
|
@ -153,47 +152,11 @@ export async function runMigrations() {
|
||||||
await pack.configure({ locked: true });
|
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';
|
lastMigrationVersion = '1.2.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundry.utils.isNewerVersion('1.2.7', lastMigrationVersion)) {
|
if (foundry.utils.isNewerVersion('1.2.7', lastMigrationVersion)) {
|
||||||
|
try {
|
||||||
const tagTeam = game.settings.get(CONFIG.DH.id, 'TagTeamRoll');
|
const tagTeam = game.settings.get(CONFIG.DH.id, 'TagTeamRoll');
|
||||||
const initatorMissing = tagTeam.initiator && !game.actors.some(actor => actor.id === tagTeam.initiator);
|
const initatorMissing = tagTeam.initiator && !game.actors.some(actor => actor.id === tagTeam.initiator);
|
||||||
const missingMembers = Object.keys(tagTeam.members).reduce((acc, id) => {
|
const missingMembers = Object.keys(tagTeam.members).reduce((acc, id) => {
|
||||||
|
|
@ -208,6 +171,7 @@ export async function runMigrations() {
|
||||||
members: missingMembers
|
members: missingMembers
|
||||||
});
|
});
|
||||||
await game.settings.set(CONFIG.DH.id, 'TagTeamRoll', tagTeam);
|
await game.settings.set(CONFIG.DH.id, 'TagTeamRoll', tagTeam);
|
||||||
|
} catch { }
|
||||||
|
|
||||||
lastMigrationVersion = '1.2.7';
|
lastMigrationVersion = '1.2.7';
|
||||||
}
|
}
|
||||||
|
|
@ -303,6 +267,8 @@ export async function runMigrations() {
|
||||||
|
|
||||||
/* Migrate existing effects modifying armor, creating new Armor Effects instead */
|
/* Migrate existing effects modifying armor, creating new Armor Effects instead */
|
||||||
const migrateEffects = async entity => {
|
const migrateEffects = async entity => {
|
||||||
|
if (!entity?.effects) return;
|
||||||
|
|
||||||
for (const effect of entity.effects) {
|
for (const effect of entity.effects) {
|
||||||
if (effect.system.changes.every(x => x.key !== 'system.armorScore')) continue;
|
if (effect.system.changes.every(x => x.key !== 'system.armorScore')) continue;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue