PDA

View Full Version : How to get <catagory .*> entries for children?



celestian
January 2nd, 2018, 21:58
So I've been able to get the catagory of a child in a list using UtilityManager.getNodeCategory(node)


local dStories = DB.getChildren("encounter");
for _,node in pairs(dStories) do
local sCategory = UtilityManager.getNodeCategory(node)
Debug.console("manager_author.lua","authorRefmanual-dStories","node",node);
Debug.console("manager_author.lua","authorRefmanual-dStories","sCategory",sCategory);
end


db.xml has the entries like this snippet.



<encounter>
<category name="Cat-2" baseicon="0" decalicon="0">
<id-00001>


However, what I'd like to have is a list of categories instead of a list of the nodes and having to ask each node what category it is. How can you get a list of categories from <encounter> node? Or can you?

I can create my own version of this flipping through every node, checking it's category and then making a new list of nodes with just those specific entries. It would seem that it's kinda backwards though and I'm probably just missing some built in functionality? I also need to ensure I preserve the order that they are in THAT category.

Moon Wizard
January 2nd, 2018, 23:29
Yes, there is. There is a whole set of API calls that I must have forgot to document a while back, but I'll put them on my to do list. I don't have the time to document right now, but the output might be enough to get you what you need.

DB
getCategory (node/path)
setCategory (node/path, categoryname/categorytable)
getChildCategories (node/path)
updateChildCategory (node/path, categoryname/categorytable, usealltrees)
addChildCategory (node/path, categoryname/categorytable)
removeChildCategory (node/path, categoryname/categorytable)
getDefaultChildCategory (node/path)
setDefaultChildCategory (node/path, categoryname/categorytable)

databasenode
getCategory ()
setCategory (categoryname/categorytable)
getChildCategories ()
updateChildCategory (categoryname/categorytable, usealltrees)
addChildCategory (categoryname/categorytable)
removeChildCategory (categoryname/categorytable)
getDefaultChildCategory ()
setDefaultChildCategory (categoryname/categorytable)

Regards,
JPG

celestian
January 3rd, 2018, 00:45
Yes, there is. There is a whole set of API calls that I must have forgot to document a while back, but I'll put them on my to do list. I don't have the time to document right now, but the output might be enough to get you what you need.

DB
getChildCategories (node/path)


Thanks, I'll tinker with it and see what I can come up with. The above one "sounds" like what im looking for. I'll dig around for examples in the code and see if I can sort out how to use it.

For now I've created my own temporary node list by category name.

The reason I'm doing this is so I can take all the "Story" entries, by category and create a reference manual block from them. I'll use the Categories as the sub-chapters with each story record in that category as an entry. This allows the user to edit things in the story editor, using all the formatting tools and what not and then create a ref-manual from it so it looks the same what is does in the story list. I REALLY hate doing ref-manuals by hand ;)

The next part of this will be to prompt much like you do for an export and let you include npc/spells/skills/whatever in the reference manual block.

My proof of concept has worked but there is still a lot to do for final rev... and it would be easier also if I could write/create the needed directory and files (client.xml, definitions.xml/etc) for this. Not sure that's possible yet but for now I simply copy/past the <library> and <reference> block to a client.xml and it works.

This was a sample. I just used some random generation tools to create some Story entries, stuck them in categories and performed the process I mentioned.

https://i.imgur.com/1t4qS33.png

Bidmaron
January 3rd, 2018, 01:02
This looks cool. Is it CoreRPG compatible?

celestian
January 3rd, 2018, 01:40
This looks cool. Is it CoreRPG compatible?

Right now it's just AD&D Core but I don't see why I couldn't create a extension for it for CoreRPG when I'm done. I tend to do my initial work there ;)

celestian
January 3rd, 2018, 03:16
Got a few more things added and decided to try and run it on the builder campaign for S4 and here is what it looked like. Not that I needed the adventure module as a ref manual but mostly to see how it would work. I'm going to fiddle with sorting and see how it'll work on all the story entries I imported for the 10 or so handbooks from Core Rules CD.

https://i.imgur.com/0ML24Id.png

damned
January 3rd, 2018, 03:48
Very nice work celestian.

Myrdin Potter
January 3rd, 2018, 07:24
This is pretty nice work.

Bidmaron
January 3rd, 2018, 12:40
We really need this celestian. I nominate you as a treasure to the community

celestian
January 4th, 2018, 00:58
Sorted out some sorting issues (harhar) and looks pretty decent.

https://i.imgur.com/CuesFBd.png

Doesn't look like I can create directories/files within FG (figured) to write these files but I'll keep poking at it. For now looks like it'll save it to a node in the db.xml and you have to copy/paste that node block into the client.xml for the ref-manual. Once I get a more final version (probably an extension for CoreRPG) I'll write a short instructional (maybe a vid).

Gonna spend sometime to try and figure out the options Moon posted and see if I can get it to work better than my work-a-round of building my own list based on category name.

Bidmaron
January 4th, 2018, 04:13
Actually, you can export to an xml file. Here is some code I am using to export an individual node or set of nodes:


function superExportTabGen(nodeTable,bDoAll)
--given a table or generator node, exports the table or generator to an xml file
--we should include a verification that referenced tables are included also
local sFile=Interface.dialogFileSave( );
if sFile then
local aExports;
if bDoAll then
local sRootMapping=LibraryData.getRootMapping(nodeTable) ;
Debug.chat("nodeTable=",nodeTable,";sRootMapping=",sRootMapping);
local topNode=DB.findNode(sRootMapping);
aExports=DB.getChildren(sRootMapping);
else
aExports={DB.getValue(nodeTable,"name")};
--Debug.chat("aExports[1]=",aExports[1]);
aExports=scanForTables(aExports,DB.getPath(nodeTab le));
end
--Debug.chat("size aExports=",tableSize(aExports));
if DB.findNode("temporary") then
--Debug.chat("deleting temporary");
DB.deleteNode("temporary");
end
DB.createNode("temporary");
local sTopType;
for _,sTab in pairs(aExports) do
local sourceNode;
if type(sTab)=="string" then
sourceNode=TableManager.findTable(sTab);
else
local sTabName=DB.getValue(sTab,"name");
Debug.chat("name=",sTabName);
sourceNode=TableManager.findTable(sTabName);
end
Debug.chat("sTab=",sTab,";sSource=",DB.getPath(sourceNode));
local destNode=DB.createChild("temporary");
Debug.chat("sourceNode=",sourceNode,";destNode=",DB.getPath(destNode));
DB.copyNode(sourceNode,destNode);
if not sTopType then
sTopType=LibraryData.getRecordTypeFromPath(superGe tRecordLevel(sourceNode));
end
Debug.chat("record type=",sTopType);
DB.setValue(destNode,"xyzzy","string",LibraryData.getRecordTypeFromPath(superGetRecordL evel(sourceNode)));
end
DB.export(sFile,"temporary"); --,sTopType,true);
DB.deleteNode("temporary");
end
end --superExportTabGen


Sorry about all the debug code. I have fully tested this, and it can be stripped out

celestian
January 4th, 2018, 05:33
Actually, you can export to an xml file. Here is some code I am using to export an individual node or set of nodes:


Ohhh thanks for the heads up! I was actually trying to use the os level lua calls to do it and hadn't saw Interface.dialogFileSave( ); before.

I can at least write out the client.xml and definition.xml!

(I need to go look at all the interface.* functions!)

edit: also DB.export() ';)

celestian
January 4th, 2018, 07:09
Thanks to your pointers this is what I ended up doing. I didn't want to have to prompt for both files so I just prompted for the client.xml, then chop it off, append the other and write both.



-- prompt for filename to save client.xml to
local sFile = Interface.dialogFileSave( );
if (sFile ~= nil) then
local sDirectory = sFile:match("(.*[/\\])");
-- export the client.xml data to selected file
DB.export(sFile,dAuthorNode.getPath());
-- export definition file in same path/definition
DB.export(sDirectory .. "definition.xml",dDefinitionNode.getPath());

-- show done message
local sFormat = Interface.getString("author_completed");
local sMsg = string.format(sFormat, aProperties.name,sFile);
ChatManager.SystemMessage(sMsg);
file.setFocus(true);
end


Works great, thanks!

Bidmaron
January 4th, 2018, 22:27
Glad to have been of service, Celestian.

Moon Wizard
January 5th, 2018, 05:08
Just added the documentation for these functions to the Ruleset API Reference on the wiki.
https://www.fantasygrounds.com/refdoc/

Cheers,
JPG

damned
January 5th, 2018, 05:14
Just added the documentation for these functions to the Ruleset API Reference on the wiki.
https://www.fantasygrounds.com/refdoc/

Cheers,
JPG

Nice.
Documentation.
The. Best. Part. Of. The. Job!

celestian
January 5th, 2018, 07:08
So here is what I'm looking at currently. Feel free to feed back.

This is a view of the Story records, the author export window and the book I am fiddling with.

"05 Thief Kits and Thieving Skills" is a story entry (you can see it in 03 Chapter 3: Thief Kits" story category. Now look at the book and you'll see "Chapter 3: Thief Kits" and within that a entry for "Thief Kits and Thieving Skills".

I assumed people wouldn't really want the numbers listed. You must have them for the story listing to get the order correctly but once I have them and sorted I can strip it out because the ref-manuals list in order of the entries and since I put them in sorted it doesn't change the order.

The export window will allow you to also select classes/effects/encounters and everything else and it will be placed in the refmanual as those specific records. If you refer to those records in a story you must include them or the links in the ref manual will not work. This goes for "STory" entries as well. So if you link a story within the story you'll need to also export Story records.

Unfortunately I don't think I can make use of the Directory or Thumnail at this time (unless someone knows of a trick to copy a image from a file path to a directory?). So that will need to be done external to FG... The main goal of this is to just make creating the bulk of the refmanual. You'll still need to zip it into a mod when you're complete.

https://i.imgur.com/Otxp0rE.jpg

damned
January 5th, 2018, 13:29
Hi celestian Ive been watching with interest. Am I right in that you are creating content as Story (and other content types) within FG using FG formatting and then using an extension have it copy all that data into a Reference Manual?

Bidmaron
January 5th, 2018, 15:13
Celestian, have you looked at the great implementation in the SW ruleset of this? I have long wondered why no one had duplicated that in CoreRPG.

Bidmaron
January 5th, 2018, 15:17
Unfortunately I don't think I can make use of the Directory or Thumnail at this time (unless someone knows of a trick to copy a image from a file path to a directory?). So that will need to be done external to FG... The main goal of this is to just make creating the bulk of the refmanual. You'll still need to zip it into a mod when you're complete.

https://i.imgur.com/Otxp0rE.jpg
So, you are wanting a thumbnail of the document obviously, but I am not sure what you are looking for on the directory because you should be able to get the directory from the filename you get through the dialog.

celestian
January 5th, 2018, 15:55
Hi celestian Ive been watching with interest. Am I right in that you are creating content as Story (and other content types) within FG using FG formatting and then using an extension have it copy all that data into a Reference Manual?

Correct. The idea is that you build the pages in the Story editor, organize the story pages by categories. Then this will processes those and creates a ref-manual using the story entries organized by story's categories as subchapters.


Celestian, have you looked at the great implementation in the SW ruleset of this? I have long wondered why no one had duplicated that in CoreRPG.

I briefly looked at it but couldn't figure it out how it worked. To be fair I didn't spend a large amount of time. If there is a vid explaining somewhere I'd be happy to look over it and see if it's doing the same thing I want to.


So, you are wanting a thumbnail of the document obviously, but I am not sure what you are looking for on the directory because you should be able to get the directory from the filename you get through the dialog.

Correct, the directory was indeed where I had initially planned to get input from the user. Technically all I need is a directory name and the client.xml and definitions.xml would be dumped there.... but since I can't get the directory the current work around is sufficient. If I could get the current working directory and assume that's FG/data I could then append modules/UserNamedDirectory/client.xml & definitions.xml... but im not sure I can get the local directory with a function within FG.

The thumbnail request is taken from the /export window and works to get the path/etc but the problem is I don't know how to copy and rename that file from that locale to the directory with the xml files within FG. If there is a function to handle this I'd love to hear about it but my google fu has failed me on this if it exists.

Both of those options might be dropped from the list if there is no way to use them.

Bidmaron
January 6th, 2018, 00:06
Hmm. Well, I will have to produce a helper program for my Generators work. It will be a background task that we can communicate with using DOE: Base extension (and I developed a very klugey way to talk back to FG as well, but at least it works. I could fix that so it would respond to a tailored URL to do the image file thing, I suppose. But it will be probably a few weeks before I get to that, as I want to get my Generators extension version 0.1 issued here.

damned
January 6th, 2018, 00:19
Celestian, have you looked at the great implementation in the SW ruleset of this? I have long wondered why no one had duplicated that in CoreRPG.

Hi Bidmaron Im pretty sure that I read a response from Ikael on this subject about how many SW ruleset dependencies were utilized in his tool.

Bidmaron
January 6th, 2018, 02:39
Yes there are several. That is why it is so awesome that celestian is doing this. However, the code methods will probably transfer.