Skip to content

Commit

Permalink
feat: add ability to drop folders on actors
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin9257 committed Jan 31, 2025
1 parent a430a34 commit 628a708
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/module/entities/TwodsixActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,12 @@ export default class TwodsixActor extends Actor {
return false;
}

/**
* Handle a dropped ActiveEffect on the Actor.
* @param {TwodsixActiveEffect} droppedEffect Dropped ActiveEffect
* @returns {Promise<boolean>}
*
*/
public async handleDroppedActiveEffect(droppedEffect:TwodsixActiveEffect): Promise<boolean> {
if ( !droppedEffect || (droppedEffect.target === this) ) {
return false;
Expand All @@ -1118,6 +1124,28 @@ export default class TwodsixActor extends Actor {
return true;
}

/**
* Handle a dropped Folder on the Actor.
* @param {FolderData} folder Extracted folder document
* @returns {Promise<void>}
*
*/
public async handleDroppedFolder(folder:FolderData): Promise<void> {
if (folder?.type === "Item" && folder?.contents.length > 0){
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: {title: game.i18n.localize("TWODSIX.Warnings.AddMultipleItems")},
content: game.i18n.localize("TWODSIX.Warnings.ConfirmDrop")
});
if (confirmed) {
for (const it of folder.contents) {
await this.handleDroppedItem(it);
}
}
} else {
ui.notifications.warn("TWODSIX.Warnings.CantDropFolder", {localize: true});
}
}

/**
* Method to handle a dropped damage payload
* @param {any} damagePayload The damage paylod being dropped (includes damage amount, AP value and damage type & label)
Expand Down
2 changes: 1 addition & 1 deletion src/module/handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export default function registerHandlebarsHelpers(): void {
return style;
});

Handlebars.registerHelper("concat", (...args) => args.slice(0, args.length - 1).join('')); //Needed? In FVTT baseline
Handlebars.registerHelper("concat", (...args) => args.slice(0, args.length - 1).join('')); //Needed -YES. FVTT baseline concat works differently
/*** No longer needed ****/
/*
Handlebars.registerHelper('each_sort_by_property', (property:string, array:TwodsixItem[], options) => {
Expand Down
6 changes: 5 additions & 1 deletion src/module/hooks/dropItemOnToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import TwodsixActor from "../entities/TwodsixActor";
import { getDocFromDropData } from "../utils/sheetUtils";
Hooks.on('dropCanvasData', (canvasObject, dropData) => {
if ((['damageItem', 'ActiveEffect'].includes(dropData.type) || (dropData.type === "Item" && !game.modules.get("item-piles")?.active)) && game.settings.get("twodsix", "allowDropOnIcon")) {
if ((['damageItem', 'ActiveEffect', 'Folder'].includes(dropData.type) || (dropData.type === "Item" && !game.modules.get("item-piles")?.active)) && game.settings.get("twodsix", "allowDropOnIcon")) {
catchDrop(canvasObject, dropData).then();
return false;
}
Expand Down Expand Up @@ -34,6 +34,10 @@ async function catchDrop(canvasObject: Canvas, dropData): Promise<any> {
const droppedEffect = await fromUuid(dropData.uuid);
return await targetActor.handleDroppedActiveEffect(droppedEffect);
}
case 'Folder': {
const folder = await fromUuid(dropData.uuid);
return targetActor.handleDroppedFolder(folder);
}
default: {
ui.notifications.warn("TWODSIX.Warnings.CantDropOnToken", {localize: true});
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/module/sheets/AbstractTwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ export abstract class AbstractTwodsixActorSheet extends foundry.applications.api
} else if (dropData.type === 'ActiveEffect') {
const droppedEffect = await fromUuid(dropData.uuid);
await this.onDropActiveEffect(ev, droppedEffect);
} else if (dropData.type === 'Folder') {
const droppedFolder = await fromUuid(dropData.uuid);
await (<TwodsixActor>this.actor).handleDroppedFolder(droppedFolder);
} else {
console.log(`Unknown Drop Type ${dropData.type}`);
return false;
Expand Down
5 changes: 4 additions & 1 deletion static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,10 @@
"CantFindShield": "Can't find an equipped shield to block",
"NoPsiPoints": "Must have at least one psionic point to use an ability",
"PsiUsageGTZero": "PSI Points used must be greater than zero",
"InvalidFormula": "Formula is Invalid for: "
"InvalidFormula": "Formula is Invalid for: ",
"ConfirmDrop": "Add all contents of folder to actor?",
"AddMultipleItems": "Add Multiple Items",
"CantDropFolder": "Cannot drop this folder onto actor."
}
},
"TYPES": {
Expand Down

0 comments on commit 628a708

Please sign in to comment.