1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 14:38:30 +02:00

Add XML forwards compatibility to tsave.vvv and qsave.vvv

These files are probably not of much consequence. The main game isn't
going to have things to be added to it anytime soon.
This commit is contained in:
Misa 2020-09-25 09:10:48 -07:00 committed by Ethan Lee
parent 17b8d0308e
commit 0eb39644c1

View File

@ -5720,6 +5720,11 @@ void Game::savetele()
} }
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/tsave.vvv", doc);
if (!already_exists)
{
puts("No tsave.vvv found. Creating new file");
}
telesummary = writemaingamesave(doc); telesummary = writemaingamesave(doc);
if(FILESYSTEM_saveTiXml2Document("saves/tsave.vvv", doc)) if(FILESYSTEM_saveTiXml2Document("saves/tsave.vvv", doc))
@ -5743,6 +5748,11 @@ void Game::savequick()
} }
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/qsave.vvv", doc);
if (!already_exists)
{
puts("No qsave.vvv found. Creating new file");
}
quicksummary = writemaingamesave(doc); quicksummary = writemaingamesave(doc);
if(FILESYSTEM_saveTiXml2Document("saves/qsave.vvv", doc)) if(FILESYSTEM_saveTiXml2Document("saves/qsave.vvv", doc))
@ -5768,18 +5778,13 @@ std::string Game::writemaingamesave(tinyxml2::XMLDocument& doc)
return ""; return "";
} }
tinyxml2::XMLElement* msg; xml::update_declaration(doc);
tinyxml2::XMLDeclaration* decl = doc.NewDeclaration();
doc.LinkEndChild( decl );
tinyxml2::XMLElement * root = doc.NewElement( "Save" ); tinyxml2::XMLElement * root = xml::update_element(doc, "Save");
doc.LinkEndChild( root );
tinyxml2::XMLComment * comment = doc.NewComment(" Save file " ); xml::update_comment(root, " Save file " );
root->LinkEndChild( comment );
tinyxml2::XMLElement * msgs = doc.NewElement( "Data" ); tinyxml2::XMLElement * msgs = xml::update_element(root, "Data");
root->LinkEndChild( msgs );
//Flags, map and stats //Flags, map and stats
@ -5789,157 +5794,91 @@ std::string Game::writemaingamesave(tinyxml2::XMLDocument& doc)
{ {
mapExplored += help.String(map.explored[i]) + ","; mapExplored += help.String(map.explored[i]) + ",";
} }
msg = doc.NewElement( "worldmap" ); xml::update_tag(msgs, "worldmap", mapExplored.c_str());
msg->LinkEndChild( doc.NewText( mapExplored.c_str() ));
msgs->LinkEndChild( msg );
std::string flags; std::string flags;
for(size_t i = 0; i < SDL_arraysize(obj.flags); i++ ) for(size_t i = 0; i < SDL_arraysize(obj.flags); i++ )
{ {
flags += help.String((int) obj.flags[i]) + ","; flags += help.String((int) obj.flags[i]) + ",";
} }
msg = doc.NewElement( "flags" ); xml::update_tag(msgs, "flags", flags.c_str());
msg->LinkEndChild( doc.NewText( flags.c_str() ));
msgs->LinkEndChild( msg );
std::string crewstatsString; std::string crewstatsString;
for(size_t i = 0; i < SDL_arraysize(crewstats); i++ ) for(size_t i = 0; i < SDL_arraysize(crewstats); i++ )
{ {
crewstatsString += help.String(crewstats[i]) + ","; crewstatsString += help.String(crewstats[i]) + ",";
} }
msg = doc.NewElement( "crewstats" ); xml::update_tag(msgs, "crewstats", crewstatsString.c_str());
msg->LinkEndChild( doc.NewText( crewstatsString.c_str() ));
msgs->LinkEndChild( msg );
std::string collect; std::string collect;
for(size_t i = 0; i < SDL_arraysize(obj.collect); i++ ) for(size_t i = 0; i < SDL_arraysize(obj.collect); i++ )
{ {
collect += help.String((int) obj.collect[i]) + ","; collect += help.String((int) obj.collect[i]) + ",";
} }
msg = doc.NewElement( "collect" ); xml::update_tag(msgs, "collect", collect.c_str());
msg->LinkEndChild( doc.NewText( collect.c_str() ));
msgs->LinkEndChild( msg );
//Position //Position
msg = doc.NewElement( "finalx" ); xml::update_tag(msgs, "finalx", map.finalx);
msg->LinkEndChild( doc.NewText( help.String(map.finalx).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "finaly" ); xml::update_tag(msgs, "finaly", map.finaly);
msg->LinkEndChild( doc.NewText( help.String(map.finaly).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "savex" ); xml::update_tag(msgs, "savex", savex);
msg->LinkEndChild( doc.NewText( help.String(savex).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "savey" ); xml::update_tag(msgs, "savey", savey);
msg->LinkEndChild( doc.NewText( help.String(savey).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "saverx" ); xml::update_tag(msgs, "saverx", saverx);
msg->LinkEndChild( doc.NewText( help.String(saverx).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "savery" ); xml::update_tag(msgs, "savery", savery);
msg->LinkEndChild( doc.NewText( help.String(savery).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "savegc" ); xml::update_tag(msgs, "savegc", savegc);
msg->LinkEndChild( doc.NewText( help.String(savegc).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "savedir" ); xml::update_tag(msgs, "savedir", savedir);
msg->LinkEndChild( doc.NewText( help.String(savedir).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "savepoint" ); xml::update_tag(msgs, "savepoint", savepoint);
msg->LinkEndChild( doc.NewText( help.String(savepoint).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "trinkets" ); xml::update_tag(msgs, "trinkets", trinkets());
msg->LinkEndChild( doc.NewText( help.String(trinkets()).c_str() ));
msgs->LinkEndChild( msg );
//Special stats //Special stats
if(music.nicefade==1) if(music.nicefade==1)
{ {
msg = doc.NewElement( "currentsong" ); xml::update_tag(msgs, "currentsong", music.nicechange);
msg->LinkEndChild( doc.NewText( help.String(music.nicechange).c_str() ));
msgs->LinkEndChild( msg );
} }
else else
{ {
msg = doc.NewElement( "currentsong" ); xml::update_tag(msgs, "currentsong", music.currentsong);
msg->LinkEndChild( doc.NewText( help.String(music.currentsong).c_str() ));
msgs->LinkEndChild( msg );
} }
msg = doc.NewElement( "teleportscript" ); xml::update_tag(msgs, "teleportscript", teleportscript.c_str());
msg->LinkEndChild( doc.NewText( teleportscript.c_str() )); xml::update_tag(msgs, "companion", companion);
msgs->LinkEndChild( msg );
msg = doc.NewElement( "companion" );
msg->LinkEndChild( doc.NewText( help.String(companion).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "lastsaved" ); xml::update_tag(msgs, "lastsaved", lastsaved);
msg->LinkEndChild( doc.NewText( help.String(lastsaved).c_str() )); xml::update_tag(msgs, "supercrewmate", BoolToString(supercrewmate));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "supercrewmate" );
msg->LinkEndChild( doc.NewText( BoolToString(supercrewmate) ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "scmprogress" ); xml::update_tag(msgs, "scmprogress", scmprogress);
msg->LinkEndChild( doc.NewText( help.String(scmprogress).c_str() )); xml::update_tag(msgs, "scmmoveme", BoolToString(scmmoveme));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "scmmoveme" );
msg->LinkEndChild( doc.NewText( BoolToString(scmmoveme) ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "frames" ); xml::update_tag(msgs, "frames", frames);
msg->LinkEndChild( doc.NewText( help.String(frames).c_str() )); xml::update_tag(msgs, "seconds", seconds);
msgs->LinkEndChild( msg );
msg = doc.NewElement( "seconds" );
msg->LinkEndChild( doc.NewText( help.String(seconds).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "minutes" ); xml::update_tag(msgs, "minutes", minutes);
msg->LinkEndChild( doc.NewText( help.String(minutes).c_str()) ); xml::update_tag(msgs, "hours", hours);
msgs->LinkEndChild( msg );
msg = doc.NewElement( "hours" );
msg->LinkEndChild( doc.NewText( help.String(hours).c_str()) );
msgs->LinkEndChild( msg );
msg = doc.NewElement( "deathcounts" ); xml::update_tag(msgs, "deathcounts", deathcounts);
msg->LinkEndChild( doc.NewText( help.String(deathcounts).c_str() )); xml::update_tag(msgs, "totalflips", totalflips);
msgs->LinkEndChild( msg );
msg = doc.NewElement( "totalflips" );
msg->LinkEndChild( doc.NewText( help.String(totalflips).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "hardestroom" ); xml::update_tag(msgs, "hardestroom", hardestroom.c_str());
msg->LinkEndChild( doc.NewText( hardestroom.c_str() )); xml::update_tag(msgs, "hardestroomdeaths", hardestroomdeaths);
msgs->LinkEndChild( msg );
msg = doc.NewElement( "hardestroomdeaths" );
msg->LinkEndChild( doc.NewText( help.String(hardestroomdeaths).c_str() ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "finalmode" ); xml::update_tag(msgs, "finalmode", BoolToString(map.finalmode));
msg->LinkEndChild( doc.NewText( BoolToString(map.finalmode))); xml::update_tag(msgs, "finalstretch", BoolToString(map.finalstretch));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "finalstretch" );
msg->LinkEndChild( doc.NewText( BoolToString(map.finalstretch) ));
msgs->LinkEndChild( msg );
msg = doc.NewElement( "summary" );
std::string summary = savearea + ", " + timestring(); std::string summary = savearea + ", " + timestring();
msg->LinkEndChild( doc.NewText( summary.c_str() )); xml::update_tag(msgs, "summary", summary.c_str());
msgs->LinkEndChild( msg );
return summary; return summary;
} }