MeepoSose
October 8th, 2009, 15:55
This is mostly for Foen I suppose. I am crashing and getting a corrupt db.xml after using it.
I plugged in your CopyNode() function into a global utility file and used it successfully (at first) to copy items from the item screen to the character sheet inventory screen. I've customized the items fairly heavily, but at first glance it seems to work. When the campaigns saves, however, the program crashes and the db.xml file gets corrupted. It just ends abruptly somewhere in the middle of the character record.
Here is the latest version I am using (with comments and console print statements added in for debug purposes):
-- provided courtesy of Foen on the Fantasy Grounds Forums
function copyNode(source, targetlist, rename)
-- creates a copy of the source node in the target list
print("copyNode() called");
local nodeType = source.getType();
if nodeType=="number" or nodeType=="string" or nodeType=="image" or nodeType=="dice" or nodeType=="windowreference" then
local newnode = targetlist.createChild(source.getName(),nodeType). setValue(source.getValue());
return newnode;
end
-- copying formattedtext isn't supported
if nodeType=="formattedtext" then
print("copyNode: formattedtext");
-- create the node but don't bother trying to populate it
local newnode = targetlist.createChild(source.getName(),nodeType);
return newnode;
end
-- unknown value?
if nodeType~="node" then
-- don't create anything. Should perhaps throw an error
return nil;
end
-- must be a complex node, we need to repeat the process on all child nodes.
local newlist;
if rename then
print("copyNode: rename");
newlist = targetlist.createChild();
else
print("copyNode: rename = false");
newlist = targetlist.createChild(source.getName());
end
for k,subnode in pairs(source.getChildren()) do
print("copyNode: copying children (with rename)");
copyNode(subnode,newlist,true);
end
return newlist;
-- done
end
Before the save occurs, the items copy over and I can click on the shortcut to open it up and modify any fields. I can copy several items without problems and the items are true copies. They update independently from that point on -- exactly like I want.
Here is the code which calls it from charsheet_inventorylist.lua. The type is "shortcut".
function addItem(source)
-- Parameter validation
if not source then
return nil;
end
local list = window.getDatabaseNode().createChild("inventorylist");
local newnode = Utility.copyNode(source,list,true);
if newnode then
newnode.createChild("shortcut","windowreference").setValue("item");
end
return true;
end
function onDrop(x, y, draginfo)
if draginfo.isType("item") then
print("item");
local source = draginfo.getDatabaseNode();
local newentry = addItem(source);
return true;
elseif draginfo.isType("shortcut") then
print("item shortcut");
local class, datasource = draginfo.getShortcutData();
local source = draginfo.getDatabaseNode();
if class == "item" then
local newentry = addItem(source);
print("shortcut to item class type dropped");
end
return true;
else
print(draginfo.getType());
end
end
The problem is reproducible. I can create new items manually in the character inventory and call a /save with no problems. It is only after dragging and dropping one or more items and calling /save (or allowing it to occur on the timer) that I get the crashes.
I plugged in your CopyNode() function into a global utility file and used it successfully (at first) to copy items from the item screen to the character sheet inventory screen. I've customized the items fairly heavily, but at first glance it seems to work. When the campaigns saves, however, the program crashes and the db.xml file gets corrupted. It just ends abruptly somewhere in the middle of the character record.
Here is the latest version I am using (with comments and console print statements added in for debug purposes):
-- provided courtesy of Foen on the Fantasy Grounds Forums
function copyNode(source, targetlist, rename)
-- creates a copy of the source node in the target list
print("copyNode() called");
local nodeType = source.getType();
if nodeType=="number" or nodeType=="string" or nodeType=="image" or nodeType=="dice" or nodeType=="windowreference" then
local newnode = targetlist.createChild(source.getName(),nodeType). setValue(source.getValue());
return newnode;
end
-- copying formattedtext isn't supported
if nodeType=="formattedtext" then
print("copyNode: formattedtext");
-- create the node but don't bother trying to populate it
local newnode = targetlist.createChild(source.getName(),nodeType);
return newnode;
end
-- unknown value?
if nodeType~="node" then
-- don't create anything. Should perhaps throw an error
return nil;
end
-- must be a complex node, we need to repeat the process on all child nodes.
local newlist;
if rename then
print("copyNode: rename");
newlist = targetlist.createChild();
else
print("copyNode: rename = false");
newlist = targetlist.createChild(source.getName());
end
for k,subnode in pairs(source.getChildren()) do
print("copyNode: copying children (with rename)");
copyNode(subnode,newlist,true);
end
return newlist;
-- done
end
Before the save occurs, the items copy over and I can click on the shortcut to open it up and modify any fields. I can copy several items without problems and the items are true copies. They update independently from that point on -- exactly like I want.
Here is the code which calls it from charsheet_inventorylist.lua. The type is "shortcut".
function addItem(source)
-- Parameter validation
if not source then
return nil;
end
local list = window.getDatabaseNode().createChild("inventorylist");
local newnode = Utility.copyNode(source,list,true);
if newnode then
newnode.createChild("shortcut","windowreference").setValue("item");
end
return true;
end
function onDrop(x, y, draginfo)
if draginfo.isType("item") then
print("item");
local source = draginfo.getDatabaseNode();
local newentry = addItem(source);
return true;
elseif draginfo.isType("shortcut") then
print("item shortcut");
local class, datasource = draginfo.getShortcutData();
local source = draginfo.getDatabaseNode();
if class == "item" then
local newentry = addItem(source);
print("shortcut to item class type dropped");
end
return true;
else
print(draginfo.getType());
end
end
The problem is reproducible. I can create new items manually in the character inventory and call a /save with no problems. It is only after dragging and dropping one or more items and calling /save (or allowing it to occur on the timer) that I get the crashes.