fix-drag-drop-from-actor-sheet #143
3 changed files with 30 additions and 21 deletions
|
@ -457,27 +457,6 @@ export class DS4ActorSheet extends ActorSheet {
|
||||||
|
|
||||||
this.actor.updateEmbeddedDocuments("Item", updates);
|
this.actor.updateEmbeddedDocuments("Item", updates);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {DragEvent} event
|
|
||||||
* @param {object} data
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
async _onDropItem(event, data) {
|
|
||||||
const item = await Item.implementation.fromDropData(data);
|
|
||||||
if (item && !this.actor.canOwnItemType(item.type)) {
|
|
||||||
notifications.warn(
|
|
||||||
getGame().i18n.format("DS4.WarningActorCannotOwnItem", {
|
|
||||||
actorName: this.actor.name,
|
|
||||||
actorType: this.actor.type,
|
|
||||||
itemName: item.name,
|
|
||||||
itemType: item.type,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return super._onDropItem(event, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,12 +4,14 @@
|
||||||
|
|
||||||
import { registerForHotbarDropHook } from "./hotbar-drop";
|
import { registerForHotbarDropHook } from "./hotbar-drop";
|
||||||
import { registerForInitHook } from "./init";
|
import { registerForInitHook } from "./init";
|
||||||
|
import { registerForPreCreateItemHook } from "./pre-create-item";
|
||||||
import { registerForReadyHook } from "./ready";
|
import { registerForReadyHook } from "./ready";
|
||||||
import { registerForRenderHooks } from "./render";
|
import { registerForRenderHooks } from "./render";
|
||||||
import { registerForSetupHook } from "./setup";
|
import { registerForSetupHook } from "./setup";
|
||||||
|
|
||||||
export function registerForHooks(): void {
|
export function registerForHooks(): void {
|
||||||
registerForHotbarDropHook();
|
registerForHotbarDropHook();
|
||||||
|
registerForPreCreateItemHook();
|
||||||
registerForInitHook();
|
registerForInitHook();
|
||||||
registerForReadyHook();
|
registerForReadyHook();
|
||||||
registerForRenderHooks();
|
registerForRenderHooks();
|
||||||
|
|
28
src/hooks/pre-create-item.js
Normal file
28
src/hooks/pre-create-item.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Johannes Loher
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import { notifications } from "../ui/notifications.js";
|
||||||
|
import { getGame } from "../utils/utils.js";
|
||||||
|
|
||||||
|
export function registerForPreCreateItemHook() {
|
||||||
|
Hooks.on("preCreateItem", preCreateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {import('../documents/item/item.js').DS4Item} item
|
||||||
|
* @returns {void | false}
|
||||||
|
*/
|
||||||
|
function preCreateItem(item) {
|
||||||
|
if (item.parent instanceof Actor && !item.parent.canOwnItemType(item.type)) {
|
||||||
|
notifications.warn(
|
||||||
|
getGame().i18n.format("DS4.WarningActorCannotOwnItem", {
|
||||||
|
actorName: item.actor.name,
|
||||||
|
actorType: item.actor.type,
|
||||||
|
itemName: item.name,
|
||||||
|
itemType: item.type,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue