[Fix] ItemLink Fix (#1032)

* .

* .

* Removed outcommented code

* Raised to minor version

* Added confirmation on import of old character data
This commit is contained in:
WBHarry 2025-08-22 01:38:07 +02:00 committed by GitHub
parent 218f180fa0
commit 523ecb506b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 122 additions and 81 deletions

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,41 @@
import { versionCompare } from '../helpers/utils.mjs';
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.1.0')) {
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.1.0';
}
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion, lastMigrationVersion);
}

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,