From 952c3a6975d3c0a1cfce269252bd9b36e9bf9482 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 22 Dec 2022 22:05:05 -0500 Subject: [PATCH] Add sim.historyRestore and sim.historyForward --- src/gui/game/GameController.cpp | 12 ++++++++---- src/gui/game/GameController.h | 4 ++-- src/lua/LuaScriptInterface.cpp | 17 +++++++++++++++++ src/lua/LuaScriptInterface.h | 2 ++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 3a1f1b469..fd942b1e8 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -164,11 +164,11 @@ GameController::~GameController() } } -void GameController::HistoryRestore() +bool GameController::HistoryRestore() { if (!gameModel->HistoryCanRestore()) { - return; + return false; } // * When undoing for the first time since the last call to HistorySnapshot, save the current state. // Ctrl+Y needs this in order to bring you back to the point right before your last Ctrl+Z, because @@ -182,6 +182,8 @@ void GameController::HistoryRestore() auto ¤t = *gameModel->HistoryCurrent(); gameModel->GetSimulation()->Restore(current); Client::Ref().OverwriteAuthorInfo(current.Authors); + + return true; } void GameController::HistorySnapshot() @@ -192,11 +194,11 @@ void GameController::HistorySnapshot() gameModel->HistoryPush(gameModel->GetSimulation()->CreateSnapshot()); } -void GameController::HistoryForward() +bool GameController::HistoryForward() { if (!gameModel->HistoryCanForward()) { - return; + return false; } gameModel->HistoryForward(); // * If gameModel has nothing more to give, we've Ctrl+Y'd our way back to the original @@ -208,6 +210,8 @@ void GameController::HistoryForward() { beforeRestore.reset(); } + + return true; } GameView * GameController::GetView() diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index cc6609611..ea61cfd4f 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -87,9 +87,9 @@ public: void Install(); - void HistoryRestore(); + bool HistoryRestore(); void HistorySnapshot(); - void HistoryForward(); + bool HistoryForward(); void AdjustGridSize(int direction); void InvertAirSim(); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index ae0eda947..8d500d0b0 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -935,6 +935,8 @@ void LuaScriptInterface::initSimulationAPI() {"framerender", simulation_framerender}, {"gspeed", simulation_gspeed}, {"takeSnapshot", simulation_takeSnapshot}, + {"historyRestore", simulation_historyRestore}, + {"historyForward", simulation_historyForward}, {"replaceModeFlags", simulation_replaceModeFlags}, {"listCustomGol", simulation_listCustomGol}, {"addCustomGol", simulation_addCustomGol}, @@ -2399,6 +2401,21 @@ int LuaScriptInterface::simulation_takeSnapshot(lua_State * l) return 0; } + +int LuaScriptInterface::simulation_historyRestore(lua_State *l) +{ + bool successful = luacon_controller->HistoryRestore(); + lua_pushboolean(l, successful); + return 1; +} + +int LuaScriptInterface::simulation_historyForward(lua_State *l) +{ + bool successful = luacon_controller->HistoryForward(); + lua_pushboolean(l, successful); + return 1; +} + int LuaScriptInterface::simulation_replaceModeFlags(lua_State *l) { if (lua_gettop(l) == 0) diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index f9e2ac3c8..d009c40ce 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -115,6 +115,8 @@ class LuaScriptInterface: public CommandInterface static int simulation_framerender(lua_State * l); static int simulation_gspeed(lua_State * l); static int simulation_takeSnapshot(lua_State *l); + static int simulation_historyRestore(lua_State *l); + static int simulation_historyForward(lua_State *l); static int simulation_replaceModeFlags(lua_State *l); static int simulation_listCustomGol(lua_State *l); static int simulation_addCustomGol(lua_State *l);