1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 18:19:43 +01:00

Convert editorclass::save() to TinyXML2

I tested this one, too. But it seems to be fine as well.
This commit is contained in:
Misa 2020-06-03 18:12:12 -07:00 committed by Ethan Lee
parent cfacc7a2dc
commit 89a8623a46

View file

@ -11,6 +11,7 @@
#include "time.h" #include "time.h"
#include "tinyxml.h" #include "tinyxml.h"
#include "tinyxml2.h"
#include "Enums.h" #include "Enums.h"
@ -1897,23 +1898,22 @@ bool editorclass::load(std::string& _path)
bool editorclass::save(std::string& _path) bool editorclass::save(std::string& _path)
{ {
TiXmlDocument doc; tinyxml2::XMLDocument doc;
TiXmlElement* msg; tinyxml2::XMLElement* msg;
TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" ); tinyxml2::XMLDeclaration* decl = doc.NewDeclaration();
doc.LinkEndChild( decl ); doc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "MapData" ); tinyxml2::XMLElement * root = doc.NewElement( "MapData" );
root->SetAttribute("version",version); root->SetAttribute("version",version);
doc.LinkEndChild( root ); doc.LinkEndChild( root );
TiXmlComment * comment = new TiXmlComment(); tinyxml2::XMLComment * comment = doc.NewComment(" Save file " );
comment->SetValue(" Save file " );
root->LinkEndChild( comment ); root->LinkEndChild( comment );
TiXmlElement * data = new TiXmlElement( "Data" ); tinyxml2::XMLElement * data = doc.NewElement( "Data" );
root->LinkEndChild( data ); root->LinkEndChild( data );
msg = new TiXmlElement( "MetaData" ); msg = doc.NewElement( "MetaData" );
time_t rawtime; time_t rawtime;
struct tm * timeinfo; struct tm * timeinfo;
@ -1930,54 +1930,54 @@ bool editorclass::save(std::string& _path)
} }
//getUser //getUser
TiXmlElement* meta = new TiXmlElement( "Creator" ); tinyxml2::XMLElement* meta = doc.NewElement( "Creator" );
meta->LinkEndChild( new TiXmlText( EditorData::GetInstance().creator.c_str() )); meta->LinkEndChild( doc.NewText( EditorData::GetInstance().creator.c_str() ));
msg->LinkEndChild( meta ); msg->LinkEndChild( meta );
meta = new TiXmlElement( "Title" ); meta = doc.NewElement( "Title" );
meta->LinkEndChild( new TiXmlText( EditorData::GetInstance().title.c_str() )); meta->LinkEndChild( doc.NewText( EditorData::GetInstance().title.c_str() ));
msg->LinkEndChild( meta ); msg->LinkEndChild( meta );
meta = new TiXmlElement( "Created" ); meta = doc.NewElement( "Created" );
meta->LinkEndChild( new TiXmlText( help.String(version).c_str() )); meta->LinkEndChild( doc.NewText( help.String(version).c_str() ));
msg->LinkEndChild( meta ); msg->LinkEndChild( meta );
meta = new TiXmlElement( "Modified" ); meta = doc.NewElement( "Modified" );
meta->LinkEndChild( new TiXmlText( EditorData::GetInstance().modifier.c_str() ) ); meta->LinkEndChild( doc.NewText( EditorData::GetInstance().modifier.c_str() ) );
msg->LinkEndChild( meta ); msg->LinkEndChild( meta );
meta = new TiXmlElement( "Modifiers" ); meta = doc.NewElement( "Modifiers" );
meta->LinkEndChild( new TiXmlText( help.String(version).c_str() )); meta->LinkEndChild( doc.NewText( help.String(version).c_str() ));
msg->LinkEndChild( meta ); msg->LinkEndChild( meta );
meta = new TiXmlElement( "Desc1" ); meta = doc.NewElement( "Desc1" );
meta->LinkEndChild( new TiXmlText( Desc1.c_str() )); meta->LinkEndChild( doc.NewText( Desc1.c_str() ));
msg->LinkEndChild( meta ); msg->LinkEndChild( meta );
meta = new TiXmlElement( "Desc2" ); meta = doc.NewElement( "Desc2" );
meta->LinkEndChild( new TiXmlText( Desc2.c_str() )); meta->LinkEndChild( doc.NewText( Desc2.c_str() ));
msg->LinkEndChild( meta ); msg->LinkEndChild( meta );
meta = new TiXmlElement( "Desc3" ); meta = doc.NewElement( "Desc3" );
meta->LinkEndChild( new TiXmlText( Desc3.c_str() )); meta->LinkEndChild( doc.NewText( Desc3.c_str() ));
msg->LinkEndChild( meta ); msg->LinkEndChild( meta );
meta = new TiXmlElement( "website" ); meta = doc.NewElement( "website" );
meta->LinkEndChild( new TiXmlText( website.c_str() )); meta->LinkEndChild( doc.NewText( website.c_str() ));
msg->LinkEndChild( meta ); msg->LinkEndChild( meta );
data->LinkEndChild( msg ); data->LinkEndChild( msg );
msg = new TiXmlElement( "mapwidth" ); msg = doc.NewElement( "mapwidth" );
msg->LinkEndChild( new TiXmlText( help.String(mapwidth).c_str() )); msg->LinkEndChild( doc.NewText( help.String(mapwidth).c_str() ));
data->LinkEndChild( msg ); data->LinkEndChild( msg );
msg = new TiXmlElement( "mapheight" ); msg = doc.NewElement( "mapheight" );
msg->LinkEndChild( new TiXmlText( help.String(mapheight).c_str() )); msg->LinkEndChild( doc.NewText( help.String(mapheight).c_str() ));
data->LinkEndChild( msg ); data->LinkEndChild( msg );
msg = new TiXmlElement( "levmusic" ); msg = doc.NewElement( "levmusic" );
msg->LinkEndChild( new TiXmlText( help.String(levmusic).c_str() )); msg->LinkEndChild( doc.NewText( help.String(levmusic).c_str() ));
data->LinkEndChild( msg ); data->LinkEndChild( msg );
//New save format //New save format
@ -1989,15 +1989,15 @@ bool editorclass::save(std::string& _path)
contentsString += help.String(contents[x + (maxwidth*40*y)]) + ","; contentsString += help.String(contents[x + (maxwidth*40*y)]) + ",";
} }
} }
msg = new TiXmlElement( "contents" ); msg = doc.NewElement( "contents" );
msg->LinkEndChild( new TiXmlText( contentsString.c_str() )); msg->LinkEndChild( doc.NewText( contentsString.c_str() ));
data->LinkEndChild( msg ); data->LinkEndChild( msg );
msg = new TiXmlElement( "edEntities" ); msg = doc.NewElement( "edEntities" );
for(size_t i = 0; i < edentity.size(); i++) for(size_t i = 0; i < edentity.size(); i++)
{ {
TiXmlElement *edentityElement = new TiXmlElement( "edentity" ); tinyxml2::XMLElement *edentityElement = doc.NewElement( "edentity" );
edentityElement->SetAttribute( "x", edentity[i].x); edentityElement->SetAttribute( "x", edentity[i].x);
edentityElement->SetAttribute( "y", edentity[i].y); edentityElement->SetAttribute( "y", edentity[i].y);
edentityElement->SetAttribute( "t", edentity[i].t); edentityElement->SetAttribute( "t", edentity[i].t);
@ -2007,16 +2007,16 @@ bool editorclass::save(std::string& _path)
edentityElement->SetAttribute( "p4", edentity[i].p4); edentityElement->SetAttribute( "p4", edentity[i].p4);
edentityElement->SetAttribute( "p5", edentity[i].p5); edentityElement->SetAttribute( "p5", edentity[i].p5);
edentityElement->SetAttribute( "p6", edentity[i].p6); edentityElement->SetAttribute( "p6", edentity[i].p6);
edentityElement->LinkEndChild( new TiXmlText( edentity[i].scriptname.c_str() )) ; edentityElement->LinkEndChild( doc.NewText( edentity[i].scriptname.c_str() )) ;
msg->LinkEndChild( edentityElement ); msg->LinkEndChild( edentityElement );
} }
data->LinkEndChild( msg ); data->LinkEndChild( msg );
msg = new TiXmlElement( "levelMetaData" ); msg = doc.NewElement( "levelMetaData" );
for(int i = 0; i < 400; i++) for(int i = 0; i < 400; i++)
{ {
TiXmlElement *edlevelclassElement = new TiXmlElement( "edLevelClass" ); tinyxml2::XMLElement *edlevelclassElement = doc.NewElement( "edLevelClass" );
edlevelclassElement->SetAttribute( "tileset", level[i].tileset); edlevelclassElement->SetAttribute( "tileset", level[i].tileset);
edlevelclassElement->SetAttribute( "tilecol", level[i].tilecol); edlevelclassElement->SetAttribute( "tilecol", level[i].tilecol);
edlevelclassElement->SetAttribute( "platx1", level[i].platx1); edlevelclassElement->SetAttribute( "platx1", level[i].platx1);
@ -2032,7 +2032,7 @@ bool editorclass::save(std::string& _path)
edlevelclassElement->SetAttribute( "directmode", level[i].directmode); edlevelclassElement->SetAttribute( "directmode", level[i].directmode);
edlevelclassElement->SetAttribute( "warpdir", level[i].warpdir); edlevelclassElement->SetAttribute( "warpdir", level[i].warpdir);
edlevelclassElement->LinkEndChild( new TiXmlText( level[i].roomname.c_str() )) ; edlevelclassElement->LinkEndChild( doc.NewText( level[i].roomname.c_str() )) ;
msg->LinkEndChild( edlevelclassElement ); msg->LinkEndChild( edlevelclassElement );
} }
data->LinkEndChild( msg ); data->LinkEndChild( msg );
@ -2048,11 +2048,11 @@ bool editorclass::save(std::string& _path)
scriptString += script_.contents[i] + "|"; scriptString += script_.contents[i] + "|";
} }
} }
msg = new TiXmlElement( "script" ); msg = doc.NewElement( "script" );
msg->LinkEndChild( new TiXmlText( scriptString.c_str() )); msg->LinkEndChild( doc.NewText( scriptString.c_str() ));
data->LinkEndChild( msg ); data->LinkEndChild( msg );
return FILESYSTEM_saveTiXmlDocument(("levels/" + _path).c_str(), &doc); return FILESYSTEM_saveTiXml2Document(("levels/" + _path).c_str(), doc);
} }