Added item icon on hotbar drop (#54)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user