Changed: add channel rgba colors and index order

--HG--
branch : lua
hg/compatibility-develop
Inky 6 years ago
parent fc47b51d23
commit 570c73576c

@ -3996,7 +3996,7 @@ int CLuaIHMRyzom::setArkPowoOptions(CLuaState &ls)
// ***************************************************************************
int CLuaIHMRyzom::readUserChannels(CLuaState &ls)
{
std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
try
{
CIFile fd;
@ -4007,37 +4007,43 @@ int CLuaIHMRyzom::readUserChannels(CLuaState &ls)
xmlKeepBlanksDefault(0);
xmlNodePtr root = stream.getRootNode();
if (!root)
return 0;
if (!root) return 0;
CXMLAutoPtr prop;
// table
ls.newTable();
CLuaObject output(ls);
uint nb = 0;
std::vector< string > tags;
// allowed tags
tags.push_back("id");
tags.push_back("name");
tags.push_back("rgba");
tags.push_back("passwd");
xmlNodePtr node = root->children;
uint nb = 0;
while (node)
{
prop = xmlGetProp(node, (xmlChar*)"name");
if (!prop)
return 0;
std::string name = (const char*)prop;
ls.newTable();
CLuaObject nodeTable(ls);
prop = xmlGetProp(node, (xmlChar*)"passwd");
if (!prop)
return 0;
std::string pass = (const char*)prop;
for (uint i = 0; i < tags.size(); i++)
{
prop = xmlGetProp(node, (xmlChar*)tags[i].c_str());
if (!prop) return 0;
output.setValue(name.c_str(), pass.c_str());
nodeTable.setValue(tags[i].c_str(), (const char *)prop);
}
output.setValue(toString("%i", nb).c_str(), nodeTable);
node = node->next;
nb++;
}
output.push();
// no exception
fd.close();
// release lua table
output.push();
}
nlinfo("parse %s", filename.c_str());
}
@ -4049,7 +4055,6 @@ int CLuaIHMRyzom::readUserChannels(CLuaState &ls)
return 1;
}
// ***************************************************************************
int CLuaIHMRyzom::saveUserChannels(CLuaState &ls)
{
const char *funcName = "saveUserChannels";
@ -4067,7 +4072,7 @@ int CLuaIHMRyzom::saveUserChannels(CLuaState &ls)
CLuaObject params;
params.pop(ls);
std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
try
{
COFile fd;
@ -4080,27 +4085,38 @@ int CLuaIHMRyzom::saveUserChannels(CLuaState &ls)
xmlNodePtr node = xmlNewDocNode(doc, NULL, (const xmlChar*)"interface_config", NULL);
xmlDocSetRootElement(doc, node);
std::string key, value;
ENUM_LUA_TABLE(params, it)
{
if (!it.nextKey().isString())
continue;
if (!it.nextValue().isString())
continue;
if (it.nextKey().type() == LUA_TSTRING)
{
xmlNodePtr newNode = xmlNewChild(node, NULL, (const xmlChar*)"channels", NULL);
if (it.nextValue().type() == LUA_TTABLE)
{
xmlSetProp(newNode, (const xmlChar*)"id", (const xmlChar*)it.nextKey().toString().c_str());
std::string name = it.nextKey().toString();
std::string pass = it.nextValue().toString();
ENUM_LUA_TABLE(it.nextValue(), itt)
{
if (!itt.nextKey().isString())
continue;
if (!itt.nextValue().isString())
continue;
xmlNodePtr newNode = xmlNewChild(node, NULL, (const xmlChar*)"channels", NULL);
xmlSetProp(newNode, (const xmlChar*)"name", (const xmlChar*)name.c_str());
xmlSetProp(newNode, (const xmlChar*)"passwd", (const xmlChar*)pass.c_str());
key = itt.nextKey().toString();
value = itt.nextValue().toString();
xmlSetProp(newNode, (const xmlChar*)key.c_str(), (const xmlChar*)value.c_str());
}
}
}
}
stream.flush();
// no exception
fd.close();
}
nlinfo("save %s", filename.c_str());
if (verbose)
CInterfaceManager::getInstance()->displaySystemInfo("Saving " + filename);
CInterfaceManager::getInstance()->displaySystemInfo("Save " + filename);
}
catch (const Exception &e)
{

Loading…
Cancel
Save