1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-12-25 14:15:46 +00:00

Fix tinyXML2 misuse; simplify scene saving code a little

This commit is contained in:
fgenesis 2014-06-10 02:18:55 +02:00
parent f4302d8313
commit 817d4beb1c
2 changed files with 23 additions and 21 deletions

View file

@ -4247,7 +4247,7 @@ bool Game::loadSceneXML(std::string scene)
l->position = Vector(atoi(lensFlare->Attribute("x")),atoi(lensFlare->Attribute("y"))); l->position = Vector(atoi(lensFlare->Attribute("x")),atoi(lensFlare->Attribute("y")));
addRenderObject(l, LR_LIGHTING); addRenderObject(l, LR_LIGHTING);
XMLElement *lSF = doc.NewElement("LensFlare"); XMLElement *lSF = saveFile->NewElement("LensFlare");
lSF->SetAttribute("inc", lensFlare->Attribute("inc")); lSF->SetAttribute("inc", lensFlare->Attribute("inc"));
lSF->SetAttribute("x", lensFlare->Attribute("x")); lSF->SetAttribute("x", lensFlare->Attribute("x"));
lSF->SetAttribute("y", lensFlare->Attribute("y")); lSF->SetAttribute("y", lensFlare->Attribute("y"));
@ -4262,7 +4262,7 @@ bool Game::loadSceneXML(std::string scene)
XMLElement *level = doc.FirstChildElement("Level"); XMLElement *level = doc.FirstChildElement("Level");
if (level) if (level)
{ {
XMLElement *levelSF = doc.NewElement("Level"); XMLElement *levelSF = saveFile->NewElement("Level");
if (level->Attribute("tileset")) if (level->Attribute("tileset"))
{ {
elementTemplatePack = level->Attribute("tileset"); elementTemplatePack = level->Attribute("tileset");
@ -4595,7 +4595,7 @@ bool Game::loadSceneXML(std::string scene)
XMLElement *quad = doc.FirstChildElement("Quad"); XMLElement *quad = doc.FirstChildElement("Quad");
while (quad) while (quad)
{ {
XMLElement *qSF = doc.NewElement("Quad"); XMLElement *qSF = saveFile->NewElement("Quad");
int x=0, y=0, z=0; int x=0, y=0, z=0;
int w=0,h=0; int w=0,h=0;
bool cull=true; bool cull=true;
@ -4855,7 +4855,7 @@ bool Game::loadSceneXML(std::string scene)
schoolFish = schoolFish->NextSiblingElement("SchoolFish"); schoolFish = schoolFish->NextSiblingElement("SchoolFish");
XMLElement *newSF = doc.NewElement("SchoolFish"); XMLElement *newSF = saveFile->NewElement("SchoolFish");
newSF->SetAttribute("x", x); newSF->SetAttribute("x", x);
newSF->SetAttribute("y", y); newSF->SetAttribute("y", y);
newSF->SetAttribute("id", id); newSF->SetAttribute("id", id);
@ -5308,20 +5308,27 @@ bool Game::saveScene(std::string scene)
std::string fn = getSceneFilename(scene); std::string fn = getSceneFilename(scene);
XMLDocument saveFile;
// hackish: Deep-clone XML doc
{
XMLPrinter printer; XMLPrinter printer;
this->saveFile->Print(&printer); this->saveFile->Print(&printer);
XMLDocument saveFile; XMLError xmlerr = saveFile.Parse(printer.CStr(), printer.CStrSize());
saveFile.Parse(printer.CStr(), printer.CStrSize()); if(xmlerr != XML_SUCCESS)
{
std::ostringstream os;
os << "Game::saveScene(): Whoops? Deep cloning level XML failed: Error " << xmlerr;
errorLog(os.str());
}
}
XMLElement *level = saveFile.FirstChildElement("Level"); XMLElement *level = saveFile.FirstChildElement("Level");
XMLElement *levelLocal = saveFile.NewElement("Level");
bool addIt = false;
if(!level) if(!level)
{ {
level = levelLocal; level = saveFile.NewElement("Level");
addIt = true; saveFile.InsertFirstChild(level);
} }
if (level) if (level)
@ -5348,11 +5355,6 @@ bool Game::saveScene(std::string scene)
} }
} }
if (addIt)
{
saveFile.InsertEndChild(levelLocal);
}
/* /*
XMLElement *level = doc.NewElement("Level"); XMLElement *level = doc.NewElement("Level");
level->SetAttribute("elementTemplatePack", elementTemplatePack); level->SetAttribute("elementTemplatePack", elementTemplatePack);
@ -5500,7 +5502,7 @@ bool Game::saveScene(std::string scene)
} }
*/ */
bool result = saveFile.SaveFile(fn.c_str()); bool result = saveFile.SaveFile(fn.c_str()) == XML_SUCCESS;
if (result) if (result)
debugLog("Successfully saved map: " + fn); debugLog("Successfully saved map: " + fn);
else else

View file

@ -1044,7 +1044,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn)
animations->InsertEndChild(animation); animations->InsertEndChild(animation);
} }
xml->InsertEndChild(animations); xml->InsertEndChild(animations);
return xml->SaveFile(file.c_str()); return xml->SaveFile(file.c_str()) == XML_SUCCESS;
} }
int SkeletalSprite::getBoneIdx(Bone *b) int SkeletalSprite::getBoneIdx(Bone *b)