diff --git a/CHANGELOG.md b/CHANGELOG.md index 87c7ce7..4a08a98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog Date format : day/month/year -## 1.11.1 - ??/05/2024 - Little fixes again +## 1.11.1 - ??/05/2024 - Some QoL - Added ability to players to set their default Item's windows height in settings (#55). +- Macro : Added item icon on hotbar drop (#54). - Moved `The blade with no name: Ancestral sword of the Dragon [Blessed Treasure]` from items to weapons compendium. ## 1.11.0 - 13/12/2023 - Little fixes diff --git a/system/scripts/actors/base-character-sheet.js b/system/scripts/actors/base-character-sheet.js index b44825a..349a47b 100644 --- a/system/scripts/actors/base-character-sheet.js +++ b/system/scripts/actors/base-character-sheet.js @@ -203,6 +203,11 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e { let itemData = item.toObject(true); + // If from another actor, break the link + if (itemData.system.parent_id !== null && itemData.system.parent_id.actor_id !== this.actor._id) { + itemData.system.parent_id = null; + } + // Item subtype specific switch (itemData.type) { case "army_cohort": @@ -247,11 +252,10 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e { itemData.system.xp_used = 0; itemData.system.in_curriculum = true; } else { - // Check if technique is allowed for this character - // if (!game.user.isGM && !this.actor.system.techniques[itemData.system.technique_type]) { - // ui.notifications.info("l5r5e.techniques.not_allowed", {localize: true}); - // return; - // } + // Informative message : Check if technique is allowed for this character + if (!game.user.isGM && !this.actor.system.techniques[itemData.system.technique_type]) { + ui.notifications.info("l5r5e.techniques.not_allowed", {localize: true}); + } // Verify cost itemData.system.xp_cost = @@ -277,12 +281,10 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e { if (li.dataset.itemParentId && li.dataset.itemId) { const item = this.actor.items.get(li.dataset.itemParentId)?.items.get(li.dataset.itemId); if (item) { - const dragData = { + event.dataTransfer.setData("text/plain", JSON.stringify({ type: "Item", - data: foundry.utils.duplicate(item), - }; - dragData.data.system.parent_id = null; - event.dataTransfer.setData("text/plain", JSON.stringify(dragData)); + uuid: item.uuid, + })); return; } } diff --git a/system/scripts/actors/twenty-questions-dialog.js b/system/scripts/actors/twenty-questions-dialog.js index f9f1815..129a7cd 100644 --- a/system/scripts/actors/twenty-questions-dialog.js +++ b/system/scripts/actors/twenty-questions-dialog.js @@ -289,11 +289,10 @@ export class TwentyQuestionsDialog extends FormApplication { `L5R5E | 20Q | This technique is not a school ability : ${item.system.technique_type}` ); return; + } else if (!this.object.data.step3.allowed_techniques?.[item.system.technique_type]) { + // Informative message : Tech not allowed + ui.notifications.info("l5r5e.techniques.not_allowed", {localize: true}); } - // } else if (!this.object.data.step3.allowed_techniques?.[item.system.technique_type]) { - // // Tech not allowed - // ui.notifications.info("l5r5e.techniques.not_allowed", {localize: true}); - // return; } break; diff --git a/system/scripts/dice/dice-picker-dialog.js b/system/scripts/dice/dice-picker-dialog.js index 801df3e..d50333a 100644 --- a/system/scripts/dice/dice-picker-dialog.js +++ b/system/scripts/dice/dice-picker-dialog.js @@ -685,9 +685,9 @@ export class DicePickerDialog extends FormApplication { macro = await Macro.create({ name, type: "script", - scope: "global", + scope: "actor", command, - img: this._actor?.img ? this._actor.img : "systems/l5r5e/assets/dices/default/ring_et.svg", + img: this._actor?.img || "systems/l5r5e/assets/dices/default/ring_et.svg", }); } diff --git a/system/scripts/hooks.js b/system/scripts/hooks.js index b274d86..8bfc199 100644 --- a/system/scripts/hooks.js +++ b/system/scripts/hooks.js @@ -28,6 +28,14 @@ export default class HooksL5r5e { game.l5r5e.migrations.migrateWorld({ force: false }).then(); } + // Taken from dnd5 : Wait to register hotbar drop hook on ready so that modules could register earlier if they want to + Hooks.on("hotbarDrop", (bar, data, slot) => { + if (data.type === "Item") { + HooksL5r5e.#createItemMacro(data, slot); + return false; + } + }); + // For some reasons, not always really ready, so wait a little await new Promise((r) => setTimeout(r, 2000)); @@ -76,9 +84,7 @@ export default class HooksL5r5e { skillsList: "artisan,martial,scholar,social,trade", }, }); - ui.notifications.info( - game.i18n.localize("l5r5e.dice.dicepicker.gm_request_dp_to_players") - ); + ui.notifications.info("l5r5e.dice.dicepicker.gm_request_dp_to_players", {localize: true}); }, 3000, true @@ -313,4 +319,35 @@ export default class HooksL5r5e { context.blind = true; } } + + /** + * Attempt to create a macro from the dropped data. Will use an existing macro if one exists. + * @param {object} dropData The dropped data + * @param {number} slot The hotbar slot to use + * @returns {Promise} + */ + static async #createItemMacro(dropData, slot) { + const itemData = await Item.implementation.fromDropData(dropData); + if (!itemData) { + console.log("L5R5E | HK | Fail to get itemData", dropData); + return null; + } + + const macroData = { + type: "script", + scope: "actor", + name: (itemData.actor?.name ? `${itemData.actor?.name} : ` : '') + itemData.name, + img: itemData.img, + command: `await Hotbar.toggleDocumentSheet("${itemData.uuid}")`, + }; + + // Assign the macro to the hotbar + const macro = game.macros.find((m) => + m.name === macroData.name + && m.command === macroData.command + && m.isAuthor + ) || await Macro.create(macroData); + + await game.user.assignHotbarMacro(macro, slot); + } }