Add sim.historyRestore and sim.historyForward

This commit is contained in:
jacob1 2022-12-22 22:05:05 -05:00
parent 81bd1fd9e7
commit 952c3a6975
No known key found for this signature in database
GPG Key ID: 4E58A32D510E1995
4 changed files with 29 additions and 6 deletions

View File

@ -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 &current = *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()

View File

@ -87,9 +87,9 @@ public:
void Install();
void HistoryRestore();
bool HistoryRestore();
void HistorySnapshot();
void HistoryForward();
bool HistoryForward();
void AdjustGridSize(int direction);
void InvertAirSim();

View File

@ -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)

View File

@ -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);