Implement Drag & Drop of checks

This commit is contained in:
Johannes Loher 2021-04-15 20:00:37 +02:00
parent 9e72c6560f
commit 0d03dbf424
35 changed files with 108 additions and 3 deletions

View file

@ -58,6 +58,10 @@ interface DS4ActorPreparedDataDataRolling {
export type Check = keyof typeof DS4.i18n.checks;
export function isCheck(value: string): value is Check {
return Object.keys(DS4.i18n.checks).includes(value);
}
type DS4ActorPreparedDataDataChecks = {
[key in Check]: number;
};

View file

@ -1,9 +1,11 @@
import { ModifiableDataBaseTotal } from "../../common/common-data";
import { DS4 } from "../../config";
import { getCanvas } from "../../helpers";
import { DS4Item } from "../../item/item";
import { DS4ItemData } from "../../item/item-data";
import notifications from "../../ui/notifications";
import { DS4Actor } from "../actor";
import { isCheck } from "../actor-prepared-data";
/**
* The base Sheet class for all DS4 Actors
@ -27,6 +29,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Data<DS4Actor>> {
".special-creature-abilities",
],
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "values" }],
dragDrop: [
{ dragSelector: ".item-list .item", dropSelector: null },
{ dragSelector: ".ds4-check", dropSelector: null },
],
width: 650,
});
}
@ -240,6 +246,27 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Data<DS4Actor>> {
this.actor.rollCheck(check);
}
/** @override */
_onDragStart(event: DragEvent): void {
const target = event.currentTarget as HTMLElement;
if (!(target instanceof HTMLElement)) return super._onDragStart(event);
const check = target.dataset.check;
if (!check) return super._onDragStart(event);
if (!isCheck(check)) throw new Error(game.i18n.format("DS4.ErrorCannotDragMissingCheck", { check }));
const dragData = {
actorId: this.actor.id,
sceneId: this.actor.isToken ? getCanvas().scene?.id : null,
tokenId: this.actor.isToken ? this.actor.token?.id : null,
type: "Check",
data: check,
};
event.dataTransfer?.setData("text/plain", JSON.stringify(dragData));
}
/** @override */
protected async _onDropItem(
event: DragEvent,