This commit is contained in:
WBHarry 2025-07-20 19:54:53 +02:00
parent 28efef7951
commit 9cdfd7a27a
11 changed files with 151 additions and 69 deletions

View file

@ -506,7 +506,12 @@ export default function DHApplicationMixin(Base) {
if (doc) return doc.sheet.render({ force: true });
// TODO: REDO this
const { actionId } = target.closest('[data-action-id]').dataset;
const actionNode = target.closest('[data-action-id]');
if (!actionNode) {
return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
}
const { actionId } = actionNode.dataset;
const { actions, attack } = this.document.system;
const action = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId);
new DHActionConfig(action).render({ force: true });

View file

@ -290,6 +290,16 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
const item = await fromUuid(data.uuid);
if (item?.type === 'feature') {
if (item.system.originId) {
const origin = await foundry.utils.fromUuid(item.system.originId);
return ui.notifications.warn(
game.i18n.format('DAGGERHEART.UI.Notifications.featureAlreadyLinked', {
name: item.name,
origin: origin.name
})
);
}
await item.update({
system: {
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,

View file

@ -50,13 +50,17 @@ export default class AncestrySheet extends DHHeritageSheet {
const item = await fromUuid(data.uuid);
if (item?.type === 'feature') {
const subType = event.target.closest('.primary-feature') ? 'primary' : 'secondary';
if (item.system.subType && item.system.subType !== CONFIG.DH.ITEM.featureSubTypes[subType]) {
const error = subType === 'primary' ? 'featureNotPrimary' : 'featureNotSecondary';
ui.notifications.warn(game.i18n.localize(`DAGGERHEART.UI.Notifications.${error}`));
return;
if (item.system.originId) {
const origin = await foundry.utils.fromUuid(item.system.originId);
return ui.notifications.warn(
game.i18n.format('DAGGERHEART.UI.Notifications.featureAlreadyLinked', {
name: item.name,
origin: origin.name
})
);
}
const subType = event.target.closest('.primary-feature') ? 'primary' : 'secondary';
await item.update({
system: {
subType: subType,

View file

@ -83,16 +83,38 @@ export default class ClassSheet extends DHBaseItemSheet {
const item = await fromUuid(data.uuid);
const target = event.target.closest('fieldset.drop-section');
if (item.type === 'subclass') {
if (item.system.originId) {
const origin = await foundry.utils.fromUuid(item.system.originId);
return ui.notifications.warn(
game.i18n.format('DAGGERHEART.UI.Notifications.featureAlreadyLinked', {
name: item.name,
origin: origin.name
})
);
}
await item.update({
system: {
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({
'system.subclasses': [...this.document.system.subclasses.map(x => x.uuid), item.uuid]
});
} else if (item.type === 'feature') {
if (target.classList.contains('hope-feature')) {
if (item.system.subType && item.system.subType !== CONFIG.DH.ITEM.featureSubTypes.hope) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureNotHope'));
return;
}
if (item.system.originId) {
const origin = await foundry.utils.fromUuid(item.system.originId);
return ui.notifications.warn(
game.i18n.format('DAGGERHEART.UI.Notifications.featureAlreadyLinked', {
name: item.name,
origin: origin.name
})
);
}
if (target.classList.contains('hope-feature')) {
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.hope,
@ -104,11 +126,6 @@ export default class ClassSheet extends DHBaseItemSheet {
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
});
} else if (target.classList.contains('class-feature')) {
if (item.system.subType && item.system.subType !== CONFIG.DH.ITEM.featureSubTypes.class) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureNotClass'));
return;
}
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.class,
@ -151,18 +168,20 @@ export default class ClassSheet extends DHBaseItemSheet {
}
} else if (item.type === 'miscellaneous') {
if (target.classList.contains('take-section')) {
if (this.document.system.inventory.take.length < 3)
if (this.document.system.inventory.take.length < 3) {
await this.document.update({
'system.inventory.take': [...this.document.system.inventory.take.map(x => x.uuid), item.uuid]
});
}
} else if (target.classList.contains('choice-b-section')) {
if (this.document.system.inventory.choiceB.length < 2)
if (this.document.system.inventory.choiceB.length < 2) {
await this.document.update({
'system.inventory.choiceB': [
...this.document.system.inventory.choiceB.map(x => x.uuid),
item.uuid
]
});
}
}
}
}
@ -179,7 +198,19 @@ 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);
await this.document.update({ [`system.${target}`]: prop.filter(i => i.uuid !== uuid) });
const item = await foundry.utils.fromUuid(uuid);
if (item) {
await item.update({
system: {
originItemType: null,
originId: null,
subType: null
}
});
}
await this.document.update({ [`system.${target}`]: prop.filter(i => i && i.uuid !== uuid) });
}
/**

View file

@ -62,12 +62,17 @@ export default class SubclassSheet extends DHBaseItemSheet {
const item = await fromUuid(data.uuid);
const target = event.target.closest('fieldset.drop-section');
if (item.type === 'feature') {
if (target.dataset.type === 'foundation') {
if (item.system.subType && item.system.subType !== CONFIG.DH.ITEM.featureSubTypes.foundation) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureNotFoundation'));
return;
}
if (item.system.originId) {
const origin = await foundry.utils.fromUuid(item.system.originId);
return ui.notifications.warn(
game.i18n.format('DAGGERHEART.UI.Notifications.featureAlreadyLinked', {
name: item.name,
origin: origin.name
})
);
}
if (target.dataset.type === 'foundation') {
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.foundation,
@ -79,11 +84,6 @@ export default class SubclassSheet extends DHBaseItemSheet {
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
});
} else if (target.dataset.type === 'specialization') {
if (item.system.subType && item.system.subType !== CONFIG.DH.ITEM.featureSubTypes.specialization) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureNotSpecialization'));
return;
}
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.specialization,
@ -95,11 +95,6 @@ export default class SubclassSheet extends DHBaseItemSheet {
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
});
} else if (target.dataset.type === 'mastery') {
if (item.system.subType && item.system.subType !== CONFIG.DH.ITEM.featureSubTypes.mastery) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureNotMastery'));
return;
}
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.mastery,