Avoid making engine handler methods public

ini_importer_tests
uramer 12 months ago
parent 4ed2af7666
commit dd6017e81e

@ -3,18 +3,17 @@
#include <SDL_events.h> #include <SDL_events.h>
#include <components/lua/luastate.hpp>
#include <components/lua/scriptscontainer.hpp>
#include <components/sdlutil/events.hpp> #include <components/sdlutil/events.hpp>
#include "../mwbase/luamanager.hpp" #include "../mwbase/luamanager.hpp"
namespace MWLua namespace MWLua
{ {
template <class Container>
class InputProcessor class InputProcessor
{ {
public: public:
InputProcessor(LuaUtil::ScriptsContainer* scriptsContainer) InputProcessor(Container* scriptsContainer)
: mScriptsContainer(scriptsContainer) : mScriptsContainer(scriptsContainer)
{ {
mScriptsContainer->registerEngineHandlers({ &mKeyPressHandlers, &mKeyReleaseHandlers, mScriptsContainer->registerEngineHandlers({ &mKeyPressHandlers, &mKeyReleaseHandlers,
@ -58,15 +57,15 @@ namespace MWLua
} }
private: private:
LuaUtil::ScriptsContainer* mScriptsContainer; Container* mScriptsContainer;
LuaUtil::ScriptsContainer::EngineHandlerList mKeyPressHandlers{ "onKeyPress" }; Container::EngineHandlerList mKeyPressHandlers{ "onKeyPress" };
LuaUtil::ScriptsContainer::EngineHandlerList mKeyReleaseHandlers{ "onKeyRelease" }; Container::EngineHandlerList mKeyReleaseHandlers{ "onKeyRelease" };
LuaUtil::ScriptsContainer::EngineHandlerList mControllerButtonPressHandlers{ "onControllerButtonPress" }; Container::EngineHandlerList mControllerButtonPressHandlers{ "onControllerButtonPress" };
LuaUtil::ScriptsContainer::EngineHandlerList mControllerButtonReleaseHandlers{ "onControllerButtonRelease" }; Container::EngineHandlerList mControllerButtonReleaseHandlers{ "onControllerButtonRelease" };
LuaUtil::ScriptsContainer::EngineHandlerList mActionHandlers{ "onInputAction" }; Container::EngineHandlerList mActionHandlers{ "onInputAction" };
LuaUtil::ScriptsContainer::EngineHandlerList mTouchpadPressed{ "onTouchPress" }; Container::EngineHandlerList mTouchpadPressed{ "onTouchPress" };
LuaUtil::ScriptsContainer::EngineHandlerList mTouchpadReleased{ "onTouchRelease" }; Container::EngineHandlerList mTouchpadReleased{ "onTouchRelease" };
LuaUtil::ScriptsContainer::EngineHandlerList mTouchpadMoved{ "onTouchMove" }; Container::EngineHandlerList mTouchpadMoved{ "onTouchMove" };
}; };
} }

@ -45,7 +45,8 @@ namespace MWLua
void uiModeChanged() { callEngineHandlers(mUiModeChanged); } void uiModeChanged() { callEngineHandlers(mUiModeChanged); }
private: private:
MWLua::InputProcessor mInputProcessor; friend class MWLua::InputProcessor<MenuScripts>;
MWLua::InputProcessor<MenuScripts> mInputProcessor;
EngineHandlerList mOnFrameHandlers{ "onFrame" }; EngineHandlerList mOnFrameHandlers{ "onFrame" };
EngineHandlerList mStateChanged{ "onStateChanged" }; EngineHandlerList mStateChanged{ "onStateChanged" };
EngineHandlerList mConsoleCommandHandlers{ "onConsoleCommand" }; EngineHandlerList mConsoleCommandHandlers{ "onConsoleCommand" };

@ -48,7 +48,8 @@ namespace MWLua
} }
private: private:
InputProcessor mInputProcessor; friend class MWLua::InputProcessor<PlayerScripts>;
InputProcessor<PlayerScripts> mInputProcessor;
EngineHandlerList mConsoleCommandHandlers{ "onConsoleCommand" }; EngineHandlerList mConsoleCommandHandlers{ "onConsoleCommand" };
EngineHandlerList mOnFrameHandlers{ "onFrame" }; EngineHandlerList mOnFrameHandlers{ "onFrame" };
EngineHandlerList mQuestUpdate{ "onQuestUpdate" }; EngineHandlerList mQuestUpdate{ "onQuestUpdate" };

@ -157,8 +157,7 @@ namespace LuaUtil
void collectStats(std::vector<ScriptStats>& stats) const; void collectStats(std::vector<ScriptStats>& stats) const;
static int64_t getInstanceCount() { return sInstanceCount; } static int64_t getInstanceCount() { return sInstanceCount; }
public: // TODO: public to be available to MWLua::InputProcessor. Consider other ways of reusing engine handlers protected:
// between containers
struct Handler struct Handler
{ {
int mScriptId; int mScriptId;
@ -199,7 +198,6 @@ namespace LuaUtil
// a public function (see how ScriptsContainer::update is implemented) that calls `callEngineHandlers`. // a public function (see how ScriptsContainer::update is implemented) that calls `callEngineHandlers`.
void registerEngineHandlers(std::initializer_list<EngineHandlerList*> handlers); void registerEngineHandlers(std::initializer_list<EngineHandlerList*> handlers);
protected:
const std::string mNamePrefix; const std::string mNamePrefix;
LuaUtil::LuaState& mLua; LuaUtil::LuaState& mLua;

Loading…
Cancel
Save