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 "Tool.h"
|
||||||
|
|
||||||
#include "GameControllerEvents.h"
|
#include "GameControllerEvents.h"
|
||||||
#ifdef LUACONSOLE
|
#include "lua/CommandInterface.h"
|
||||||
# include "lua/LuaScriptInterface.h"
|
|
||||||
#else
|
|
||||||
# include "lua/TPTScriptInterface.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
#include "client/GameSave.h"
|
#include "client/GameSave.h"
|
||||||
@ -94,11 +90,7 @@ GameController::GameController():
|
|||||||
|
|
||||||
gameView->SetDebugHUD(Client::Ref().GetPrefBool("Renderer.DebugMode", false));
|
gameView->SetDebugHUD(Client::Ref().GetPrefBool("Renderer.DebugMode", false));
|
||||||
|
|
||||||
#ifdef LUACONSOLE
|
commandInterface = CommandInterface::Create(this, gameModel);
|
||||||
commandInterface = new LuaScriptInterface(this, gameModel);
|
|
||||||
#else
|
|
||||||
commandInterface = new TPTScriptInterface(this, gameModel);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Client::Ref().AddListener(this);
|
Client::Ref().AddListener(this);
|
||||||
|
|
||||||
@ -733,9 +725,7 @@ void GameController::Tick()
|
|||||||
{
|
{
|
||||||
if(firstTick)
|
if(firstTick)
|
||||||
{
|
{
|
||||||
#ifdef LUACONSOLE
|
commandInterface->Init();
|
||||||
((LuaScriptInterface*)commandInterface)->Init();
|
|
||||||
#endif
|
|
||||||
#if !defined(MACOSX)
|
#if !defined(MACOSX)
|
||||||
if constexpr (INSTALL_CHECK)
|
if constexpr (INSTALL_CHECK)
|
||||||
{
|
{
|
||||||
|
@ -14,15 +14,17 @@ protected:
|
|||||||
String lastError;
|
String lastError;
|
||||||
GameModel * m;
|
GameModel * m;
|
||||||
GameController * c;
|
GameController * c;
|
||||||
|
CommandInterface(GameController * c, GameModel * m);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum LogType { LogError, LogWarning, LogNotice };
|
enum LogType { LogError, LogWarning, LogNotice };
|
||||||
enum FormatType { FormatInt, FormatString, FormatChar, FormatFloat, FormatElement };
|
enum FormatType { FormatInt, FormatString, FormatChar, FormatFloat, FormatElement };
|
||||||
CommandInterface(GameController * c, GameModel * m);
|
|
||||||
int GetPropertyOffset(ByteString key, FormatType & format);
|
int GetPropertyOffset(ByteString key, FormatType & format);
|
||||||
void Log(LogType type, String message);
|
void Log(LogType type, String message);
|
||||||
//void AttachGameModel(GameModel * m);
|
//void AttachGameModel(GameModel * m);
|
||||||
|
|
||||||
virtual void OnTick() { }
|
virtual void OnTick() { }
|
||||||
|
virtual void Init() { }
|
||||||
|
|
||||||
virtual bool HandleEvent(const GameControllerEvent &event) { return true; }
|
virtual bool HandleEvent(const GameControllerEvent &event) { return true; }
|
||||||
|
|
||||||
@ -34,4 +36,6 @@ public:
|
|||||||
}
|
}
|
||||||
String GetLastError();
|
String GetLastError();
|
||||||
virtual ~CommandInterface();
|
virtual ~CommandInterface();
|
||||||
|
|
||||||
|
static CommandInterface *Create(GameController * c, GameModel * m);
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#ifdef LUACONSOLE
|
|
||||||
|
|
||||||
#include "client/http/Request.h" // includes curl.h, needs to come first to silence a warning on windows
|
#include "client/http/Request.h" // includes curl.h, needs to come first to silence a warning on windows
|
||||||
#include "bzip2/bz2wrap.h"
|
#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);
|
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;
|
void OnTick() override;
|
||||||
bool HandleEvent(const GameControllerEvent &event) override;
|
bool HandleEvent(const GameControllerEvent &event) override;
|
||||||
|
|
||||||
void Init();
|
void Init() override;
|
||||||
void SetWindow(ui::Window * window);
|
void SetWindow(ui::Window * window);
|
||||||
int Command(String command) override;
|
int Command(String command) override;
|
||||||
String FormatCommand(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);
|
return NumberType(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TPTScriptInterface::~TPTScriptInterface() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
class TPTScriptInterface: public CommandInterface {
|
class TPTScriptInterface: public CommandInterface {
|
||||||
protected:
|
|
||||||
AnyType eval(std::deque<String> * words);
|
AnyType eval(std::deque<String> * words);
|
||||||
int parseNumber(String str);
|
int parseNumber(String str);
|
||||||
AnyType tptS_set(std::deque<String> * words);
|
AnyType tptS_set(std::deque<String> * words);
|
||||||
@ -21,5 +20,4 @@ public:
|
|||||||
TPTScriptInterface(GameController * c, GameModel * m);
|
TPTScriptInterface(GameController * c, GameModel * m);
|
||||||
int Command(String command) override;
|
int Command(String command) override;
|
||||||
String FormatCommand(String command) override;
|
String FormatCommand(String command) override;
|
||||||
virtual ~TPTScriptInterface();
|
|
||||||
};
|
};
|
||||||
|
@ -33,6 +33,10 @@ subdir('graphics')
|
|||||||
subdir('gui')
|
subdir('gui')
|
||||||
if lua_variant != 'none'
|
if lua_variant != 'none'
|
||||||
subdir('lua')
|
subdir('lua')
|
||||||
|
else
|
||||||
|
powder_files += files(
|
||||||
|
'lua/PlainCommandInterface.cpp',
|
||||||
|
)
|
||||||
endif
|
endif
|
||||||
subdir('resampler')
|
subdir('resampler')
|
||||||
subdir('simulation')
|
subdir('simulation')
|
||||||
|
Loading…
Reference in New Issue
Block a user