PDA

View Full Version : "extra" node is being created and can't see why....



celestian
August 4th, 2017, 02:21
So in my quest to add a stupid amount of tables I added a feature to be able to import text and create a table from that. Right now it's pretty basic and each line is a entry in the table. Works as I expect BUT...When I click on the button to get the initial window to pop up something is creating a "<<New Table>>" and it's at least not the lua code I wrote. I suspect it's something I'm not familiar with on how FG handles things.

I've set several debug points and watched and it wasn't my lua code adding the initial entry so it's gotta be something... elsewhere? My suspicion is it's in the template (listed first) where I bolded the line but I'm clueless what I can do to fix it.

Here is the code. Forgive me I figured I'd post it all so I wouldn't make any assumptions.

Template for table jiggery pokery...


<template name="button_import_table">
<buttoncontrol insertbefore="filter_sharedonly">
<anchored to="rightanchor" width="20" height="20">
<top />
<right anchor="left" relation="relative" offset="-5" />
</anchored>
<icon normal="button_importtext_table" pressed="button_importtext_table_down" />
<tooltip textres="table_button_import_tooltip" />
<script>
function onButtonPress()
if User.isHost() then
Interface.openWindow("table_import_window", window.getDatabaseNode());
end
end
</script>
<invisible />
</buttoncontrol>
</template>



Tweaked "table" entry in aRecords



["table"] = {
bExport = true,
aDataMap = { "tables", "reference.tables" },
aDisplayIcon = { "button_tables", "button_tables_down" },
-- sRecordDisplayClass = "table",
aGMEditButtons = { "button_add_table_guided","button_import_table" };
},



Window and subwindow code to pop up window and prompt for text.



<root>
<windowclass name="table_import_window">
<frame>charsheethelper</frame>
<placement>
<size width="220" height="200" />
</placement>
<sizelimits>
<minimum width="220" height="200" />
<dynamic />
</sizelimits>
<sheetdata>
<windowtitlebar_char name="title">
<prefix>table_import_window_title</prefix>
</windowtitlebar_char>
<anchor_title_charsheethelper name="contentanchor" />
<subwindow name="contents">
<anchored>
<top offset="0" />
<bottom offset="-30" />
<left offset="0" />
<right offset="-15" />
</anchored>
<class>table_import_contents</class>
<activate />
<fastinit />
</subwindow>
<scrollbar_charcontents />
<buttoncontrol name="importbutton">
<anchored to="contents" position="below" offset="0,-10" height="20" />
<icon normal="button_dialog_check_red" pressed="button_dialog_ok" />
<script>
function onButtonPress(x, y)
window.contents.subwindow.importTextAsTable();
window.contents.subwindow.tableimporttext.setValue ("");
window.close();
end
</script>
</buttoncontrol>
<label_fieldtop name="label_importtext_button">
<anchored to="importbutton" />
<static textres="table_import_text_button" />
</label_fieldtop>

<close>
<anchored>
<top offset="24" />
<right offset="0" />
</anchored>
</close>
<resize>
<anchored>
<right offset="-12" />
<bottom offset="-14" />
</anchored>
</resize>

</sheetdata>
</windowclass>

<windowclass name="table_import_contents">
<margins control="15,15,15,15" />
<script file="campaign/scripts/table_import.lua" />
<sheetdata>

<anchor_column name="columnanchor" />
<anchor_left />
<anchor_right />


<label_charframetop>
<anchored>
<top parent="columnanchor" anchor="bottom" relation="relative" offset="50" />
<left parent="leftanchor" anchor="right" relation="relative" offset="5" />
<!-- <right parent="rightanchor" anchor="left" relation="relative" offset="35" /> -->
<right />
</anchored>
<multilinespacing>20</multilinespacing>
<static textres="table_import_text_helptext" />
</label_charframetop>

<label_charframetop name="importtabletitle">
<anchored height="20">
<top parent="columnanchor" anchor="bottom" relation="relative" offset="5" />
<left />
<right />
</anchored>
<static textres="table_import_text_title" />
</label_charframetop>
<stringu name="tableimporttext">
<anchored>
<top parent="columnanchor" anchor="bottom" relation="relative" offset="5" />
<left offset="15" />
<right offset="-10" />
</anchored>
<multilinespacing>20</multilinespacing>
</stringu>
<scrollbar>
<anchored to="tableimporttext" offset="-5,-10"/>
<target>tableimporttext</target>
</scrollbar>
</sheetdata>
</windowclass>
</root>




Lua code to handle all the buttons/suck in the text, parse it and deal with making the table/rows/etc.



function onInit()
--Debug.console("table_import.lua","onInit","window.getDatabaseNode",window.getDatabaseNode());
Debug.console("table_import.lua","onInit","getDatabaseNode",getDatabaseNode());
end


function createBlankTable()
local node = getDatabaseNode().createChild();
--Debug.console("table_import.lua","createTable","node",node);

if node then
local w = Interface.openWindow("table", node.getNodeName());
--TableManager.createRows(node, nRows, nStep, bSpecial);
if w and w.name then
w.name.setFocus();
end
end
return node;
end

function importTextAsTable()
local sText = tableimporttext.getValue() or "";

--Debug.console("table_import.lua","importTextAsTable","sText",sText);

if (sText ~= "") then
local aTableText = {};
for sLine in string.gmatch(sText, '([^\r\n]+)') do
table.insert(aTableText, sLine);
--Debug.console("table_import.lua","importTextAsTable","sLine",sLine);

end

local nodeTable = createBlankTable();
local nNewRow = 0;
if (nodeTable) then
--Debug.console("table_import.lua","importTextAsTable","nodeTable",nodeTable);
local nodeTableRows = nodeTable.createChild("tablerows");
--Debug.console("table_import.lua","importTextAsTable","nodeTableRows",nodeTableRows);
for _,sTableLines in ipairs(aTableText) do
nNewRow = nNewRow + 1;
--Debug.console("table_import.lua","importTextAsTable","sTableLines",sTableLines);
local nodeRow = nodeTableRows.createChild();
DB.setValue(nodeRow, "fromrange", "number", nNewRow);
DB.setValue(nodeRow, "torange", "number", nNewRow);
local nodeResults = nodeRow.createChild("results");
local nodeResult = nodeResults.createChild();
DB.setValue(nodeResult, "result", "string", sTableLines);
end
end
end
end



Here is a screenshot, at this point ALL I did was click on the "edit" pen to get the extended menus up then clicked the blue import button to bring up the window. Nothing more. I didn't paste text into the window and click the red check/import.

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

Apologies if this is information overload.

Trenloe
August 4th, 2017, 03:17
Windows have to be anchored to a database node unless they are unbound - see info here: https://www.fantasygrounds.com/refdoc/windowinstance.xcp

Interface.openWindow (https://www.fantasygrounds.com/refdoc/Interface.xcp#openWindow)("table_import_window", window.getDatabaseNode()); includes a database node, and as the one provided is the base <tables> node from the tables list (Iwindow.getDatabaseNode()), FG creates a new blank, database node. Hence why you're seeing the default labelling for a new table, which is set in the CoreRPG "table_header" windowclass under the <empty textres="library_recordtype_empty_table" /> parameter.

Create an unbound window with Interface.openWindow("table_import_window", ""); and take it from there. I haven't gone through the rest of your code to see what you'll have to change to take the unbound window into account (I'm guessing createBlankTable will need to be more specific with where it gets the database node from, and maybe in other places).

EDIT: Replacing local node = getDatabaseNode().createChild(); with local node = DB.createChild("tables"); in the createBlankTable function should be enough to get you started with a new table node when you create the new blank table to import data into. https://www.fantasygrounds.com/refdoc/DB.xcp#createChild

celestian
August 4th, 2017, 03:44
Windows have to be anchored to a database node unless they are unbound - see info here: https://www.fantasygrounds.com/refdoc/windowinstance.xcp

Interface.openWindow (https://www.fantasygrounds.com/refdoc/Interface.xcp#openWindow)("table_import_window", window.getDatabaseNode()); includes a database node, and as the one provided is the base <tables> node from the tables list (Iwindow.getDatabaseNode()), FG creates a new blank, database node. Hence why you're seeing the default labelling for a new table, which is set in the CoreRPG "table_header" windowclass under the <empty textres="library_recordtype_empty_table" /> parameter.

Create an unbound window with Interface.openWindow("table_import_window", ""); and take it from there. I haven't gone through the rest of your code to see what you'll have to change to take the unbound window into account (I'm guessing createBlankTable will need to be more specific with where it gets the database node from, and maybe in other places).

EDIT: Replacing local node = getDatabaseNode().createChild(); with local node = DB.createChild("tables"); in the createBlankTable function should be enough to get you started with a new table node when you create the new blank table to import data into. https://www.fantasygrounds.com/refdoc/DB.xcp#createChild

Dead on with the assessment. I've corrected the mentioned bits and works without the extra node now! Thanks ;)

I knew it had something to do with some tricky bit I was missing somewhere. I kept floating around the openWindow docs/page trying to figure out what I was missing. I even set it to the datasource to "" at one point but didn't click I needed to create the child using the method you mentioned.

At some point I'll make this an extension for CoreRPG but I've got a few other things I'd like to add to it (columns) first.

Thanks for the assist and information, most appreciated.