mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
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:
parent
eac58c1386
commit
e9ad9c539a
58 changed files with 1146 additions and 1114 deletions
|
|
@ -3,12 +3,7 @@ import DHBaseItemSheet from '../api/base-item.mjs';
|
|||
export default class BeastformSheet extends DHBaseItemSheet {
|
||||
/**@inheritdoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['beastform'],
|
||||
dragDrop: [{ dragSelector: null, dropSelector: '.drop-section' }],
|
||||
actions: {
|
||||
editFeature: this.editFeature,
|
||||
removeFeature: this.removeFeature
|
||||
}
|
||||
classes: ['beastform']
|
||||
};
|
||||
|
||||
/**@override */
|
||||
|
|
@ -40,26 +35,4 @@ export default class BeastformSheet extends DHBaseItemSheet {
|
|||
|
||||
return context;
|
||||
}
|
||||
|
||||
static editFeature(event) {
|
||||
const target = event.target.closest('[data-action="editFeature"]');
|
||||
const feature = this.document.system.features[target.dataset.index];
|
||||
feature.sheet.render({ force: true });
|
||||
}
|
||||
|
||||
static async removeFeature(_, target) {
|
||||
const current = this.document.system.features.map(x => x.uuid);
|
||||
await this.document.update({
|
||||
'system.features': current.filter((_, index) => index !== Number(target.dataset.index))
|
||||
});
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (item.type === 'feature') {
|
||||
const current = this.document.system.features.map(x => x.uuid);
|
||||
await this.document.update({ 'system.features': [...current, item.uuid] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import DHBaseItemSheet from '../api/base-item.mjs';
|
||||
import DHActionConfig from '../../sheets-configs/action-config.mjs';
|
||||
import { actionsTypes } from '../../../data/action/_module.mjs';
|
||||
|
||||
const { TextEditor } = foundry.applications.ux;
|
||||
|
||||
|
|
@ -169,71 +167,45 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
doc.sheet.render({ force: true });
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
async selectActionType() {
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/actionTypes/actionType.hbs',
|
||||
{ types: CONFIG.DH.ACTIONS.actionTypes }
|
||||
),
|
||||
title = 'Select Action Type',
|
||||
type = 'form',
|
||||
data = {};
|
||||
return Dialog.prompt({
|
||||
title,
|
||||
label: title,
|
||||
content,
|
||||
type,
|
||||
callback: html => {
|
||||
const form = html[0].querySelector('form'),
|
||||
fd = new foundry.applications.ux.FormDataExtended(form);
|
||||
foundry.utils.mergeObject(data, fd.object, { inplace: true });
|
||||
|
||||
return data;
|
||||
},
|
||||
rejectClose: false
|
||||
});
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
getActionPath(type) {
|
||||
return type === 'hope' ? 'hopeFeatures' : 'classFeatures';
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
static async addFeature(_, target) {
|
||||
const actionPath = this.getActionPath(target.dataset.type);
|
||||
const actionType = await this.selectActionType();
|
||||
const cls = actionsTypes[actionType?.type] ?? actionsTypes.attack,
|
||||
action = new cls(
|
||||
{
|
||||
_id: foundry.utils.randomID(),
|
||||
systemPath: actionPath,
|
||||
type: actionType.type,
|
||||
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType.type].name),
|
||||
...cls.getSourceConfig(this.document)
|
||||
},
|
||||
{
|
||||
parent: this.document
|
||||
}
|
||||
);
|
||||
await this.document.update({ [`system.${actionPath}`]: [...this.document.system[actionPath], action] });
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
static async editFeature(_, target) {
|
||||
const action = this.document.system[this.getActionPath(target.dataset.type)].find(
|
||||
x => x._id === target.dataset.feature
|
||||
);
|
||||
await new DHActionConfig(action).render(true);
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
static async deleteFeature(_, target) {
|
||||
const actionPath = this.getActionPath(target.dataset.type);
|
||||
const feature = await game.items.documentClass.create({
|
||||
type: 'feature',
|
||||
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') })
|
||||
});
|
||||
await this.document.update({
|
||||
[`system.${actionPath}`]: this.document.system[actionPath].filter(
|
||||
action => action._id !== target.dataset.feature
|
||||
)
|
||||
[`system.${actionPath}`]: [
|
||||
...this.document.system[actionPath].filter(x => x).map(x => x.uuid),
|
||||
feature.uuid
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
static async editFeature(_, button) {
|
||||
const target = button.closest('.feature-item');
|
||||
const actionPath = this.getActionPath(button.dataset.type);
|
||||
const feature = this.document.system[actionPath].find(x => x?.id === target.dataset.featureId);
|
||||
if (!feature) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.featureIsMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
feature.sheet.render(true);
|
||||
}
|
||||
|
||||
static async deleteFeature(event, button) {
|
||||
event.stopPropagation();
|
||||
const target = button.closest('.feature-item');
|
||||
const actionPath = this.getActionPath(button.dataset.type);
|
||||
|
||||
await this.document.update({
|
||||
[`system.${actionPath}`]: this.document.system[actionPath]
|
||||
.filter(feature => feature && feature.id !== target.dataset.featureId)
|
||||
.map(x => x.uuid)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { actionsTypes } from '../../../data/action/_module.mjs';
|
||||
import DHActionConfig from '../../sheets-configs/action-config.mjs';
|
||||
import DHBaseItemSheet from '../api/base-item.mjs';
|
||||
|
||||
export default class FeatureSheet extends DHBaseItemSheet {
|
||||
|
|
@ -6,7 +8,12 @@ export default class FeatureSheet extends DHBaseItemSheet {
|
|||
id: 'daggerheart-feature',
|
||||
classes: ['feature'],
|
||||
position: { height: 600 },
|
||||
window: { resizable: true }
|
||||
window: { resizable: true },
|
||||
actions: {
|
||||
addAction: FeatureSheet.#addAction,
|
||||
editAction: FeatureSheet.#editAction,
|
||||
removeAction: FeatureSheet.#removeAction
|
||||
}
|
||||
};
|
||||
|
||||
/**@override */
|
||||
|
|
@ -41,4 +48,83 @@ export default class FeatureSheet extends DHBaseItemSheet {
|
|||
|
||||
return context;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Render a dialog prompting the user to select an action type.
|
||||
*
|
||||
* @returns {Promise<object>} An object containing the selected action type.
|
||||
*/
|
||||
static async selectActionType() {
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/actionTypes/actionType.hbs',
|
||||
{ types: CONFIG.DH.ACTIONS.actionTypes }
|
||||
),
|
||||
title = 'Select Action Type';
|
||||
|
||||
return foundry.applications.api.DialogV2.prompt({
|
||||
window: { title },
|
||||
content,
|
||||
ok: {
|
||||
label: title,
|
||||
callback: (event, button, dialog) => button.form.elements.type.value
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new action to the item, prompting the user for its type.
|
||||
* @param {PointerEvent} _event - The originating click event
|
||||
* @param {HTMLElement} _button - The capturing HTML element which defines the [data-action="addAction"]
|
||||
*/
|
||||
static async #addAction(_event, _button) {
|
||||
const actionType = await FeatureSheet.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.document)
|
||||
},
|
||||
{
|
||||
parent: this.document
|
||||
}
|
||||
);
|
||||
await this.document.update({ 'system.actions': [...this.document.system.actions, action] });
|
||||
await new DHActionConfig(this.document.system.actions[this.document.system.actions.length - 1]).render({
|
||||
force: true
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an existing action on the item
|
||||
* @param {PointerEvent} _event - The originating click event
|
||||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="editAction"]
|
||||
*/
|
||||
static async #editAction(_event, button) {
|
||||
const action = this.document.system.actions[button.dataset.index];
|
||||
await new DHActionConfig(action).render({ force: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an action from the item.
|
||||
* @param {PointerEvent} event - The originating click event
|
||||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="removeAction"]
|
||||
*/
|
||||
static async #removeAction(event, button) {
|
||||
event.stopPropagation();
|
||||
const actionIndex = button.closest('[data-index]').dataset.index;
|
||||
await this.document.update({
|
||||
'system.actions': this.document.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import DHBaseItemSheet from '../api/base-item.mjs';
|
||||
import DHActionConfig from '../../sheets-configs/action-config.mjs';
|
||||
import { actionsTypes } from '../../../data/action/_module.mjs';
|
||||
|
||||
export default class SubclassSheet extends DHBaseItemSheet {
|
||||
/**@inheritdoc */
|
||||
|
|
@ -39,101 +37,63 @@ export default class SubclassSheet extends DHBaseItemSheet {
|
|||
}
|
||||
};
|
||||
|
||||
//TODO redo everything below this message
|
||||
|
||||
static addFeature(_, target) {
|
||||
if (target.dataset.type === 'action') this.addAction(target.dataset.level);
|
||||
else this.addEffect(target.dataset.level);
|
||||
}
|
||||
|
||||
static async editFeature(_, target) {
|
||||
if (target.dataset.type === 'action') this.editAction(target.dataset.level, target.dataset.feature);
|
||||
else this.editEffect(target.dataset.feature);
|
||||
}
|
||||
|
||||
static async deleteFeature(_, target) {
|
||||
if (target.dataset.type === 'action') this.removeAction(target.dataset.level, target.dataset.feature);
|
||||
else this.removeEffect(target.dataset.level, target.dataset.feature);
|
||||
}
|
||||
|
||||
async #selectActionType() {
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/actionTypes/actionType.hbs',
|
||||
{ types: CONFIG.DH.ACTIONS.actionTypes }
|
||||
),
|
||||
title = 'Select Action Type',
|
||||
type = 'form',
|
||||
data = {};
|
||||
return Dialog.prompt({
|
||||
title,
|
||||
label: title,
|
||||
content,
|
||||
type,
|
||||
callback: html => {
|
||||
const form = html[0].querySelector('form'),
|
||||
fd = new foundry.applications.ux.FormDataExtended(form);
|
||||
foundry.utils.mergeObject(data, fd.object, { inplace: true });
|
||||
return data;
|
||||
},
|
||||
rejectClose: false
|
||||
static async addFeature(_, target) {
|
||||
const feature = await game.items.documentClass.create({
|
||||
type: 'feature',
|
||||
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') })
|
||||
});
|
||||
}
|
||||
|
||||
async addAction(level) {
|
||||
const actionType = await this.#selectActionType();
|
||||
const cls = actionsTypes[actionType?.type] ?? actionsTypes.attack,
|
||||
action = new cls(
|
||||
{
|
||||
_id: foundry.utils.randomID(),
|
||||
systemPath: `${level}.actions`,
|
||||
type: actionType.type,
|
||||
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType.type].name),
|
||||
...cls.getSourceConfig(this.document)
|
||||
},
|
||||
{
|
||||
parent: this.document
|
||||
}
|
||||
);
|
||||
await this.document.update({ [`system.${level}.actions`]: [...this.document.system[level].actions, action] });
|
||||
await new DHActionConfig(
|
||||
this.document.system[level].actions[this.document.system[level].actions.length - 1]
|
||||
).render(true);
|
||||
}
|
||||
|
||||
async addEffect(level) {
|
||||
const embeddedItems = await this.document.createEmbeddedDocuments('ActiveEffect', [
|
||||
{ name: game.i18n.localize('DAGGERHEART.Feature.NewEffect') }
|
||||
]);
|
||||
await this.document.update({
|
||||
[`system.${level}.effects`]: [
|
||||
...this.document.system[level].effects.map(x => x.uuid),
|
||||
embeddedItems[0].uuid
|
||||
]
|
||||
[`system.${target.dataset.type}`]: feature.uuid
|
||||
});
|
||||
}
|
||||
|
||||
async editAction(level, id) {
|
||||
const action = this.document.system[level].actions.find(x => x._id === id);
|
||||
await new DHActionConfig(action).render(true);
|
||||
static async editFeature(_, button) {
|
||||
const feature = this.document.system[button.dataset.type];
|
||||
if (!feature) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.featureIsMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
feature.sheet.render(true);
|
||||
}
|
||||
|
||||
async editEffect(id) {
|
||||
const effect = this.document.effects.get(id);
|
||||
effect.sheet.render(true);
|
||||
}
|
||||
static async deleteFeature(event, button) {
|
||||
event.stopPropagation();
|
||||
|
||||
async removeAction(level, id) {
|
||||
await this.document.update({
|
||||
[`system.${level}.actions`]: this.document.system[level].actions.filter(action => action._id !== id)
|
||||
[`system.${button.dataset.type}`]: null
|
||||
});
|
||||
}
|
||||
|
||||
async removeEffect(level, id) {
|
||||
await this.document.effects.get(id).delete();
|
||||
await this.document.update({
|
||||
[`system.${level}.effects`]: this.document.system[level].effects
|
||||
.filter(x => x && x.id !== id)
|
||||
.map(effect => effect.uuid)
|
||||
});
|
||||
async _onDragStart(event) {
|
||||
const featureItem = event.currentTarget.closest('.drop-section');
|
||||
|
||||
if (featureItem) {
|
||||
const feature = this.document.system[featureItem.dataset.type];
|
||||
if (!feature) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.featureIsMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
const featureData = { type: 'Item', data: { ...feature.toObject(), _id: null }, 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') {
|
||||
const dropSection = event.target.closest('.drop-section');
|
||||
if (this.document.system[dropSection.dataset.type]) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.featureIsFull'));
|
||||
return;
|
||||
}
|
||||
|
||||
await this.document.update({ [`system.${dropSection.dataset.type}`]: item.uuid });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue