summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-07 13:23:26 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-07 13:23:26 (GMT)
commit61ed6e0276d580515d0acf5ddb96b1db95b9b191 (patch)
tree65d9ad219e0b0f6bb1a81813c1888888f2cbd7a4 /src/game
parent2e48fc6115ebe0d294a2c7ff7fe8774217676f44 (diff)
downloadpowder-61ed6e0276d580515d0acf5ddb96b1db95b9b191.zip
powder-61ed6e0276d580515d0acf5ddb96b1db95b9b191.tar.gz
Rename Save class to SaveInfo, introduce SaveFile for hanlding of local data (stamps and local saves). Rename Stamps browser to LocalBrowser, ready for sharing code with the local save browser
Diffstat (limited to 'src/game')
-rw-r--r--src/game/GameController.cpp35
-rw-r--r--src/game/GameController.h4
-rw-r--r--src/game/GameModel.cpp27
-rw-r--r--src/game/GameModel.h10
4 files changed, 30 insertions, 46 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index dff6c18..01cf1de 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -4,7 +4,7 @@
#include "Config.h"
#include "GameController.h"
#include "GameModel.h"
-#include "search/Save.h"
+#include "client/SaveInfo.h"
#include "search/SearchController.h"
#include "render/RenderController.h"
#include "login/LoginController.h"
@@ -37,7 +37,7 @@ public:
{
try
{
- cc->gameModel->SetSave(new Save(*(cc->search->GetLoadedSave())));
+ cc->gameModel->SetSave(new SaveInfo(*(cc->search->GetLoadedSave())));
}
catch(GameModelException & ex)
{
@@ -79,7 +79,7 @@ public:
{
if(cc->ssave->GetSaveUploaded())
{
- cc->gameModel->SetSave(new Save(*(cc->ssave->GetSave())));
+ cc->gameModel->SetSave(new SaveInfo(*(cc->ssave->GetSave())));
}
//cc->gameModel->SetUser(cc->loginWindow->GetUser());
@@ -93,7 +93,7 @@ public:
TagsCallback(GameController * cc_) { cc = cc_; }
virtual void ControllerExit()
{
- cc->gameModel->SetSave(new Save(*(cc->tagsWindow->GetSave())));
+ cc->gameModel->SetSave(new SaveInfo(*(cc->tagsWindow->GetSave())));
}
};
@@ -104,9 +104,9 @@ public:
StampsCallback(GameController * cc_) { cc = cc_; }
virtual void ControllerExit()
{
- if(cc->stamps->GetStamp())
+ if(cc->localBrowser->GetSave())
{
- cc->gameModel->SetStamp(cc->stamps->GetStamp());
+ cc->gameModel->SetStamp(cc->localBrowser->GetSave()->GetGameSave());
}
else
cc->gameModel->SetStamp(NULL);
@@ -501,8 +501,8 @@ void GameController::OpenTags()
void GameController::OpenStamps()
{
- stamps = new StampsController(new StampsCallback(this));
- ui::Engine::Ref().ShowWindow(stamps->GetView());
+ localBrowser = new LocalBrowserController(new StampsCallback(this));
+ ui::Engine::Ref().ShowWindow(localBrowser->GetView());
}
void GameController::OpenOptions()
@@ -529,25 +529,23 @@ void GameController::OpenSaveWindow()
{
if(gameModel->GetUser().ID)
{
- GameSave * tempSave = gameModel->GetSimulation()->Save();
- if(!tempSave)
+ GameSave * gameSave = gameModel->GetSimulation()->Save();
+ if(!gameSave)
{
new ErrorMessage("Error", "Unable to build save.");
}
else
{
- int dataSize;
- unsigned char * tempData = (unsigned char*)tempSave->Serialise(dataSize);
if(gameModel->GetSave())
{
- Save tempSave(*gameModel->GetSave());
- tempSave.SetData(tempData, dataSize);
+ SaveInfo tempSave(*gameModel->GetSave());
+ tempSave.SetGameSave(gameSave);
ssave = new SSaveController(new SSaveCallback(this), tempSave);
}
else
{
- Save tempSave(0, 0, 0, 0, gameModel->GetUser().Username, "");
- tempSave.SetData(tempData, dataSize);
+ SaveInfo tempSave(0, 0, 0, 0, gameModel->GetUser().Username, "");
+ tempSave.SetGameSave(gameSave);
ssave = new SSaveController(new SSaveCallback(this), tempSave);
}
ui::Engine::Ref().ShowWindow(ssave->GetView());
@@ -584,10 +582,9 @@ void GameController::ClearSim()
void GameController::ReloadSim()
{
- if(gameModel->GetSave() && gameModel->GetSave()->GetData())
+ if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave())
{
- GameSave * newSave = new GameSave((char*)gameModel->GetSave()->GetData(), gameModel->GetSave()->GetDataLength());
- gameModel->GetSimulation()->Load(newSave);
+ gameModel->GetSimulation()->Load(gameModel->GetSave()->GetGameSave());
}
}
diff --git a/src/game/GameController.h b/src/game/GameController.h
index bb6e61a..25705bc 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -12,7 +12,7 @@
#include "ssave/SSaveController.h"
#include "tags/TagsController.h"
#include "console/ConsoleController.h"
-#include "stamps/StampsController.h"
+#include "localbrowser/LocalBrowserController.h"
//#include "cat/TPTScriptInterface.h"
#include "cat/LuaScriptInterface.h"
#include "options/OptionsController.h"
@@ -36,7 +36,7 @@ private:
SSaveController * ssave;
ConsoleController * console;
TagsController * tagsWindow;
- StampsController * stamps;
+ LocalBrowserController * localBrowser;
OptionsController * options;
CommandInterface * commandInterface;
public:
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 966eca7..9e655f9 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -263,20 +263,19 @@ vector<Menu*> GameModel::GetMenuList()
return menuList;
}
-Save * GameModel::GetSave()
+SaveInfo * GameModel::GetSave()
{
return currentSave;
}
-void GameModel::SetSave(Save * newSave)
+void GameModel::SetSave(SaveInfo * newSave)
{
if(currentSave)
delete currentSave;
currentSave = newSave;
if(currentSave)
{
- GameSave * newSave = new GameSave((char*)currentSave->GetData(), currentSave->GetDataLength());
- int returnVal = sim->Load(newSave);
+ int returnVal = sim->Load(currentSave->GetGameSave());
if(returnVal){
delete currentSave;
currentSave = NULL;
@@ -430,15 +429,11 @@ void GameModel::ClearSimulation()
sim->clear_sim();
}
-void GameModel::SetStamp(Save * save)
+void GameModel::SetStamp(GameSave * save)
{
if(stamp)
delete stamp;
- try {
- stamp = new GameSave((char*)save->GetData(), save->GetDataLength());
- } catch (ParseException& e) {
- stamp = NULL;
- }
+ stamp = new GameSave(*save);
notifyStampChanged();
}
@@ -446,16 +441,8 @@ void GameModel::AddStamp(GameSave * save)
{
if(stamp)
delete stamp;
- stamp = save;
-
- char * saveData;
- int saveSize;
- saveData = save->Serialise(saveSize);
- Save * tempSave = new Save(0, 0, 0, 0, "", "");
- tempSave->SetData((unsigned char*)saveData, saveSize);
- Client::Ref().AddStamp(tempSave);
- delete tempSave;
-
+ stamp = new GameSave(*save);
+ Client::Ref().AddStamp(save);
notifyClipboardChanged();
}
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index c038493..5c8b0aa 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -3,7 +3,7 @@
#include <vector>
#include <deque>
-#include "search/Save.h"
+#include "client/SaveInfo.h"
#include "simulation/Simulation.h"
#include "interface/Colour.h"
#include "Renderer.h"
@@ -43,7 +43,7 @@ private:
Menu * activeMenu;
int currentBrush;
vector<Brush *> brushList;
- Save * currentSave;
+ SaveInfo * currentSave;
Simulation * sim;
Renderer * ren;
Tool * activeTools[3];
@@ -78,9 +78,9 @@ public:
ui::Colour GetColourSelectorColour();
void SetVote(int direction);
- Save * GetSave();
+ SaveInfo * GetSave();
Brush * GetBrush();
- void SetSave(Save * newSave);
+ void SetSave(SaveInfo * newSave);
void AddObserver(GameView * observer);
Tool * GetActiveTool(int selection);
void SetActiveTool(int selection, Tool * tool);
@@ -110,7 +110,7 @@ public:
ui::Point GetZoomPosition();
void SetZoomWindowPosition(ui::Point position);
ui::Point GetZoomWindowPosition();
- void SetStamp(Save * newStamp);
+ void SetStamp(GameSave * newStamp);
void AddStamp(GameSave * save);
void SetClipboard(GameSave * save);
void Log(string message);