PDA

View Full Version : Do onUpdate and onChildUpdate work for formattedtext nodes?



Baoghal
October 22nd, 2020, 19:36
I am coding an extension for Fantasy Grounds (Classic, but I don't think the difference matters for this issue) that sits atop the GURPS ruleset, which is in turn based upon the CoreRPG ruleset. I am trying to detect changes on a formattedtext node contained within various objects contained within list nodes, e.g.:


function onInit()
DB.addHandler("charsheet.*.abilities.skilllist.*", "onChildUpdate", onSkillUpdooted);
end

function onSkillUpdooted(nSkill)
ChatManager.SystemMessage("Aww yiss, I caught an update!");
end

My data's structure in db.xml looks something like this:


<root>
<charsheet>
<id-00001>
<abilities>
<skilllist>
<id-00001>
<!-- buncha nodes -->
<text type="formattedtext">
<h>Butt-Kicking (DX/VH)</h>
<p>Its dangerous to go alone, take this skill with you</p>
<linklist>
<!-- links are here -->
</linklist>
</text>
<!-- moar nodes -->

I pick up changes to all the other nodes in the skilllist item, as one might expect. Since the structure of the data seems to indicate that the formattedtext node is a list of "runs" then I thought this would solve my problem:



function onInit()
DB.addHandler("charsheet.*.abilities.skilllist.*", "onChildUpdate", onSkillUpdooted);
DB.addHandler("charsheet.*.abilities.skilllist.*.text.*", "onChildUpdate", onSkillTextUpdooted);
end

function onSkillUpdooted(nSkill)
ChatManager.SystemMessage("Aww yiss, I caught an update!");
end

function onSkillTextUpdooted(nUpdatedRun)
ChatManager.SystemMessage("Tarnation! This never fires! Whyyyyyyy?");
end

FWIW I also tried picking up changes like this, because I like playing Battleship...


DB.addHandler("charsheet.*.abilities.skilllist.*.text", "onUpdate", onTheOffChanceThisWorks);
DB.addHandler("charsheet.*.abilities.skilllist.*.text", "onChildUpdate", onTheOffChanceThisWorks);
DB.addHandler("charsheet.*.abilities.skilllist.*.text.*", "onUpdate", onTheOffChanceThisWorks);

Anyone have any secrets about how I can pickup changes in that node? Or am I just going to be sad and make people press a magic button to get the text to be parsed again when it changes.

superteddy57
October 22nd, 2020, 21:15
function onInit()
DB.addHandler("charsheet.*.abilities.skilllist.*", "onChildUpdate", onSkillUpdooted);
DB.addHandler("charsheet.*.abilities.skilllist.*.text", "onUpdate", onSkillTextUpdooted);
end

Have you tried it this way instead?

Edit: I see that was one of the options. The one I have bold should do the trick. Since text doesn't have a child node the onChildUpdate won't work directly with the text node. The best location for onChildUpdate would be with the "charsheet.*.abilities.skilllist.*" set you showed. Since this has child nodes it will 'listen' to when these are changed and fire the script. I'm not sure if this is directly related to it being a formattedtext element or not, but might be as I never really have attempted to listen for changes in a formattedtext element.

Baoghal
October 22nd, 2020, 22:58
I have attempted your suggestion and failed successfully :(

This page (it might no longer be valid) mentions that it is not bound to a database node.
https://www.fantasygrounds.com/refdoc/formattedtextcontrol.xcp

I can almost hear Adam Savage in the background saying "Well, there's your problem!"

I did do some rigging to see if the node was being updated at runtime (by capturing the parent (skill) node and calling a getText() on its "text" node. It's definitely getting pushed to the DB, I'm just straight up not getting notified about it.

Having this work isn't a "must have" to pull off what I am trying to do, but it would be a lot cooler if it did. ;)

Trenloe
October 23rd, 2020, 09:50
This page (it might no longer be valid) mentions that it is not bound to a database node.
https://www.fantasygrounds.com/refdoc/formattedtextcontrol.xcp
That is still correct.

A "control" is not linked to database data, but a "field" is. This is a key piece of FG terminology. So, the formatted text "field" is what stores data in the database: https://www.fantasygrounds.com/refdoc/formattedtextfield.xcp

That probably doesn’t address your issue, but it hopefully explains some terminology and the documentation.

Baoghal
October 23rd, 2020, 11:30
Thank you for the clarification. As for this issue, is there another place where I should leave a bug report for it? I also have FGU, but I haven't moved my work over to it to see if the bug is there too.

Moon Wizard
October 23rd, 2020, 21:12
I just investigated this. It will work in FGU, but not FGC.

It was by design in FGC by the original developers (before my time) based on the way formatted text fields are implemented and dealing with performance. With FGU, it was completely rebuilt, and the proposed solution will work (in FGU only). Unfortunately, there is no easy way to make this work in FGC without rewriting whole portions of formatted text fields; and there are no plans to spend that much development time on FGC given FGU work.

The workaround is to use the onValueChanged event in the formattedtextcontrol/formattedtextfield to capture the changes; and apply whatever actions you want.

Regards,
JPG

Baoghal
October 24th, 2020, 12:35
Ah ha! Thank you! It's almost time to move, then :)