Permalink
Browse files

Take history snapshot before setting save (#358)

  • Loading branch information...
krawthekrow authored and jacob1 committed Mar 20, 2017
1 parent e13e31c commit 1c12d1ec16988fa859acaa5dd5248856769162b4
Showing with 8 additions and 11 deletions.
  1. +8 −6 src/gui/game/GameController.cpp
  2. +0 −1 src/gui/game/GameModel.cpp
  3. +0 −3 src/gui/game/GameModel.h
  4. +0 −1 src/gui/game/GameView.cpp
@@ -51,6 +51,7 @@ class GameController::SearchCallback: public ControllerCallback
{
try
{
cc->HistorySnapshot();
cc->gameModel->SetSave(cc->search->GetLoadedSave());
cc->search->ReleaseLoadedSave();
}
@@ -73,6 +74,7 @@ class GameController::SaveOpenCallback: public ControllerCallback
{
try
{
cc->HistorySnapshot();
cc->LoadSave(cc->activePreview->GetSaveInfo());
}
catch(GameModelException & ex)
@@ -144,7 +146,6 @@ GameController::GameController():
gameView->AttachController(this);
gameModel->AddObserver(gameView);
gameModel->SetAllowHistory();
gameView->SetDebugHUD(Client::Ref().GetPrefBool("Renderer.DebugMode", false));
@@ -253,11 +254,6 @@ void GameController::HistoryRestore()
void GameController::HistorySnapshot()
{
// callbacks during initialization create two empty snapshots on startup
// Prevent that from happening here
if (!gameModel->GetAllowHistory())
return;
std::deque<Snapshot*> history = gameModel->GetHistory();
unsigned int historyPosition = gameModel->GetHistoryPosition();
Snapshot * newSnap = gameModel->GetSimulation()->CreateSnapshot();
@@ -288,6 +284,8 @@ void GameController::HistorySnapshot()
void GameController::HistoryForward()
{
std::deque<Snapshot*> history = gameModel->GetHistory();
if (!history.size())
return;
unsigned int historyPosition = gameModel->GetHistoryPosition();
unsigned int newHistoryPosition = std::min((size_t)historyPosition+1, history.size());
Snapshot *snap;
@@ -1252,6 +1250,7 @@ void GameController::OpenLocalBrowse()
virtual ~LocalSaveOpenCallback() {};
virtual void FileSelected(SaveFile* file)
{
c->HistorySnapshot();
c->LoadSaveFile(file);
delete file;
}
@@ -1488,6 +1487,7 @@ void GameController::ChangeBrush()
void GameController::ClearSim()
{
HistorySnapshot();
gameModel->SetSave(NULL);
gameModel->ClearSimulation();
}
@@ -1496,10 +1496,12 @@ void GameController::ReloadSim()
{
if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave())
{
HistorySnapshot();
gameModel->SetSave(gameModel->GetSave());
}
else if(gameModel->GetSaveFile() && gameModel->GetSaveFile()->GetGameSave())
{
HistorySnapshot();
gameModel->SetSaveFile(gameModel->GetSaveFile());
}
}
@@ -28,7 +28,6 @@ GameModel::GameModel():
currentFile(NULL),
currentUser(0, ""),
toolStrength(1.0f),
allowHistory(false),
redoHistory(NULL),
historyPosition(0),
activeColourPreset(0),
@@ -64,7 +64,6 @@ class GameModel
Tool * regularToolset[4];
User currentUser;
float toolStrength;
bool allowHistory;
std::deque<Snapshot*> history;
Snapshot *redoHistory;
unsigned int historyPosition;
@@ -132,8 +131,6 @@ class GameModel
void BuildFavoritesMenu();
void BuildQuickOptionMenu(GameController * controller);
bool GetAllowHistory() { return allowHistory; }
void SetAllowHistory() { allowHistory = true; }
std::deque<Snapshot*> GetHistory();
unsigned int GetHistoryPosition();
void SetHistory(std::deque<Snapshot*> newHistory);
@@ -1035,7 +1035,6 @@ void GameView::NotifySaveChanged(GameModel * sender)
}
saveSimulationButton->Enabled = (saveSimulationButtonEnabled || ctrlBehaviour);
SetSaveButtonTooltips();
c->HistorySnapshot();
}
void GameView::NotifyBrushChanged(GameModel * sender)

0 comments on commit 1c12d1e

Please sign in to comment.