1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2025-01-08 18:09:45 +01:00

Add XML forwards compatibility to custom level quicksaves

Now these files might have things added to them in the future? I'm not
so sure. But at least they're XML forwards-compatible now.
This commit is contained in:
Misa 2020-09-25 09:11:03 -07:00 committed by Ethan Lee
parent 0eb39644c1
commit 58795a1381

View file

@ -5886,19 +5886,22 @@ std::string Game::writemaingamesave(tinyxml2::XMLDocument& doc)
void Game::customsavequick(std::string savfile) void Game::customsavequick(std::string savfile)
{ {
const std::string levelfile = savfile.substr(7);
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
tinyxml2::XMLElement* msg; bool already_exists = FILESYSTEM_loadTiXml2Document(("saves/" + levelfile + ".vvv").c_str(), doc);
tinyxml2::XMLDeclaration* decl = doc.NewDeclaration(); if (!already_exists)
doc.LinkEndChild( decl ); {
printf("No %s.vvv found. Creating new file\n", levelfile.c_str());
}
tinyxml2::XMLElement * root = doc.NewElement( "Save" ); xml::update_declaration(doc);
doc.LinkEndChild( root );
tinyxml2::XMLComment * comment = doc.NewComment(" Save file " ); tinyxml2::XMLElement * root = xml::update_element(doc, "Save");
root->LinkEndChild( comment );
tinyxml2::XMLElement * msgs = doc.NewElement( "Data" ); xml::update_comment(root, " Save file ");
root->LinkEndChild( msgs );
tinyxml2::XMLElement * msgs = xml::update_element(root, "Data");
//Flags, map and stats //Flags, map and stats
@ -5908,179 +5911,108 @@ void Game::customsavequick(std::string savfile)
{ {
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 moods; std::string moods;
for(size_t i = 0; i < SDL_arraysize(obj.customcrewmoods); i++ ) for(size_t i = 0; i < SDL_arraysize(obj.customcrewmoods); i++ )
{ {
moods += help.String(obj.customcrewmoods[i]) + ","; moods += help.String(obj.customcrewmoods[i]) + ",";
} }
msg = doc.NewElement( "moods" ); xml::update_tag(msgs, "moods", moods.c_str());
msg->LinkEndChild( doc.NewText( moods.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 );
std::string customcollect; std::string customcollect;
for(size_t i = 0; i < SDL_arraysize(obj.customcollect); i++ ) for(size_t i = 0; i < SDL_arraysize(obj.customcollect); i++ )
{ {
customcollect += help.String((int) obj.customcollect[i]) + ","; customcollect += help.String((int) obj.customcollect[i]) + ",";
} }
msg = doc.NewElement( "customcollect" ); xml::update_tag(msgs, "customcollect", customcollect.c_str());
msg->LinkEndChild( doc.NewText( customcollect.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 );
msg = doc.NewElement( "crewmates" ); xml::update_tag(msgs, "crewmates", crewmates());
msg->LinkEndChild( doc.NewText( help.String(crewmates()).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( "showminimap" ); xml::update_tag(msgs, "showminimap", BoolToString(map.customshowmm));
msg->LinkEndChild( doc.NewText( BoolToString(map.customshowmm) ));
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 );
customquicksummary = summary; customquicksummary = summary;
std::string levelfile = savfile.substr(7);
if(FILESYSTEM_saveTiXml2Document(("saves/"+levelfile+".vvv").c_str(), doc)) if(FILESYSTEM_saveTiXml2Document(("saves/"+levelfile+".vvv").c_str(), doc))
{ {
printf("Game saved\n"); printf("Game saved\n");