mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 07:36:26 +01:00
Added support for actionMacro drag from items
This commit is contained in:
parent
3232e7ed65
commit
bd4d903a96
4 changed files with 65 additions and 5 deletions
|
|
@ -1518,7 +1518,9 @@
|
||||||
"noAvailableArmorMarks": "You have no more available armor marks",
|
"noAvailableArmorMarks": "You have no more available armor marks",
|
||||||
"notEnoughStress": "You don't have enough stress",
|
"notEnoughStress": "You don't have enough stress",
|
||||||
"damageIgnore": "{character} did not take damage",
|
"damageIgnore": "{character} did not take damage",
|
||||||
"featureIsMissing": "Feature is missing"
|
"featureIsMissing": "Feature is missing",
|
||||||
|
"actionIsMissing": "Action is missing",
|
||||||
|
"unownedActionMacro": "Cannot make a Use macro for an Action not on your character"
|
||||||
},
|
},
|
||||||
"Tooltip": {
|
"Tooltip": {
|
||||||
"openItemWorld": "Open Item World",
|
"openItemWorld": "Open Item World",
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
||||||
},
|
},
|
||||||
dragDrop: [
|
dragDrop: [
|
||||||
{ dragSelector: null, dropSelector: '.tab.features .drop-section' },
|
{ dragSelector: null, dropSelector: '.tab.features .drop-section' },
|
||||||
{ dragSelector: '.feature-item', dropSelector: null }
|
{ dragSelector: '.feature-item', dropSelector: null },
|
||||||
|
{ dragSelector: '.action-item', dropSelector: null }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -258,6 +259,23 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
||||||
const featureData = { type: 'Item', data: { ...feature.toObject(), _id: null }, fromInternal: true };
|
const featureData = { type: 'Item', data: { ...feature.toObject(), _id: null }, fromInternal: true };
|
||||||
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
|
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
|
||||||
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
|
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
|
||||||
|
} else {
|
||||||
|
const actionItem = event.currentTarget.closest('.action-item');
|
||||||
|
if (actionItem) {
|
||||||
|
const action = this.document.system.actions[actionItem.dataset.index];
|
||||||
|
if (!action) {
|
||||||
|
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.actionIsMissing'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const actionData = {
|
||||||
|
type: 'Action',
|
||||||
|
data: { ...action.toObject(), id: action.id, itemUuid: this.document.uuid },
|
||||||
|
fromInternal: true
|
||||||
|
};
|
||||||
|
event.dataTransfer.setData('text/plain', JSON.stringify(actionData));
|
||||||
|
event.dataTransfer.setDragImage(actionItem.querySelector('img'), 60, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export default class DhHotbar extends Hotbar {
|
export default class DhHotbar extends foundry.applications.ui.Hotbar {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
|
|
@ -19,6 +19,25 @@ export default class DhHotbar extends Hotbar {
|
||||||
await item.use({});
|
await item.use({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async useAction(itemUuid, actionId) {
|
||||||
|
const item = await foundry.utils.fromUuid(itemUuid);
|
||||||
|
if (!item) {
|
||||||
|
return ui.notifications.warn('WARNING.ObjectDoesNotExist', {
|
||||||
|
format: {
|
||||||
|
name: game.i18n.localize('Document'),
|
||||||
|
identifier: itemUuid
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const action = item.system.actions.find(x => x.id === actionId);
|
||||||
|
if (!action) {
|
||||||
|
return ui.notifications.warn('DAGGERHEART.UI.Notifications.actionIsMissing');
|
||||||
|
}
|
||||||
|
|
||||||
|
await action.use({});
|
||||||
|
}
|
||||||
|
|
||||||
setupHooks() {
|
setupHooks() {
|
||||||
Hooks.on('hotbarDrop', (bar, data, slot) => {
|
Hooks.on('hotbarDrop', (bar, data, slot) => {
|
||||||
if (data.type === 'Item') {
|
if (data.type === 'Item') {
|
||||||
|
|
@ -35,6 +54,16 @@ export default class DhHotbar extends Hotbar {
|
||||||
this.createItemMacro(data, slot);
|
this.createItemMacro(data, slot);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (data.type === 'Action') {
|
||||||
|
const item = foundry.utils.fromUuidSync(data.data.itemUuid);
|
||||||
|
if (item.uuid.startsWith('Compendium')) return true;
|
||||||
|
if (!item.isOwned || !item.isOwner) {
|
||||||
|
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.unownedActionMacro'));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.createActionMacro(data, slot);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -49,4 +78,15 @@ export default class DhHotbar extends Hotbar {
|
||||||
await game.user.assignHotbarMacro(macro, slot);
|
await game.user.assignHotbarMacro(macro, slot);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async createActionMacro(data, slot) {
|
||||||
|
const macro = await Macro.implementation.create({
|
||||||
|
name: `${game.i18n.localize('Display')} ${name}`,
|
||||||
|
type: CONST.MACRO_TYPES.SCRIPT,
|
||||||
|
img: 'icons/svg/book.svg',
|
||||||
|
command: `await game.system.api.applications.ui.DhHotbar.useAction("${data.data.itemUuid}", "${data.data.id}");`
|
||||||
|
});
|
||||||
|
await game.user.assignHotbarMacro(macro, slot);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,8 @@ export const registerCountdownHooks = () => {
|
||||||
if (application) {
|
if (application) {
|
||||||
foundry.applications.instances.get(application)?.render();
|
foundry.applications.instances.get(application)?.render();
|
||||||
} else {
|
} else {
|
||||||
foundry.applications.instances.get('narrative-countdowns').render();
|
foundry.applications.instances.get('narrative-countdowns')?.render();
|
||||||
foundry.applications.instances.get('encounter-countdowns').render();
|
foundry.applications.instances.get('encounter-countdowns')?.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue