mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Added confirmation on import of old character data
This commit is contained in:
parent
bcb678d059
commit
f8d1c9d5ba
4 changed files with 46 additions and 24 deletions
|
|
@ -193,7 +193,9 @@
|
||||||
"companionLevelup": {
|
"companionLevelup": {
|
||||||
"confirmTitle": "Companion Levelup",
|
"confirmTitle": "Companion Levelup",
|
||||||
"confirmText": "Would you like to level up your companion {name} by {levelChange} levels at this time? (You can do it manually later)"
|
"confirmText": "Would you like to level up your companion {name} by {levelChange} levels at this time? (You can do it manually later)"
|
||||||
}
|
},
|
||||||
|
"InvalidOldCharacterImportTitle": "Old Character Import",
|
||||||
|
"InvalidOldCharacterImportText": "Character data exported prior to system version 1.1 will not generate a complete character. Do you wish to continue?"
|
||||||
},
|
},
|
||||||
"Companion": {
|
"Companion": {
|
||||||
"FIELDS": {
|
"FIELDS": {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { emitAsGM, GMUpdateEvent } from '../systemRegistration/socket.mjs';
|
import { emitAsGM, GMUpdateEvent } from '../systemRegistration/socket.mjs';
|
||||||
import { LevelOptionType } from '../data/levelTier.mjs';
|
import { LevelOptionType } from '../data/levelTier.mjs';
|
||||||
import DHFeature from '../data/item/feature.mjs';
|
import DHFeature from '../data/item/feature.mjs';
|
||||||
import { damageKeyToNumber } from '../helpers/utils.mjs';
|
import { damageKeyToNumber, versionCompare } from '../helpers/utils.mjs';
|
||||||
import DhCompanionLevelUp from '../applications/levelup/companionLevelup.mjs';
|
import DhCompanionLevelUp from '../applications/levelup/companionLevelup.mjs';
|
||||||
|
|
||||||
export default class DhpActor extends Actor {
|
export default class DhpActor extends Actor {
|
||||||
|
|
@ -27,7 +27,7 @@ export default class DhpActor extends Actor {
|
||||||
|
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
static migrateData(source) {
|
static migrateData(source) {
|
||||||
if(source.system?.attack && !source.system.attack.type) source.system.attack.type = "attack";
|
if (source.system?.attack && !source.system.attack.type) source.system.attack.type = 'attack';
|
||||||
return super.migrateData(source);
|
return super.migrateData(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -573,17 +573,13 @@ export default class DhpActor extends Actor {
|
||||||
updates.find(u => u.key === 'hitPoints').value = modifiedDamage;
|
updates.find(u => u.key === 'hitPoints').value = modifiedDamage;
|
||||||
if (armorSpent) {
|
if (armorSpent) {
|
||||||
const armorUpdate = updates.find(u => u.key === 'armor');
|
const armorUpdate = updates.find(u => u.key === 'armor');
|
||||||
if(armorUpdate)
|
if (armorUpdate) armorUpdate.value += armorSpent;
|
||||||
armorUpdate.value += armorSpent;
|
else updates.push({ value: armorSpent, key: 'armor' });
|
||||||
else
|
|
||||||
updates.push({ value: armorSpent, key: 'armor' });
|
|
||||||
}
|
}
|
||||||
if (stressSpent) {
|
if (stressSpent) {
|
||||||
const stressUpdate = updates.find(u => u.key === 'stress');
|
const stressUpdate = updates.find(u => u.key === 'stress');
|
||||||
if(stressUpdate)
|
if (stressUpdate) stressUpdate.value += stressSpent;
|
||||||
stressUpdate.value += stressSpent;
|
else updates.push({ value: stressSpent, key: 'stress' });
|
||||||
else
|
|
||||||
updates.push({ value: stressSpent, key: 'stress' });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -753,4 +749,26 @@ export default class DhpActor extends Actor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @inheritdoc */
|
||||||
|
async importFromJSON(json) {
|
||||||
|
if (!this.type === 'character') return await super.importFromJSON(json);
|
||||||
|
|
||||||
|
if (!CONST.WORLD_DOCUMENT_TYPES.includes(this.documentName)) {
|
||||||
|
throw new Error('Only world Documents may be imported');
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedJSON = JSON.parse(json);
|
||||||
|
if (versionCompare(parsedJSON._stats.systemVersion, '1.1.0')) {
|
||||||
|
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||||
|
window: {
|
||||||
|
title: game.i18n.localize('DAGGERHEART.ACTORS.Character.InvalidOldCharacterImportTitle')
|
||||||
|
},
|
||||||
|
content: game.i18n.localize('DAGGERHEART.ACTORS.Character.InvalidOldCharacterImportText')
|
||||||
|
});
|
||||||
|
if (!confirmed) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await super.importFromJSON(json);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -420,3 +420,14 @@ export async function createEmbeddedItemsWithEffects(actor, baseData) {
|
||||||
export const slugify = name => {
|
export const slugify = name => {
|
||||||
return name.toLowerCase().replaceAll(' ', '-').replaceAll('.', '');
|
return name.toLowerCase().replaceAll(' ', '-').replaceAll('.', '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const versionCompare = (current, target) => {
|
||||||
|
const currentSplit = current.split('.').map(x => Number.parseInt(x));
|
||||||
|
const targetSplit = target.split('.').map(x => Number.parseInt(x));
|
||||||
|
for (var i = 0; i < currentSplit.length; i++) {
|
||||||
|
if (currentSplit[i] < targetSplit[i]) return true;
|
||||||
|
if (currentSplit[i] > targetSplit[i]) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { versionCompare } from '../helpers/utils.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);
|
||||||
if (!lastMigrationVersion) lastMigrationVersion = '1.0.6';
|
if (!lastMigrationVersion) lastMigrationVersion = '1.0.6';
|
||||||
|
|
@ -37,14 +39,3 @@ export async function runMigrations() {
|
||||||
|
|
||||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion, lastMigrationVersion);
|
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion, lastMigrationVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
const versionCompare = (current, target) => {
|
|
||||||
const currentSplit = current.split('.').map(x => Number.parseInt(x));
|
|
||||||
const targetSplit = target.split('.').map(x => Number.parseInt(x));
|
|
||||||
for (var i = 0; i < currentSplit.length; i++) {
|
|
||||||
if (currentSplit[i] < targetSplit[i]) return true;
|
|
||||||
if (currentSplit[i] > targetSplit[i]) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue