Change to uuid approach

This commit is contained in:
Carlos Fernandez 2026-05-02 17:58:48 -04:00
parent 20f42e8a0d
commit a5db9371c6
8 changed files with 44 additions and 73 deletions

View file

@ -1,3 +1,4 @@
import { sortBy } from '../../../helpers/utils.mjs';
import DHBaseItemSheet from '../api/base-item.mjs';
const { TextEditor } = foundry.applications.ux;
@ -9,8 +10,7 @@ export default class ClassSheet extends DHBaseItemSheet {
position: { width: 700 },
actions: {
removeItemFromCollection: ClassSheet.#removeItemFromCollection,
removeSuggestedItem: ClassSheet.#removeSuggestedItem,
resetIdentifier: ClassSheet.#resetIdentifier
removeSuggestedItem: ClassSheet.#removeSuggestedItem
},
tagifyConfigs: [
{
@ -105,10 +105,10 @@ export default class ClassSheet extends DHBaseItemSheet {
}
/**@inheritdoc */
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
async _prepareContext(options) {
const context = await super._prepareContext(options);
context.domains = this.document.system.domains;
context.subclasses = await this.document.system.getSubclasses();
context.subclasses = await this.document.system.fetchSubclasses();
return context;
}
@ -190,12 +190,6 @@ export default class ClassSheet extends DHBaseItemSheet {
static async #removeItemFromCollection(_event, element) {
const { uuid, target } = element.dataset;
const prop = foundry.utils.getProperty(this.document.system, target);
if (target === 'subclasses') {
const subclass = await foundry.utils.fromUuid(uuid);
await subclass?.update({ 'system.linkedClass': null });
}
await this.document.update({ [`system.${target}`]: prop.filter(i => i && i.uuid !== uuid).map(x => x.uuid) });
}
@ -208,10 +202,4 @@ export default class ClassSheet extends DHBaseItemSheet {
const { target } = element.dataset;
await this.document.update({ [`system.characterGuide.${target}`]: null });
}
static async #resetIdentifier() {
const document = this.document;
const initial = document.system.schema.fields.identifier.getInitialValue(document._source);
document.update({ 'system.identifier': initial });
}
}

View file

@ -41,22 +41,27 @@ export default class SubclassSheet extends DHBaseItemSheet {
return this.document.system.features.map(x => x.item);
}
async _prepareContext(options) {
const context = await super._prepareContext(options);
if (this.document.system.linkedClass) {
context.class = (await fromUuid(this.document.system.linkedClass)) ?? {
name: 'Missing Class',
img: 'systems/daggerheart/assets/icons/documents/items/laurel-crown.svg',
missing: true
};
}
return context;
}
async _onDrop(event) {
event.stopPropagation();
const data = TextEditor.getDragEventData(event);
const item = await fromUuid(data.uuid);
const itemType = data.type === 'ActiveEffect' ? data.type : item.type;
if (itemType === 'class') {
const identifier = item.system.identifier;
if (!identifier) {
return ui.notifications.error(
game.i18n.localize('DAGGERHEART.UI.Notifications.classMissingIdentifier')
);
}
if (this.document.system.classLink.identifier !== identifier) {
const { img, name } = item;
await this.document.update({ 'system.classLink': { identifier, img, name } });
const uuid = item._stats.compendiumSource ?? item.uuid;
if (this.document.system.linkedClass !== uuid) {
await this.document.update({ 'system.linkedClass': uuid });
}
return;
}