Thread: Experimental APIs for FGU
-
January 16th, 2021, 21:08 #1
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 21,622
Experimental APIs for FGU
As part of v4.0.7; I've actually embedded quite a few new APIs that I'm testing out to see how useful they are; as well as to make sure that the API calls are in the right formats that are needed as well as to sound out issues with the new APIs. These APIs may change in the near term based on feedback, and I'll post here if I do. So, if you plan to look at using these, make sure to subscribe to this thread.
And here they are:
imagecontrol
getTokensWithinDistance(token/{x=#,y=#}, #) -> (table of tokens)
getDistanceBetween(token/{x=#,y=#}, token/{x=#,y=#}) -> (number/nil)
File (new global package)
addCampaignAssetFile(path, type) -> (string/nil)
getCampaignFolder() -> (string)
getDataFolder() -> (string)
openCampaignFolder([subpath])
openDataFolder([subpath])
openTextFile(path) -> (string/nil)
saveTextFile(path, string)
Token
getTokensWithinDistance(token, #) -> (table of tokens)
getDistanceBetween(token, token) -> (number/nil)
Utility (new global package)
decodeXML(string) -> (table)
encodeXML(table, [bool]) -> (string)
Regards,
JPGLast edited by Moon Wizard; January 27th, 2021 at 21:51.
-
January 25th, 2021, 22:56 #2
- Join Date
- Mar 2020
- Posts
- 43
Thanks Moon Wizard! I just gave Token.getDistanceBetween() a shot, and I love how it returns usable values in ruleset units instead of the pixels or whatever they were that getPosition() returns. I was trying to figure out how to convert for ChatBat. I'll be using that for sure.
-
January 27th, 2021, 18:17 #3
Oh wow, so will this import Hero Labs Online?
-
January 27th, 2021, 18:23 #4
I can see these being pretty useful. Not planning on making any more extensions at the moment, but you never know what will trigger one as my own campaign progresses. I can see these being handy enough (plus any future ones - maybe with lighting?) that I will need to track this thread in case I want to incorporate new stuff into my existing extensions or make a new one.
Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
January 27th, 2021, 20:47 #5---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset FGU Reference Module, or Web.
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.
-
January 27th, 2021, 21:11 #6
I ran a few tests to figure out how to use these, "Utility" seems to be valid? Utility.encodeXML()
The test was this:
Code:msgOOB.jsonDice = JSON.encode(aDice or ""); Debug.console("manager_action_damage.lua","notifyApplyDamage","aDice---->",aDice); Debug.console("manager_action_damage.lua","notifyApplyDamage","msgOOB.jsonDice---->",msgOOB.jsonDice); if UtilityManagerADND.isFGU() then Debug.console("manager_action_damage.lua","notifyApplyDamage","encodeXML()",Utility.encodeXML(aDice)); end
Code:[1/27/2021 2:07:39 PM] s'manager_action_damage.lua' | s'notifyApplyDamage' | s'aDice---->' | { #1 = { s'value' = #1, s'type' = s'd3', s'result' = #1 }, s'expr' = s'd3' } [1/27/2021 2:07:39 PM] s'manager_action_damage.lua' | s'notifyApplyDamage' | s'msgOOB.jsonDice---->' | s'{"1":{"value":1, "type":"d3", "result":1}, "expr":"d3"}' [1/27/2021 2:07:39 PM] s'manager_action_damage.lua' | s'notifyApplyDamage' | s'encodeXML()' | s'<?xml version="1.0" encoding="utf-8"?>'
---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset FGU Reference Module, or Web.
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.
-
January 27th, 2021, 21:47 #7
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 21,622
What is in aDice?
EDIT: Nevermind, I see it in your code output
JPGLast edited by Moon Wizard; January 27th, 2021 at 21:52.
-
January 27th, 2021, 21:48 #8
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 21,622
The encode/decode XML is very specifically to encode/decode between XML and Lua tables. I do not expect it to match to JSON encoding/decoding.
JPG
-
January 27th, 2021, 22:18 #9---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset FGU Reference Module, or Web.
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.
-
January 27th, 2021, 22:20 #10
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 21,622
Just to clarify, there is a very specific format that the encoding supports for Lua tables in order to allow bi-directional translation of data. It's not meant (at least at this point) to be some sort of general purpose convert "any" Lua table to XML. It could be something to enhance later.
Within the table, all XML child tags are referred to by number indicating their child sibling order pointing to a table that must include a "name" variable. This is the XML "tag". You can also specify an "attr" table for the tag, as well a numerical children. This is to deal with the fact that XML child tags can have the same name; mirrors the format used for controls to access XML tags; and matches up with a common Lua library used for XML processing.
Here's an example:
XML
Code:<?xml version="1.0" encoding="utf-8"?> <root version="4" dataversion="20201016" release="4.1"> <character> <name type="string">Bobby</name> <token type="token">portrait_id-00002_token</token> <coins> <slot1> <amount type="number">0</amount> </slot1> <slot2> <amount type="number">0</amount> </slot2> <slot3> <amount type="number">0</amount> </slot3> <slot4> <amount type="number">0</amount> </slot4> <slot5> <amount type="number">0</amount> </slot5> <slot6> <amount type="number">0</amount> </slot6> </coins> </character> </root>
Code:{ 1 = { name = "root", attr = { release = "4.1", dataversion = "20201016", version = "4"} 1 = { name = "character", 1 = { name = "name", attr = { type = "string" }, 1 = "Bobby", }, 2 = { name = "token", attr = { type = "token" }, 1 = "portrait_id-00002_token", }, 3 = { name = "coins", 1 = { name = "slot1", 1 = { name = "amount", attr = { type = "number" }, 1 = "0", }, }, 2 = { name = "slot2", 1 = { name = "amount", attr = { type = "number" }, 1 = "0", }, }, 3 = { name = "slot3", 1 = { name = "amount", attr = { type = "number" }, 1 = "0", }, }, 4 = { name = "slot4", 1 = { name = "amount", attr = { type = "number" }, 1 = "0", }, }, 5 = { name = "slot5", 1 = { name = "amount", attr = { type = "number" }, 1 = "0", }, }, 6 = { name = "slot6", 1 = { name = "amount", attr = { type = "number" }, 1 = "0", }, }, }, }, }, }
JPG
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks