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 DHEnvironmentSettings extends HandlebarsApplicationMixin(ApplicationV2) {
@ -25,9 +21,9 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
},
position: { width: 455, height: 'auto' },
actions: {
addAction: this.#addAction,
editAction: this.#editAction,
removeAction: this.#removeAction,
addFeature: this.#addFeature,
editFeature: this.#editFeature,
removeFeature: this.#removeFeature,
addCategory: this.#addCategory,
deleteProperty: this.#deleteProperty,
viewAdversary: this.#viewAdversary,
@ -38,7 +34,11 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
submitOnChange: true,
closeOnSubmit: false
},
dragDrop: [{ dragSelector: null, dropSelector: '.category-container' }]
dragDrop: [
{ dragSelector: null, dropSelector: '.category-container' },
{ dragSelector: null, dropSelector: '.tab.features' },
{ dragSelector: '.feature-item', dropSelector: null }
]
};
static PARTS = {
@ -51,9 +51,9 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
id: 'details',
template: 'systems/daggerheart/templates/sheets-settings/environment-settings/details.hbs'
},
actions: {
id: 'actions',
template: 'systems/daggerheart/templates/sheets-settings/environment-settings/actions.hbs'
features: {
id: 'features',
template: 'systems/daggerheart/templates/sheets-settings/environment-settings/features.hbs'
},
adversaries: {
id: 'adversaries',
@ -70,13 +70,13 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
icon: null,
label: 'DAGGERHEART.General.tabs.details'
},
actions: {
features: {
active: false,
cssClass: '',
group: 'primary',
id: 'actions',
id: 'features',
icon: null,
label: 'DAGGERHEART.General.tabs.actions'
label: 'DAGGERHEART.General.tabs.features'
},
adversaries: {
active: false,
@ -107,6 +107,7 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
_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);
@ -122,46 +123,23 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
return tabs;
}
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/magic/perception/orb-crystal-ball-scrying-blue.webp'
}
]);
this.render();
}
static async #editAction(event, target) {
event.stopPropagation();
const actionIndex = target.dataset.index;
await new DHActionConfig(this.actor.system.actions[actionIndex]).render({
force: true
});
static async #editFeature(_, target) {
this.actor.items.get(target.id).sheet.render(true);
}
static async #removeAction(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))
});
static async #removeFeature(_, target) {
await this.actor.deleteEmbeddedDocuments('Item', [target.id]);
this.render();
}
@ -199,10 +177,23 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
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 === 'adversary') {
if (item.type === 'adversary' && event.target.closest('.category-container')) {
const target = event.target.closest('.category-container');
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
const current = foundry.utils.getProperty(this.actor, path).map(x => x.uuid);
@ -210,6 +201,9 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
[path]: [...current, item.uuid]
});
this.render();
} else if (item.type === 'feature' && event.target.closest('.tab.features')) {
await this.actor.createEmbeddedDocuments('Item', [item]);
this.render();
}
}