mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-12 19:34:01 +02:00
Take history snapshot before setting save (#358)
This commit is contained in:
@@ -51,6 +51,7 @@ public:
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
cc->HistorySnapshot();
|
||||||
cc->gameModel->SetSave(cc->search->GetLoadedSave());
|
cc->gameModel->SetSave(cc->search->GetLoadedSave());
|
||||||
cc->search->ReleaseLoadedSave();
|
cc->search->ReleaseLoadedSave();
|
||||||
}
|
}
|
||||||
@@ -73,6 +74,7 @@ public:
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
cc->HistorySnapshot();
|
||||||
cc->LoadSave(cc->activePreview->GetSaveInfo());
|
cc->LoadSave(cc->activePreview->GetSaveInfo());
|
||||||
}
|
}
|
||||||
catch(GameModelException & ex)
|
catch(GameModelException & ex)
|
||||||
@@ -144,7 +146,6 @@ GameController::GameController():
|
|||||||
|
|
||||||
gameView->AttachController(this);
|
gameView->AttachController(this);
|
||||||
gameModel->AddObserver(gameView);
|
gameModel->AddObserver(gameView);
|
||||||
gameModel->SetAllowHistory();
|
|
||||||
|
|
||||||
gameView->SetDebugHUD(Client::Ref().GetPrefBool("Renderer.DebugMode", false));
|
gameView->SetDebugHUD(Client::Ref().GetPrefBool("Renderer.DebugMode", false));
|
||||||
|
|
||||||
@@ -253,11 +254,6 @@ void GameController::HistoryRestore()
|
|||||||
|
|
||||||
void GameController::HistorySnapshot()
|
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();
|
std::deque<Snapshot*> history = gameModel->GetHistory();
|
||||||
unsigned int historyPosition = gameModel->GetHistoryPosition();
|
unsigned int historyPosition = gameModel->GetHistoryPosition();
|
||||||
Snapshot * newSnap = gameModel->GetSimulation()->CreateSnapshot();
|
Snapshot * newSnap = gameModel->GetSimulation()->CreateSnapshot();
|
||||||
@@ -288,6 +284,8 @@ void GameController::HistorySnapshot()
|
|||||||
void GameController::HistoryForward()
|
void GameController::HistoryForward()
|
||||||
{
|
{
|
||||||
std::deque<Snapshot*> history = gameModel->GetHistory();
|
std::deque<Snapshot*> history = gameModel->GetHistory();
|
||||||
|
if (!history.size())
|
||||||
|
return;
|
||||||
unsigned int historyPosition = gameModel->GetHistoryPosition();
|
unsigned int historyPosition = gameModel->GetHistoryPosition();
|
||||||
unsigned int newHistoryPosition = std::min((size_t)historyPosition+1, history.size());
|
unsigned int newHistoryPosition = std::min((size_t)historyPosition+1, history.size());
|
||||||
Snapshot *snap;
|
Snapshot *snap;
|
||||||
@@ -1252,6 +1250,7 @@ void GameController::OpenLocalBrowse()
|
|||||||
virtual ~LocalSaveOpenCallback() {};
|
virtual ~LocalSaveOpenCallback() {};
|
||||||
virtual void FileSelected(SaveFile* file)
|
virtual void FileSelected(SaveFile* file)
|
||||||
{
|
{
|
||||||
|
c->HistorySnapshot();
|
||||||
c->LoadSaveFile(file);
|
c->LoadSaveFile(file);
|
||||||
delete file;
|
delete file;
|
||||||
}
|
}
|
||||||
@@ -1488,6 +1487,7 @@ void GameController::ChangeBrush()
|
|||||||
|
|
||||||
void GameController::ClearSim()
|
void GameController::ClearSim()
|
||||||
{
|
{
|
||||||
|
HistorySnapshot();
|
||||||
gameModel->SetSave(NULL);
|
gameModel->SetSave(NULL);
|
||||||
gameModel->ClearSimulation();
|
gameModel->ClearSimulation();
|
||||||
}
|
}
|
||||||
@@ -1496,10 +1496,12 @@ void GameController::ReloadSim()
|
|||||||
{
|
{
|
||||||
if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave())
|
if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave())
|
||||||
{
|
{
|
||||||
|
HistorySnapshot();
|
||||||
gameModel->SetSave(gameModel->GetSave());
|
gameModel->SetSave(gameModel->GetSave());
|
||||||
}
|
}
|
||||||
else if(gameModel->GetSaveFile() && gameModel->GetSaveFile()->GetGameSave())
|
else if(gameModel->GetSaveFile() && gameModel->GetSaveFile()->GetGameSave())
|
||||||
{
|
{
|
||||||
|
HistorySnapshot();
|
||||||
gameModel->SetSaveFile(gameModel->GetSaveFile());
|
gameModel->SetSaveFile(gameModel->GetSaveFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,6 @@ GameModel::GameModel():
|
|||||||
currentFile(NULL),
|
currentFile(NULL),
|
||||||
currentUser(0, ""),
|
currentUser(0, ""),
|
||||||
toolStrength(1.0f),
|
toolStrength(1.0f),
|
||||||
allowHistory(false),
|
|
||||||
redoHistory(NULL),
|
redoHistory(NULL),
|
||||||
historyPosition(0),
|
historyPosition(0),
|
||||||
activeColourPreset(0),
|
activeColourPreset(0),
|
||||||
|
@@ -64,7 +64,6 @@ private:
|
|||||||
Tool * regularToolset[4];
|
Tool * regularToolset[4];
|
||||||
User currentUser;
|
User currentUser;
|
||||||
float toolStrength;
|
float toolStrength;
|
||||||
bool allowHistory;
|
|
||||||
std::deque<Snapshot*> history;
|
std::deque<Snapshot*> history;
|
||||||
Snapshot *redoHistory;
|
Snapshot *redoHistory;
|
||||||
unsigned int historyPosition;
|
unsigned int historyPosition;
|
||||||
@@ -132,8 +131,6 @@ public:
|
|||||||
void BuildFavoritesMenu();
|
void BuildFavoritesMenu();
|
||||||
void BuildQuickOptionMenu(GameController * controller);
|
void BuildQuickOptionMenu(GameController * controller);
|
||||||
|
|
||||||
bool GetAllowHistory() { return allowHistory; }
|
|
||||||
void SetAllowHistory() { allowHistory = true; }
|
|
||||||
std::deque<Snapshot*> GetHistory();
|
std::deque<Snapshot*> GetHistory();
|
||||||
unsigned int GetHistoryPosition();
|
unsigned int GetHistoryPosition();
|
||||||
void SetHistory(std::deque<Snapshot*> newHistory);
|
void SetHistory(std::deque<Snapshot*> newHistory);
|
||||||
|
@@ -1035,7 +1035,6 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
|||||||
}
|
}
|
||||||
saveSimulationButton->Enabled = (saveSimulationButtonEnabled || ctrlBehaviour);
|
saveSimulationButton->Enabled = (saveSimulationButtonEnabled || ctrlBehaviour);
|
||||||
SetSaveButtonTooltips();
|
SetSaveButtonTooltips();
|
||||||
c->HistorySnapshot();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::NotifyBrushChanged(GameModel * sender)
|
void GameView::NotifyBrushChanged(GameModel * sender)
|
||||||
|
Reference in New Issue
Block a user