Starfinder Playlist
  1. #1

    Overridden onDoubleClick still calling CoreRPG onDoubleClick

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

  2. #2
    Return true/false. True should block the super.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  3. #3
    Quote Originally Posted by celestian View Post
    Return true/false. True should block the super.
    I tried that, but it had no effect.

  4. #4
    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

  5. #5
    Quote Originally Posted by Moon Wizard View Post
    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?

  6. #6
    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.
    Last edited by Moon Wizard; January 18th, 2022 at 22:28.

  7. #7
    Okay, thanks.

    Quote Originally Posted by Moon Wizard View Post
    but extension writers do some crazy stuff...
    We have to keep you on your toes!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Product Walkthrough Playlist

Log in

Log in