PDA

View Full Version : Can dragdata objects be created from scratch?



chillhelm
July 24th, 2023, 21:56
Hi,

I want to make an extension that allows the user to make last minute modifications to a roll. I can capture the dropped roll, open a window where the user can make their modifications and confirm their roll, and then have them click a button to lock in their selection. However, I can't create a dragdata object to pass on to the original destination of the roll. And if I try to store the dragdata object, it looses it's dragdata-ness. When I try to store it by assigning it to a variable in the windows (or extensions) scope, the dragdata object degenerates to generic userdata (presumably it gets garbage collected behind the scenes?).

In short, can I create a dragdata object without having the user manually start a drag operation?

Best,
Chillhelm

superteddy57
July 24th, 2023, 22:07
The wiki is a great place for this type of information.

https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644741/dragdata

So yes you can create a custom dragdata object.

chillhelm
July 24th, 2023, 23:36
This article doesn't mention creating Dragdata objects. Only what you can do with them, once you have them (like customizing existing dragdata objects or adding data etc).

I could create a Lua dictionary that has all the properties of a dragdata object, but I'd also have to implement every single function listed there. And that still wouldn't work, because the code that I'm passing my Dragdata object to calls the member functions of the Dragdata object like this

dragdata.getType()
But if I implemented the Dragdata object in Lua on my own member functions would have to be called like this:

dragdata:getType()

In short: No. I've already checked the wiki and the old refdoc (https://www.fantasygrounds.com/refdoc/) (which one are we supposed to use btw? The wiki says to use the old one) and creating a new dragdata object or storing an old one isn't mentioned in either. But I know that the API contains functions that are not documented in the refdoc or the wiki (you can find API calls to unlisted functions in CoreRPG) so I was hoping someone knows one of those.

Moon Wizard
July 25th, 2023, 02:57
You can not create dragdata objects directly. You can use one passed as part of the parameters provided by a dice landed or mouse event.

What is the purpose of creating a dragdata object?

Regards,
JPG

chillhelm
July 25th, 2023, 10:57
Well, as I described in the OP: I want to capture a drag as it is dropped on a token (easy enough), open a window where the user can make adjustments (apply bonuses etc) and then at will pass the (modified) result on to the appropriate ruleset handler. (In my case [SavageWorlds ruleset] this would be CombatManager.onActionDropEvent(...)).

I would have liked to use the existing dragdata functionality, instead of reimplementing that whole thing, but to do that I'd have to make the user drag something onto something in order to get a dragdata object ... that seems like bad UX (since the purpose of this extension would be to speed things up and requiring two drags doesn't do that).

So from what I can see I'll have to reimplement the entirety of dragdata functionality into some global state object that I can pass on to the destination. It's awkward and a lot of work to maintain, but it would work.

PS: the fgapp.idea.informer.com link in your signature is broken. Apparently the page doesn't support https.

Trenloe
July 25th, 2023, 11:37
You don't need to exactly recreate the whole draginfo record, you only need to create the values that the Savage Worlds code will read.

In Savage Worls, CombatManager.onActionDropEvent calls RollsManager.throwDragged which then calls: RollsManager.throwDice(sType, aDices, nMod, sDesc, rCustomData, rSource, vTargets)

So you can directly call RollsManager.throwDice with the various parameters populated as needed.

chillhelm
July 25th, 2023, 11:49
Ok, but then my extension is overwriting any ruleset behaviour that happens between the drop and the rolling or I would have to redo all that work myself (not to mention what happens if other extensions also hook into that same structure, like one of my own other extensions already does).
I strongly suspect that the ruleset is more prone to changing than the dragdata object structure, so keeping up with changes on a reimplementation of dragdata should be less frequent maintenance work than trying to recreate the ruleset behaviour.

I believe that for sideways compatibility reasons (interactions with other extensions), forward compatibility (likelyhood of future ruleset changes vs future dragdata changes) a dragdata reimplementation in lua is the way to go.

Or, of course, I just keep pestering you guys until you give me Interface.getDummyDragDataObject() ;)