Implement Drag & Drop of checks
This commit is contained in:
parent
9e72c6560f
commit
0d03dbf424
35 changed files with 108 additions and 3 deletions
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -334,6 +334,40 @@ export const DS4 = {
|
|||
spellcasting: "systems/ds4/assets/icons/official/combat-values/spellcasting.png",
|
||||
targetedSpellcasting: "systems/ds4/assets/icons/official/combat-values/targeted-spellcasting.png",
|
||||
},
|
||||
|
||||
/**
|
||||
* Define the file paths to check images
|
||||
*/
|
||||
checks: {
|
||||
appraise: "systems/ds4/assets/icons/game-icons/two-coins.svg",
|
||||
changeSpell: "systems/ds4/assets/icons/game-icons/card-exchange.svg",
|
||||
climb: "systems/ds4/assets/icons/game-icons/mountain-climbing.svg",
|
||||
communicate: "systems/ds4/assets/icons/game-icons/discussion.svg",
|
||||
decipherScript: "systems/ds4/assets/icons/game-icons/rune-stone.svg",
|
||||
defend: "systems/ds4/assets/icons/game-icons/shield.svg",
|
||||
defyPoison: "systems/ds4/assets/icons/game-icons/poison-bottle.svg",
|
||||
disableTraps: "systems/ds4/assets/icons/game-icons/wolf-trap.svg",
|
||||
featOfStrength: "systems/ds4/assets/icons/game-icons/biceps.svg",
|
||||
flirt: "systems/ds4/assets/icons/game-icons/charm.svg",
|
||||
haggle: "systems/ds4/assets/icons/game-icons/cash.svg",
|
||||
hide: "systems/ds4/assets/icons/game-icons/hidden.svg",
|
||||
identifyMagic: "systems/ds4/assets/icons/game-icons/uncertainty.svg",
|
||||
jump: "systems/ds4/assets/icons/game-icons/jump-across.svg",
|
||||
knowledge: "systems/ds4/assets/icons/game-icons/bookshelf.svg",
|
||||
openLock: "systems/ds4/assets/icons/game-icons/padlock-open.svg",
|
||||
perception: "systems/ds4/assets/icons/game-icons/awareness.svg",
|
||||
pickPocket: "systems/ds4/assets/icons/game-icons/robber-hand.svg",
|
||||
readTracks: "systems/ds4/assets/icons/game-icons/deer-track.svg",
|
||||
resistDisease: "systems/ds4/assets/icons/game-icons/virus.svg",
|
||||
ride: "systems/ds4/assets/icons/game-icons/cavalry.svg",
|
||||
search: "systems/ds4/assets/icons/game-icons/magnifying-glass.svg",
|
||||
senseMagic: "systems/ds4/assets/icons/game-icons/sparkles.svg",
|
||||
sneak: "systems/ds4/assets/icons/game-icons/mute.svg",
|
||||
startFire: "systems/ds4/assets/icons/game-icons/campfire.svg",
|
||||
swim: "systems/ds4/assets/icons/game-icons/pool-dive.svg",
|
||||
wakeUp: "systems/ds4/assets/icons/game-icons/alarm-clock.svg",
|
||||
workMechanism: "systems/ds4/assets/icons/game-icons/lever.svg",
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { isCheck } from "../actor/actor-prepared-data";
|
||||
import { DS4Item } from "../item/item";
|
||||
import { DS4ItemData } from "../item/item-data";
|
||||
import { createRollCheckMacro } from "../macros/roll-check";
|
||||
import { createRollItemMacro } from "../macros/roll-item";
|
||||
import notifications from "../ui/notifications";
|
||||
|
||||
|
@ -21,7 +23,13 @@ export default function registerForHotbarDropHook(): void {
|
|||
}),
|
||||
);
|
||||
}
|
||||
await createRollItemMacro(itemData, slot);
|
||||
return createRollItemMacro(itemData, slot);
|
||||
}
|
||||
case "Check": {
|
||||
if (!("data" in data) || typeof data.data !== "string" || !isCheck(data.data)) {
|
||||
return notifications.warn(game.i18n.localize("DS4.WarningInvalidCheckDropped"));
|
||||
}
|
||||
return createRollCheckMacro(data.data, slot);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -29,7 +29,7 @@ async function getOrCreateRollCheckMacro(check: Check): Promise<Macro | null> {
|
|||
command,
|
||||
name: DS4.i18n.checks[check],
|
||||
type: "script",
|
||||
// TODO: img, should be addressed in https://git.f3l.de/dungeonslayers/ds4/-/issues/79
|
||||
img: DS4.icons.checks[check],
|
||||
flags: { "ds4.checkMacro": true },
|
||||
},
|
||||
{ displaySheet: false },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue