mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-10 18:34:21 +02:00
PTsave opening
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
|
#include "Style.h"
|
||||||
#include "interface/Engine.h"
|
#include "interface/Engine.h"
|
||||||
#include "interface/Button.h"
|
#include "interface/Button.h"
|
||||||
#include "interface/Panel.h"
|
#include "interface/Panel.h"
|
||||||
@@ -365,7 +366,9 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
if(arguments["open"].length())
|
if(arguments["open"].length())
|
||||||
{
|
{
|
||||||
std::cout << arguments["open"] << std::endl;
|
#ifdef DEBUG
|
||||||
|
std::cout << "Loading " << arguments["open"] << std::endl;
|
||||||
|
#endif
|
||||||
if(Client::Ref().FileExists(arguments["open"]))
|
if(Client::Ref().FileExists(arguments["open"]))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -396,6 +399,66 @@ int main(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(arguments["ptsave"].length())
|
||||||
|
{
|
||||||
|
engine->g->fillrect((engine->GetWidth()/2)-101, (engine->GetHeight()/2)-26, 202, 52, 0, 0, 0, 210);
|
||||||
|
engine->g->drawrect((engine->GetWidth()/2)-100, (engine->GetHeight()/2)-25, 200, 50, 255, 255, 255, 180);
|
||||||
|
engine->g->drawtext((engine->GetWidth()/2)-(Graphics::textwidth("Loading save...")/2), (engine->GetHeight()/2)-5, "Loading save...", style::Colour::InformationTitle.Red, style::Colour::InformationTitle.Green, style::Colour::InformationTitle.Blue, 255);
|
||||||
|
|
||||||
|
#ifdef OGLI
|
||||||
|
blit();
|
||||||
|
#else
|
||||||
|
if(engine->Scale==2)
|
||||||
|
blit2(engine->g->vid, engine->Scale);
|
||||||
|
else
|
||||||
|
blit(engine->g->vid);
|
||||||
|
#endif
|
||||||
|
std::string ptsaveArg = arguments["ptsave"];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(!ptsaveArg.find("ptsave:"))
|
||||||
|
{
|
||||||
|
std::string saveIdPart = "";
|
||||||
|
int saveId;
|
||||||
|
int hashPos = ptsaveArg.find('#');
|
||||||
|
if(hashPos != std::string::npos)
|
||||||
|
{
|
||||||
|
saveIdPart = ptsaveArg.substr(7, hashPos-7);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saveIdPart = ptsaveArg.substr(7);
|
||||||
|
}
|
||||||
|
if(saveIdPart.length())
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cout << "Got Ptsave: id: " << saveIdPart << std::endl;
|
||||||
|
#endif
|
||||||
|
saveId = format::StringToNumber<int>(saveIdPart);
|
||||||
|
if(!saveId)
|
||||||
|
throw std::runtime_error("Invalid Save ID");
|
||||||
|
|
||||||
|
SaveInfo * newSave = Client::Ref().GetSave(saveId, 0);
|
||||||
|
GameSave * newGameSave = new GameSave(Client::Ref().GetSaveData(saveId, 0));
|
||||||
|
newSave->SetGameSave(newGameSave);
|
||||||
|
if(!newSave)
|
||||||
|
throw std::runtime_error("Could not load save");
|
||||||
|
|
||||||
|
gameController->LoadSave(newSave);
|
||||||
|
delete newSave;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("No Save ID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception & e)
|
||||||
|
{
|
||||||
|
new ErrorMessage("Error", "Invalid save link");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while(engine->Running())
|
while(engine->Running())
|
||||||
{
|
{
|
||||||
|
@@ -741,6 +741,17 @@ unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> Client::GetSaveData(int saveID, int saveDate)
|
||||||
|
{
|
||||||
|
int dataSize;
|
||||||
|
unsigned char * data = GetSaveData(saveID, saveDate, dataSize);
|
||||||
|
|
||||||
|
std::vector<unsigned char> saveData(data, data+dataSize);
|
||||||
|
|
||||||
|
delete[] data;
|
||||||
|
return saveData;
|
||||||
|
}
|
||||||
|
|
||||||
LoginStatus Client::Login(string username, string password, User & user)
|
LoginStatus Client::Login(string username, string password, User & user)
|
||||||
{
|
{
|
||||||
lastError = "";
|
lastError = "";
|
||||||
|
@@ -111,6 +111,7 @@ public:
|
|||||||
RequestStatus AddComment(int saveID, std::string comment);
|
RequestStatus AddComment(int saveID, std::string comment);
|
||||||
|
|
||||||
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
||||||
|
std::vector<unsigned char> GetSaveData(int saveID, int saveDate);
|
||||||
LoginStatus Login(string username, string password, User & user);
|
LoginStatus Login(string username, string password, User & user);
|
||||||
void ClearThumbnailRequests();
|
void ClearThumbnailRequests();
|
||||||
std::vector<SaveInfo*> * SearchSaves(int start, int count, string query, string sort, string category, int & resultCount);
|
std::vector<SaveInfo*> * SearchSaves(int start, int count, string query, string sort, string category, int & resultCount);
|
||||||
|
@@ -819,6 +819,9 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
|||||||
{
|
{
|
||||||
if(sender->GetSave())
|
if(sender->GetSave())
|
||||||
{
|
{
|
||||||
|
if(introText > 50)
|
||||||
|
introText = 50;
|
||||||
|
|
||||||
saveSimulationButton->SetText(sender->GetSave()->GetName());
|
saveSimulationButton->SetText(sender->GetSave()->GetName());
|
||||||
if(sender->GetSave()->GetUserName() == sender->GetUser().Username)
|
if(sender->GetSave()->GetUserName() == sender->GetUser().Username)
|
||||||
((SplitButton*)saveSimulationButton)->SetShowSplit(true);
|
((SplitButton*)saveSimulationButton)->SetShowSplit(true);
|
||||||
@@ -1324,7 +1327,7 @@ void GameView::OnTick(float dt)
|
|||||||
}
|
}
|
||||||
if(introText)
|
if(introText)
|
||||||
{
|
{
|
||||||
introText -= int(dt)>0?int(dt):1;
|
introText -= int(dt)>0?std::min(int(dt), 5):1;
|
||||||
if(introText < 0)
|
if(introText < 0)
|
||||||
introText = 0;
|
introText = 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user