dragdrop shennenegins
Right now, a user can drag a spell onto their character sheet. I store that in a 'spell' array and list it in the 'spell library'. They can prep the spell with the UI and that (for now) sets a flag which causes it to be displayed under the 'prepared spells' side as well. Ideally, I'd like a user to drag the spell from the library side to the prepped side and achieve the same thing. I don't need a solution and I haven't started trying to do this, but I'd really appreciate if someone could simply drop me a hint. A key word or function to look into to make this happen, because right now my understanding of how items get embedded into actors after dragging them onto the sheet is, "A wizard foundry did it."
5 Replies
the key word hint is
dragDrop
more details are that somewhere in ActorSheet
, there's a dragDrop
registration which handles Item droppage.
You'll want to modify that logic to see what element the item is dropped into and thus change what happensSomehow, in spite of me looking, I managed to not find this function. *facepalm*
Thanks. That should be enough for me to get into all sorts of stupid trouble!
these are the docs for DragDrop itself, but they're not super helpful:
https://foundryvtt.com/api/DragDrop.html
Core puts some fluff around this automatically for ActorSheet, providing these methods:
_onDrop
, and more interestingly _onDropItem
I can't find these in the docs actually, seems they're marked Private, but a system is definitely expected to override them.
@cswendrowski check me on that 'definitely' when you get a chance pretty please.I see. I mean, that looks usable after some experimentation. Famous last words, though.
I just noticed this in testing almost immediately. One of my players messed up his spell order because he instinctively wanted to drag his spells over to the 'prepped' section, so this should be a thing.
Default behaviour for drag&dropping an item on same sheet is to sort them. You may want to override that some when they aren't dropped into same section.