#ifndef MWLUA_INPUTPROCESSOR_H #define MWLUA_INPUTPROCESSOR_H #include #include #include "../mwbase/luamanager.hpp" namespace MWLua { template class InputProcessor { public: InputProcessor(Container* scriptsContainer) : mScriptsContainer(scriptsContainer) { mScriptsContainer->registerEngineHandlers({ &mKeyPressHandlers, &mKeyReleaseHandlers, &mControllerButtonPressHandlers, &mControllerButtonReleaseHandlers, &mActionHandlers, &mTouchpadPressed, &mTouchpadReleased, &mTouchpadMoved }); } void processInputEvent(const MWBase::LuaManager::InputEvent& event) { using InputEvent = MWBase::LuaManager::InputEvent; switch (event.mType) { case InputEvent::KeyPressed: mScriptsContainer->callEngineHandlers(mKeyPressHandlers, std::get(event.mValue)); break; case InputEvent::KeyReleased: mScriptsContainer->callEngineHandlers(mKeyReleaseHandlers, std::get(event.mValue)); break; case InputEvent::ControllerPressed: mScriptsContainer->callEngineHandlers(mControllerButtonPressHandlers, std::get(event.mValue)); break; case InputEvent::ControllerReleased: mScriptsContainer->callEngineHandlers( mControllerButtonReleaseHandlers, std::get(event.mValue)); break; case InputEvent::Action: mScriptsContainer->callEngineHandlers(mActionHandlers, std::get(event.mValue)); break; case InputEvent::TouchPressed: mScriptsContainer->callEngineHandlers( mTouchpadPressed, std::get(event.mValue)); break; case InputEvent::TouchReleased: mScriptsContainer->callEngineHandlers( mTouchpadReleased, std::get(event.mValue)); break; case InputEvent::TouchMoved: mScriptsContainer->callEngineHandlers(mTouchpadMoved, std::get(event.mValue)); break; } } private: Container* mScriptsContainer; typename Container::EngineHandlerList mKeyPressHandlers{ "onKeyPress" }; typename Container::EngineHandlerList mKeyReleaseHandlers{ "onKeyRelease" }; typename Container::EngineHandlerList mControllerButtonPressHandlers{ "onControllerButtonPress" }; typename Container::EngineHandlerList mControllerButtonReleaseHandlers{ "onControllerButtonRelease" }; typename Container::EngineHandlerList mActionHandlers{ "onInputAction" }; typename Container::EngineHandlerList mTouchpadPressed{ "onTouchPress" }; typename Container::EngineHandlerList mTouchpadReleased{ "onTouchRelease" }; typename Container::EngineHandlerList mTouchpadMoved{ "onTouchMove" }; }; } #endif // MWLUA_INPUTPROCESSOR_H