Hide CommandInterface creation behind a factory
Which is then provided by either a Lua-ful or a Lua-less translation unit.
This commit is contained in:
parent
33edb2e0e4
commit
169aa47685
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
7
src/lua/PlainCommandInterface.cpp
Normal file
7
src/lua/PlainCommandInterface.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "CommandInterface.h"
|
||||
#include "TPTScriptInterface.h"
|
||||
|
||||
CommandInterface *CommandInterface::Create(GameController * c, GameModel * m)
|
||||
{
|
||||
return new TPTScriptInterface(c, m);
|
||||
}
|
@ -610,7 +610,3 @@ AnyType TPTScriptInterface::tptS_quit(std::deque<String> * words)
|
||||
|
||||
return NumberType(0);
|
||||
}
|
||||
|
||||
TPTScriptInterface::~TPTScriptInterface() {
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <deque>
|
||||
|
||||
class TPTScriptInterface: public CommandInterface {
|
||||
protected:
|
||||
AnyType eval(std::deque<String> * words);
|
||||
int parseNumber(String str);
|
||||
AnyType tptS_set(std::deque<String> * words);
|
||||
@ -21,5 +20,4 @@ public:
|
||||
TPTScriptInterface(GameController * c, GameModel * m);
|
||||
int Command(String command) override;
|
||||
String FormatCommand(String command) override;
|
||||
virtual ~TPTScriptInterface();
|
||||
};
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user