diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index fc8e00676..20324082e 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -14,11 +14,7 @@ #include "Tool.h" #include "GameControllerEvents.h" -#ifdef LUACONSOLE -# include "lua/LuaScriptInterface.h" -#else -# include "lua/TPTScriptInterface.h" -#endif +#include "lua/CommandInterface.h" #include "client/Client.h" #include "client/GameSave.h" @@ -94,11 +90,7 @@ GameController::GameController(): gameView->SetDebugHUD(Client::Ref().GetPrefBool("Renderer.DebugMode", false)); -#ifdef LUACONSOLE - commandInterface = new LuaScriptInterface(this, gameModel); -#else - commandInterface = new TPTScriptInterface(this, gameModel); -#endif + commandInterface = CommandInterface::Create(this, gameModel); Client::Ref().AddListener(this); @@ -733,9 +725,7 @@ void GameController::Tick() { if(firstTick) { -#ifdef LUACONSOLE - ((LuaScriptInterface*)commandInterface)->Init(); -#endif + commandInterface->Init(); #if !defined(MACOSX) if constexpr (INSTALL_CHECK) { diff --git a/src/lua/CommandInterface.h b/src/lua/CommandInterface.h index 692b31a8e..d5513ffad 100644 --- a/src/lua/CommandInterface.h +++ b/src/lua/CommandInterface.h @@ -14,15 +14,17 @@ protected: String lastError; GameModel * m; GameController * c; + CommandInterface(GameController * c, GameModel * m); + public: enum LogType { LogError, LogWarning, LogNotice }; enum FormatType { FormatInt, FormatString, FormatChar, FormatFloat, FormatElement }; - CommandInterface(GameController * c, GameModel * m); int GetPropertyOffset(ByteString key, FormatType & format); void Log(LogType type, String message); //void AttachGameModel(GameModel * m); virtual void OnTick() { } + virtual void Init() { } virtual bool HandleEvent(const GameControllerEvent &event) { return true; } @@ -34,4 +36,6 @@ public: } String GetLastError(); virtual ~CommandInterface(); + + static CommandInterface *Create(GameController * c, GameModel * m); }; diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 8ccd33ba0..7ea42683c 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -1,5 +1,4 @@ #include "Config.h" -#ifdef LUACONSOLE #include "client/http/Request.h" // includes curl.h, needs to come first to silence a warning on windows #include "bzip2/bz2wrap.h" @@ -5029,4 +5028,7 @@ bool tpt_lua_equalsString(lua_State *L, int index, const char *data, size_t size return lua_isstring(L, index) && lua_objlen(L, index) == size && !memcmp(lua_tostring(L, index), data, size); } -#endif +CommandInterface *CommandInterface::Create(GameController * c, GameModel * m) +{ + return new LuaScriptInterface(c, m); +} diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index e8eaad9cf..363c8065a 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -215,7 +215,7 @@ public: void OnTick() override; bool HandleEvent(const GameControllerEvent &event) override; - void Init(); + void Init() override; void SetWindow(ui::Window * window); int Command(String command) override; String FormatCommand(String command) override; diff --git a/src/lua/PlainCommandInterface.cpp b/src/lua/PlainCommandInterface.cpp new file mode 100644 index 000000000..9763f82fa --- /dev/null +++ b/src/lua/PlainCommandInterface.cpp @@ -0,0 +1,7 @@ +#include "CommandInterface.h" +#include "TPTScriptInterface.h" + +CommandInterface *CommandInterface::Create(GameController * c, GameModel * m) +{ + return new TPTScriptInterface(c, m); +} diff --git a/src/lua/TPTScriptInterface.cpp b/src/lua/TPTScriptInterface.cpp index 66d63f5d6..3a05e5666 100644 --- a/src/lua/TPTScriptInterface.cpp +++ b/src/lua/TPTScriptInterface.cpp @@ -610,7 +610,3 @@ AnyType TPTScriptInterface::tptS_quit(std::deque * words) return NumberType(0); } - -TPTScriptInterface::~TPTScriptInterface() { -} - diff --git a/src/lua/TPTScriptInterface.h b/src/lua/TPTScriptInterface.h index 3aaaf8083..ef1f760a7 100644 --- a/src/lua/TPTScriptInterface.h +++ b/src/lua/TPTScriptInterface.h @@ -6,7 +6,6 @@ #include class TPTScriptInterface: public CommandInterface { -protected: AnyType eval(std::deque * words); int parseNumber(String str); AnyType tptS_set(std::deque * words); @@ -21,5 +20,4 @@ public: TPTScriptInterface(GameController * c, GameModel * m); int Command(String command) override; String FormatCommand(String command) override; - virtual ~TPTScriptInterface(); }; diff --git a/src/meson.build b/src/meson.build index 1aee21f8b..c6ed7006d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -33,6 +33,10 @@ subdir('graphics') subdir('gui') if lua_variant != 'none' subdir('lua') +else + powder_files += files( + 'lua/PlainCommandInterface.cpp', + ) endif subdir('resampler') subdir('simulation')