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

Convert Game::customsavequick() to TinyXML2

At this point I stopped actually doing a quick test, and just went off
of "if it compiles, it works".
This commit is contained in:
Misa 2020-06-03 17:36:27 -07:00 committed by Ethan Lee
parent c03fdc6c01
commit 677dd424ec

View file

@ -6021,19 +6021,18 @@ void Game::savequick()
void Game::customsavequick(std::string savfile) void Game::customsavequick(std::string savfile)
{ {
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( "Save" ); tinyxml2::XMLElement * root = doc.NewElement( "Save" );
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 * msgs = new TiXmlElement( "Data" ); tinyxml2::XMLElement * msgs = doc.NewElement( "Data" );
root->LinkEndChild( msgs ); root->LinkEndChild( msgs );
@ -6044,8 +6043,8 @@ void Game::customsavequick(std::string savfile)
{ {
mapExplored += help.String(map.explored[i]) + ","; mapExplored += help.String(map.explored[i]) + ",";
} }
msg = new TiXmlElement( "worldmap" ); msg = doc.NewElement( "worldmap" );
msg->LinkEndChild( new TiXmlText( mapExplored.c_str() )); msg->LinkEndChild( doc.NewText( mapExplored.c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string flags; std::string flags;
@ -6053,8 +6052,8 @@ void Game::customsavequick(std::string savfile)
{ {
flags += help.String((int) obj.flags[i]) + ","; flags += help.String((int) obj.flags[i]) + ",";
} }
msg = new TiXmlElement( "flags" ); msg = doc.NewElement( "flags" );
msg->LinkEndChild( new TiXmlText( flags.c_str() )); msg->LinkEndChild( doc.NewText( flags.c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string moods; std::string moods;
@ -6062,8 +6061,8 @@ void Game::customsavequick(std::string savfile)
{ {
moods += help.String(obj.customcrewmoods[i]) + ","; moods += help.String(obj.customcrewmoods[i]) + ",";
} }
msg = new TiXmlElement( "moods" ); msg = doc.NewElement( "moods" );
msg->LinkEndChild( new TiXmlText( moods.c_str() )); msg->LinkEndChild( doc.NewText( moods.c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string crewstatsString; std::string crewstatsString;
@ -6071,8 +6070,8 @@ void Game::customsavequick(std::string savfile)
{ {
crewstatsString += help.String(crewstats[i]) + ","; crewstatsString += help.String(crewstats[i]) + ",";
} }
msg = new TiXmlElement( "crewstats" ); msg = doc.NewElement( "crewstats" );
msg->LinkEndChild( new TiXmlText( crewstatsString.c_str() )); msg->LinkEndChild( doc.NewText( crewstatsString.c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string collect; std::string collect;
@ -6080,8 +6079,8 @@ void Game::customsavequick(std::string savfile)
{ {
collect += help.String((int) obj.collect[i]) + ","; collect += help.String((int) obj.collect[i]) + ",";
} }
msg = new TiXmlElement( "collect" ); msg = doc.NewElement( "collect" );
msg->LinkEndChild( new TiXmlText( collect.c_str() )); msg->LinkEndChild( doc.NewText( collect.c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string customcollect; std::string customcollect;
@ -6089,54 +6088,54 @@ void Game::customsavequick(std::string savfile)
{ {
customcollect += help.String((int) obj.customcollect[i]) + ","; customcollect += help.String((int) obj.customcollect[i]) + ",";
} }
msg = new TiXmlElement( "customcollect" ); msg = doc.NewElement( "customcollect" );
msg->LinkEndChild( new TiXmlText( customcollect.c_str() )); msg->LinkEndChild( doc.NewText( customcollect.c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
//Position //Position
msg = new TiXmlElement( "finalx" ); msg = doc.NewElement( "finalx" );
msg->LinkEndChild( new TiXmlText( help.String(map.finalx).c_str() )); msg->LinkEndChild( doc.NewText( help.String(map.finalx).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "finaly" ); msg = doc.NewElement( "finaly" );
msg->LinkEndChild( new TiXmlText( help.String(map.finaly).c_str() )); msg->LinkEndChild( doc.NewText( help.String(map.finaly).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "savex" ); msg = doc.NewElement( "savex" );
msg->LinkEndChild( new TiXmlText( help.String(savex).c_str() )); msg->LinkEndChild( doc.NewText( help.String(savex).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "savey" ); msg = doc.NewElement( "savey" );
msg->LinkEndChild( new TiXmlText( help.String(savey).c_str() )); msg->LinkEndChild( doc.NewText( help.String(savey).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "saverx" ); msg = doc.NewElement( "saverx" );
msg->LinkEndChild( new TiXmlText( help.String(saverx).c_str() )); msg->LinkEndChild( doc.NewText( help.String(saverx).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "savery" ); msg = doc.NewElement( "savery" );
msg->LinkEndChild( new TiXmlText( help.String(savery).c_str() )); msg->LinkEndChild( doc.NewText( help.String(savery).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "savegc" ); msg = doc.NewElement( "savegc" );
msg->LinkEndChild( new TiXmlText( help.String(savegc).c_str() )); msg->LinkEndChild( doc.NewText( help.String(savegc).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "savedir" ); msg = doc.NewElement( "savedir" );
msg->LinkEndChild( new TiXmlText( help.String(savedir).c_str() )); msg->LinkEndChild( doc.NewText( help.String(savedir).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "savepoint" ); msg = doc.NewElement( "savepoint" );
msg->LinkEndChild( new TiXmlText( help.String(savepoint).c_str() )); msg->LinkEndChild( doc.NewText( help.String(savepoint).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "trinkets" ); msg = doc.NewElement( "trinkets" );
msg->LinkEndChild( new TiXmlText( help.String(trinkets()).c_str() )); msg->LinkEndChild( doc.NewText( help.String(trinkets()).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "crewmates" ); msg = doc.NewElement( "crewmates" );
msg->LinkEndChild( new TiXmlText( help.String(crewmates()).c_str() )); msg->LinkEndChild( doc.NewText( help.String(crewmates()).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
@ -6144,80 +6143,80 @@ void Game::customsavequick(std::string savfile)
if(music.nicefade==1) if(music.nicefade==1)
{ {
msg = new TiXmlElement( "currentsong" ); msg = doc.NewElement( "currentsong" );
msg->LinkEndChild( new TiXmlText( help.String(music.nicechange).c_str() )); msg->LinkEndChild( doc.NewText( help.String(music.nicechange).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
} }
else else
{ {
msg = new TiXmlElement( "currentsong" ); msg = doc.NewElement( "currentsong" );
msg->LinkEndChild( new TiXmlText( help.String(music.currentsong).c_str() )); msg->LinkEndChild( doc.NewText( help.String(music.currentsong).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
} }
msg = new TiXmlElement( "teleportscript" ); msg = doc.NewElement( "teleportscript" );
msg->LinkEndChild( new TiXmlText( teleportscript.c_str() )); msg->LinkEndChild( doc.NewText( teleportscript.c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "companion" ); msg = doc.NewElement( "companion" );
msg->LinkEndChild( new TiXmlText( help.String(companion).c_str() )); msg->LinkEndChild( doc.NewText( help.String(companion).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "lastsaved" ); msg = doc.NewElement( "lastsaved" );
msg->LinkEndChild( new TiXmlText( help.String(lastsaved).c_str() )); msg->LinkEndChild( doc.NewText( help.String(lastsaved).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "supercrewmate" ); msg = doc.NewElement( "supercrewmate" );
msg->LinkEndChild( new TiXmlText( BoolToString(supercrewmate) )); msg->LinkEndChild( doc.NewText( BoolToString(supercrewmate) ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "scmprogress" ); msg = doc.NewElement( "scmprogress" );
msg->LinkEndChild( new TiXmlText( help.String(scmprogress).c_str() )); msg->LinkEndChild( doc.NewText( help.String(scmprogress).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "scmmoveme" ); msg = doc.NewElement( "scmmoveme" );
msg->LinkEndChild( new TiXmlText( BoolToString(scmmoveme) )); msg->LinkEndChild( doc.NewText( BoolToString(scmmoveme) ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "frames" ); msg = doc.NewElement( "frames" );
msg->LinkEndChild( new TiXmlText( help.String(frames).c_str() )); msg->LinkEndChild( doc.NewText( help.String(frames).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "seconds" ); msg = doc.NewElement( "seconds" );
msg->LinkEndChild( new TiXmlText( help.String(seconds).c_str() )); msg->LinkEndChild( doc.NewText( help.String(seconds).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "minutes" ); msg = doc.NewElement( "minutes" );
msg->LinkEndChild( new TiXmlText( help.String(minutes).c_str()) ); msg->LinkEndChild( doc.NewText( help.String(minutes).c_str()) );
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "hours" ); msg = doc.NewElement( "hours" );
msg->LinkEndChild( new TiXmlText( help.String(hours).c_str()) ); msg->LinkEndChild( doc.NewText( help.String(hours).c_str()) );
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "deathcounts" ); msg = doc.NewElement( "deathcounts" );
msg->LinkEndChild( new TiXmlText( help.String(deathcounts).c_str() )); msg->LinkEndChild( doc.NewText( help.String(deathcounts).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "totalflips" ); msg = doc.NewElement( "totalflips" );
msg->LinkEndChild( new TiXmlText( help.String(totalflips).c_str() )); msg->LinkEndChild( doc.NewText( help.String(totalflips).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "hardestroom" ); msg = doc.NewElement( "hardestroom" );
msg->LinkEndChild( new TiXmlText( hardestroom.c_str() )); msg->LinkEndChild( doc.NewText( hardestroom.c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "hardestroomdeaths" ); msg = doc.NewElement( "hardestroomdeaths" );
msg->LinkEndChild( new TiXmlText( help.String(hardestroomdeaths).c_str() )); msg->LinkEndChild( doc.NewText( help.String(hardestroomdeaths).c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "showminimap" ); msg = doc.NewElement( "showminimap" );
msg->LinkEndChild( new TiXmlText( BoolToString(map.customshowmm) )); msg->LinkEndChild( doc.NewText( BoolToString(map.customshowmm) ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
msg = new TiXmlElement( "summary" ); msg = doc.NewElement( "summary" );
std::string summary = savearea + ", " + timestring(); std::string summary = savearea + ", " + timestring();
msg->LinkEndChild( new TiXmlText( summary.c_str() )); msg->LinkEndChild( doc.NewText( summary.c_str() ));
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
customquicksummary = summary; customquicksummary = summary;
std::string levelfile = savfile.substr(7); std::string levelfile = savfile.substr(7);
if(FILESYSTEM_saveTiXmlDocument(("saves/"+levelfile+".vvv").c_str(), &doc)) if(FILESYSTEM_saveTiXml2Document(("saves/"+levelfile+".vvv").c_str(), doc))
{ {
printf("Game saved\n"); printf("Game saved\n");
} }