mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-21 18:09:54 +02:00
Fix linking world item subclasses (#1987)
Some checks failed
Project CI / build (24.x) (push) Has been cancelled
Some checks failed
Project CI / build (24.x) (push) Has been cancelled
This commit is contained in:
parent
b884130826
commit
7a631c27a7
6 changed files with 17 additions and 10 deletions
|
|
@ -441,9 +441,8 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
|
||||
if (type === 'subclasses') {
|
||||
const classItem = this.setup.class;
|
||||
const uuid = classItem?._stats.compendiumSource ?? classItem?.uuid;
|
||||
presets.filter = {
|
||||
'system.linkedClass': { key: 'system.linkedClass', value: uuid }
|
||||
'system.linkedClass': { key: 'system.linkedClass', value: classItem?.sourceUuid }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
|
||||
const levelups = Object.values(actor.system.levelData?.levelups) ?? [];
|
||||
const uuid = item.uuid;
|
||||
const sourceUuid = item._stats.compendiumSource; // on older characters this may be missing
|
||||
const sourceUuid = item.sourceUuid; // on older characters this may be missing
|
||||
return levelups.some(data => {
|
||||
if (item.type === 'subclass') {
|
||||
const selectedSubclasses = data.selections.map(s => s.secondaryData?.subclass).filter(s => !!s);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ export default class SubclassSheet extends DHBaseItemSheet {
|
|||
const item = await fromUuid(data.uuid);
|
||||
const itemType = data.type === 'ActiveEffect' ? data.type : item.type;
|
||||
if (itemType === 'class') {
|
||||
const uuid = item._stats.compendiumSource ?? item.uuid;
|
||||
const uuid = item.sourceUuid;
|
||||
if (this.document.system.linkedClass !== uuid) {
|
||||
await this.document.update({ 'system.linkedClass': uuid });
|
||||
// Re-render all class sheets for instant feedback
|
||||
|
|
|
|||
|
|
@ -70,14 +70,14 @@ export default class DHClass extends BaseDataItem {
|
|||
}
|
||||
|
||||
async fetchSubclasses() {
|
||||
const uuids = [this.parent.uuid, this.parent._stats?.compendiumSource].filter(u => !!u);
|
||||
const subclasses = game.items.filter(x => x.type === 'subclass' && uuids.includes(x.system.linkedClass));
|
||||
const sourceUuid = this.parent.sourceUuid;
|
||||
const subclasses = game.items.filter(x => x.type === 'subclass' && x.system.linkedClass === sourceUuid);
|
||||
for (const pack of game.packs) {
|
||||
const packIds = [];
|
||||
const indexes = await pack.getIndex({ fields: ['system.linkedClass'] });
|
||||
for (const index of indexes) {
|
||||
if (index.type !== 'subclass') continue;
|
||||
if (!uuids.includes(index.system?.linkedClass)) continue;
|
||||
if (index.system?.linkedClass !== sourceUuid) continue;
|
||||
if (subclasses.find(x => x.uuid === index.uuid)) continue;
|
||||
packIds.push(index._id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,9 +70,7 @@ export default class DHSubclass extends BaseDataItem {
|
|||
return false;
|
||||
}
|
||||
|
||||
const match = [multiclass, actorClass].find(
|
||||
c => c && (c._stats.compendiumSource ?? c.uuid) === this.linkedClass
|
||||
);
|
||||
const match = [multiclass, actorClass].find(c => c && c.sourceUuid === this.linkedClass);
|
||||
if (!match) {
|
||||
const key = multiclass ? 'subclassNotInMulticlass' : 'subclassNotInClass';
|
||||
ui.notifications.warn(`DAGGERHEART.UI.Notifications.${key}`, { localize: true });
|
||||
|
|
|
|||
|
|
@ -5,6 +5,16 @@ import ActionSelectionDialog from '../applications/dialogs/actionSelectionDialog
|
|||
* @extends {foundry.documents.Item}
|
||||
*/
|
||||
export default class DHItem extends foundry.documents.Item {
|
||||
/**
|
||||
* Returns the uuid of the original item this item was derived from,
|
||||
* or its own uuid if its a compendium item or not derived from a source item.
|
||||
* @returns {string}
|
||||
*/
|
||||
get sourceUuid() {
|
||||
const isCompendium = this._id && this.pack && !this.isEmbedded;
|
||||
return isCompendium ? this.uuid : this._stats.duplicateSource ?? this._stats.compendiumSource ?? this.uuid;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
prepareEmbeddedDocuments() {
|
||||
super.prepareEmbeddedDocuments();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue