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

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

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

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

Loading…
Cancel
Save