This commit is contained in:
WBHarry 2025-08-20 22:45:31 +02:00
parent 07f9d4a9bc
commit 05cc148e91
7 changed files with 77 additions and 2 deletions

View file

@ -13,6 +13,7 @@ import { enrichedDualityRoll } from './module/enrichers/DualityRollEnricher.mjs'
import { registerCountdownHooks } from './module/data/countdowns.mjs';
import {
handlebarsRegistration,
runMigrations,
settingsRegistration,
socketRegistration
} from './module/systemRegistration/_module.mjs';
@ -168,6 +169,8 @@ Hooks.on('ready', async () => {
game.user.setFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.welcomeMessage, true);
}
}
runMigrations();
});
Hooks.once('dicesoniceready', () => {});

View file

@ -26,5 +26,6 @@ export const gameSettings = {
Fear: 'ResourcesFear'
},
LevelTiers: 'LevelTiers',
Countdowns: 'Countdowns'
Countdowns: 'Countdowns',
LastMigrationVersion: 'LastMigrationVersion'
};

View file

@ -12,6 +12,20 @@ export default class DHFeature extends BaseDataItem {
});
}
// /** @inheritDoc */
// _initializeSource(data, options={}) {
// const { originItemType, isMulticlass } = data;
// const base = (originItemType && this.parent?.parent?.type === 'character') ? this.parent.parent.items._source.find(x => x.type === originItemType && Boolean(isMulticlass) === x.system.isMulticlass) : null;
// if(base) {
// const feature = base.system.features.find(x => x.item && x.item === this.parent.uuid);
// if(feature && data.identifier !== 'multiclass') {
// data.identifier = feature.type;
// }
// }
// return super._initializeSource(data, options);
// }
/* -------------------------------------------- */
/**@override */

View file

@ -1,3 +1,4 @@
export { preloadHandlebarsTemplates as handlebarsRegistration } from './handlebars.mjs';
export * as settingsRegistration from './settings.mjs';
export * as socketRegistration from './socket.mjs';
export { runMigrations } from './migrations.mjs';

View file

@ -0,0 +1,50 @@
export async function runMigrations() {
let lastMigrationVersion = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion);
if (!lastMigrationVersion) lastMigrationVersion = '1.0.6';
if (versionCompare(lastMigrationVersion, '1.0.7')) {
const compendiumActors = [];
for (let pack of game.packs) {
const documents = await pack.getDocuments();
compendiumActors.push(...documents.filter(x => x.type === 'character'));
}
[...compendiumActors, ...game.actors].forEach(actor => {
const items = actor.items.reduce((acc, item) => {
if (item.type === 'feature') {
const { originItemType, isMulticlass, identifier } = item.system;
const base = originItemType
? actor.items.find(
x => x.type === originItemType && Boolean(isMulticlass) === Boolean(x.system.isMulticlass)
)
: null;
if (base) {
const feature = base.system.features.find(x => x.item && x.item.uuid === item.uuid);
if (feature && identifier !== 'multiclass') {
acc.push({ _id: item.id, system: { identifier: feature.type } });
}
}
}
return acc;
}, []);
actor.updateEmbeddedDocuments('Item', items);
});
lastMigrationVersion = '1.0.7';
}
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;
};

View file

@ -91,6 +91,12 @@ const registerMenus = () => {
};
const registerNonConfigSettings = () => {
game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion, {
scope: 'world',
config: false,
type: String
});
game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers, {
scope: 'world',
config: false,

View file

@ -2,7 +2,7 @@
"id": "daggerheart",
"title": "Daggerheart",
"description": "An unofficial implementation of the Daggerheart system",
"version": "1.0.6",
"version": "1.0.7",
"compatibility": {
"minimum": "13",
"verified": "13.347",