264 - Action Feature Swap (#265)

* Removed action fields on Adversary/Environment in favor of using Feature Items

* Added drag/drop for features onto adversary/environment settings

* Added Drag of features from Adversary/Environment settings to anywhere in Foundry

* Updated all item types except Class/Subclass

* Added for Class/Subclass

* Items now copy over their features to Character

* Corrected back to actions for right items

* Fixed adversary/environment features display

* PR Fixes
This commit is contained in:
WBHarry 2025-07-05 22:35:05 +02:00 committed by GitHub
parent eac58c1386
commit e9ad9c539a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
58 changed files with 1146 additions and 1114 deletions

View file

@ -1,7 +1,3 @@
import DHActionConfig from './action-config.mjs';
import DHBaseItemSheet from '../sheets/api/base-item.mjs';
import { actionsTypes } from '../../data/action/_module.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class DHAdversarySettings extends HandlebarsApplicationMixin(ApplicationV2) {
@ -9,6 +5,7 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
super({});
this.actor = actor;
this._dragDrop = this._createDragDropHandlers();
}
get title() {
@ -26,15 +23,19 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
actions: {
addExperience: this.#addExperience,
removeExperience: this.#removeExperience,
addAction: this.#addAction,
editAction: this.#editAction,
removeAction: this.#removeAction
addFeature: this.#addFeature,
editFeature: this.#editFeature,
removeFeature: this.#removeFeature
},
form: {
handler: this.updateForm,
submitOnChange: true,
closeOnSubmit: false
}
},
dragDrop: [
{ dragSelector: null, dropSelector: '.tab.features' },
{ dragSelector: '.feature-item', dropSelector: null }
]
};
static PARTS = {
@ -55,9 +56,9 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
id: 'experiences',
template: 'systems/daggerheart/templates/sheets-settings/adversary-settings/experiences.hbs'
},
actions: {
id: 'actions',
template: 'systems/daggerheart/templates/sheets-settings/adversary-settings/actions.hbs'
features: {
id: 'features',
template: 'systems/daggerheart/templates/sheets-settings/adversary-settings/features.hbs'
}
};
@ -86,13 +87,13 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
icon: null,
label: 'DAGGERHEART.General.tabs.experiences'
},
actions: {
features: {
active: false,
cssClass: '',
group: 'primary',
id: 'actions',
id: 'features',
icon: null,
label: 'DAGGERHEART.General.tabs.actions'
label: 'DAGGERHEART.General.tabs.features'
}
};
@ -107,6 +108,22 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
return context;
}
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
this._dragDrop.forEach(d => d.bind(htmlElement));
}
_createDragDropHandlers() {
return this.options.dragDrop.map(d => {
d.callbacks = {
dragstart: this._onDragStart.bind(this),
drop: this._onDrop.bind(this)
};
return new foundry.applications.ux.DragDrop.implementation(d);
});
}
_getTabs(tabs) {
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
@ -130,46 +147,25 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
this.render();
}
static async #addAction(_event, _button) {
const actionType = await DHBaseItemSheet.selectActionType();
if (!actionType) return;
try {
const cls = actionsTypes[actionType] ?? actionsTypes.attack,
action = new cls(
{
_id: foundry.utils.randomID(),
type: actionType,
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
...cls.getSourceConfig(this.actor)
},
{
parent: this.actor
}
);
await this.actor.update({ 'system.actions': [...this.actor.system.actions, action] });
await new DHActionConfig(this.actor.system.actions[this.actor.system.actions.length - 1]).render({
force: true
});
this.render();
} catch (error) {
console.log(error);
}
static async #addFeature(_, _button) {
await this.actor.createEmbeddedDocuments('Item', [
{
type: 'feature',
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') }),
img: 'icons/skills/melee/weapons-crossed-swords-black.webp'
}
]);
this.render();
}
static async #editAction(event, target) {
static async #editFeature(event, target) {
event.stopPropagation();
const actionIndex = target.dataset.index;
await new DHActionConfig(this.actor.system.actions[actionIndex]).render({
force: true
});
this.actor.items.get(target.id).sheet.render(true);
}
static async #removeAction(event, target) {
static async #removeFeature(event, target) {
event.stopPropagation();
const actionIndex = target.dataset.index;
await this.actor.update({
'system.actions': this.actor.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex))
});
await this.actor.deleteEmbeddedDocuments('Item', [target.id]);
this.render();
}
@ -177,4 +173,26 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
await this.actor.update(formData.object);
this.render();
}
async _onDragStart(event) {
const featureItem = event.currentTarget.closest('.feature-item');
if (featureItem) {
const feature = this.actor.items.get(featureItem.id);
const featureData = { type: 'Item', uuid: feature.uuid, fromInternal: true };
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
}
}
async _onDrop(event) {
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
if (data.fromInternal) return;
const item = await fromUuid(data.uuid);
if (item.type === 'feature') {
await this.actor.createEmbeddedDocuments('Item', [item]);
this.render();
}
}
}