Hooks refactor
This commit is contained in:
parent
dea687654a
commit
4663845c5f
4 changed files with 9 additions and 92 deletions
|
@ -98,47 +98,4 @@ export class BladesActorSheet extends ActorSheet {
|
|||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
async _onDrop (event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// Get dropped data
|
||||
let data;
|
||||
let item;
|
||||
try {
|
||||
data = JSON.parse(event.dataTransfer.getData('text/plain'));
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add only Items.
|
||||
if (data.type === "Item") {
|
||||
|
||||
// Import from Compendium
|
||||
if (data.pack) {
|
||||
const pack = game.packs.find(p => p.collection === data.pack);
|
||||
await pack.getEntity(data.id).then(ent => {
|
||||
item = ent;
|
||||
});
|
||||
}
|
||||
// Get from Items list.
|
||||
else {
|
||||
// Class must be distinct.
|
||||
item = game.items.get(data.id);
|
||||
}
|
||||
|
||||
if (item) {
|
||||
const actor = this.actor;
|
||||
BladesHelpers.removeDuplicatedItemType(item.data.type, actor);
|
||||
}
|
||||
|
||||
// Call parent on drop logic
|
||||
return super._onDrop(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
}
|
||||
|
|
|
@ -94,10 +94,14 @@ Hooks.once("init", async function() {
|
|||
/*
|
||||
* Hooks
|
||||
*/
|
||||
Hooks.on("createOwnedItem", (parent, child, options, userId) => {
|
||||
BladesHelpers.callItemLogic(child, parent);
|
||||
Hooks.on("preCreateOwnedItem", (parent_entity, child_data, options, userId) => {
|
||||
BladesHelpers.removeDuplicatedItemType(child_data.type, parent_entity);
|
||||
});
|
||||
|
||||
Hooks.on("deleteOwnedItem", (parent, child, options, userId) => {
|
||||
BladesHelpers.undoItemLogic(child, parent);
|
||||
Hooks.on("createOwnedItem", (parent_entity, child_data, options, userId) => {
|
||||
BladesHelpers.callItemLogic(child_data, parent_entity);
|
||||
});
|
||||
|
||||
Hooks.on("deleteOwnedItem", (parent_entity, child_data, options, userId) => {
|
||||
BladesHelpers.undoItemLogic(child_data, parent_entity);
|
||||
});
|
||||
|
|
|
@ -95,48 +95,4 @@ export class BladesCrewSheet extends ActorSheet {
|
|||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
async _onDrop (event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// Get dropped data
|
||||
let data;
|
||||
let item;
|
||||
try {
|
||||
data = JSON.parse(event.dataTransfer.getData('text/plain'));
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add only Items.
|
||||
if (data.type === "Item") {
|
||||
|
||||
// Import from Compendium
|
||||
if (data.pack) {
|
||||
const pack = game.packs.find(p => p.collection === data.pack);
|
||||
await pack.getEntity(data.id).then(ent => {
|
||||
item = ent;
|
||||
});
|
||||
}
|
||||
// Get from Items list.
|
||||
else {
|
||||
// Class must be distinct.
|
||||
item = game.items.get(data.id);
|
||||
}
|
||||
|
||||
if (item) {
|
||||
const actor = this.actor;
|
||||
BladesHelpers.removeDuplicatedItemType(item.data.type, actor);
|
||||
BladesHelpers.callItemLogic(item, actor);
|
||||
}
|
||||
|
||||
// Call parent on drop logic
|
||||
return super._onDrop(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue