PDA

View Full Version : Overridden onDoubleClick still calling CoreRPG onDoubleClick



anathemort
January 18th, 2022, 20:44
Hello,
I am attempting to muck with what happens on token double-click, effectively turning a double-click into a toggle target action. manager_token has this:

function onInit()
-- snipped
Token.onDoubleClick = onDoubleClick
-- etc
end

function onDoubleClick(tokenMap, vImage)
-- open sheet if owner or host, etc
end


I would like to intervene in this process, so I tried this:


function onInit()
Token.onDoubleClick = onTokenDoubleClick;

OptionsManager.registerOption2("TFD_TDC", true, "option_header_client", "option_label_TFD_TDC", "option_entry_cycler",
{ labels = "option_val_on", values = "on", baselabel = "option_val_off", baseval = "off", default = "off" });
end

function onTokenDoubleClick(tokenMap, vImage)
Debug.chat("onDoubleClick", tokenMap);
if OptionsManager.getOption("TFD_TDC", "on") then
local nodeActive = CombatManager.getActiveCT();
local nodeCT = CombatManager.getCTFromToken(tokenMap);

if not nodeActive or not nodeCT then
Debug.chat("calling TM", nodeActive, nodeCT);
TokenManager.onDoubleClick(tokenMap, vImage);
else
local _, sRecord = DB.getValue(nodeActive, "link");
local owner = DB.getOwner(sRecord);

if DB.isOwner(sRecord) then
TargetingManager.toggleCTTarget(nodeActive, nodeCT);
else
Debug.chat("calling TM", "not owner");
TokenManager.onDoubleClick(tokenMap, vImage);
end
end
else
Debug.chat("calling TM", "option off");
TokenManager.onDoubleClick(tokenMap, vImage);
end
end


I can see my first debug message, and my code works all the way up to and including the target toggle. But the default TokenManager behavior still happens; I know this because as a host, if I double-click on a NPC, it gets targeted and the NPC sheet opens. However, none of my "calling TM" debug messages print, so I am lead to believe the original Token.onDoubleClick hook from TokenManager is still in place. I did try return true after my call to TargetingManager, but that didn't change anything. This is maybe not a possible thing to fix, but also it seems very likely I just don't know how LUA is resolving the override. Any insights?

celestian
January 18th, 2022, 20:49
Return true/false. True should block the super.

anathemort
January 18th, 2022, 20:51
Return true/false. True should block the super.

I tried that, but it had no effect.

Moon Wizard
January 18th, 2022, 22:19
You can't override the double-click handling in TokenManager without replacing TokenManager completely.

Token.onDoubleClick registrations are handler registrations, which any number can be registered and all will be called.

Regards,
JPG

anathemort
January 18th, 2022, 22:22
You can't override the double-click handling in TokenManager without replacing TokenManager completely.

Token.onDoubleClick registrations are handler registrations, which any number can be registered and all will be called.

Regards,
JPG

Thanks for clarifying, JPG! That's what it seemed like.

For curiosity's sake, Token is outside the ruleset packs, right? Is there an example of something similar in one of the ruleset packs, showing how you can use LUA "=" assignment to create a handler registry?

Moon Wizard
January 18th, 2022, 22:26
They are built-in "handler" registrations that are part of the FG API. Anything listed as a "handler" in the API falls into this category of a multiple registration scenario.

I've been slowly refactoring the scripts to move the handler registrations into onDesktopInit in many global scripts to allow more flexibility; but I've been doing that as I update the files for other reasons and I'm concerned with modifications that may break extensions. I don't think it will, but extension writers do some crazy stuff...

Regards,
JPG

NOTE: It looks like the "handler" tagging in the documentation got lost in the migration to the new wiki. Most handlers begin with "on...", such as "onDesktopInit", "onWindowOpened", etc.

anathemort
January 19th, 2022, 00:20
Okay, thanks.


but extension writers do some crazy stuff...

We have to keep you on your toes! :)