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?
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?