1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-28 14:53:58 +00:00
OpenMW/apps/openmw/mwlua/playerscripts.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
3.4 KiB
C++
Raw Normal View History

2020-12-18 23:21:10 +01:00
#ifndef MWLUA_PLAYERSCRIPTS_H
#define MWLUA_PLAYERSCRIPTS_H
2021-07-09 20:18:23 +02:00
#include <SDL_events.h>
#include <components/sdlutil/events.hpp>
2021-06-26 23:10:24 +02:00
#include "../mwbase/luamanager.hpp"
2020-12-18 23:21:10 +01:00
#include "localscripts.hpp"
namespace MWLua
{
class PlayerScripts : public LocalScripts
{
public:
2022-05-20 21:47:13 +02:00
PlayerScripts(LuaUtil::LuaState* lua, const LObject& obj)
: LocalScripts(lua, obj)
2020-12-18 23:21:10 +01:00
{
2022-04-09 23:07:57 +02:00
registerEngineHandlers({ &mConsoleCommandHandlers, &mKeyPressHandlers, &mKeyReleaseHandlers,
&mControllerButtonPressHandlers, &mControllerButtonReleaseHandlers, &mActionHandlers, &mOnFrameHandlers,
&mTouchpadPressed, &mTouchpadReleased, &mTouchpadMoved });
2020-12-18 23:21:10 +01:00
}
2021-06-26 23:10:24 +02:00
void processInputEvent(const MWBase::LuaManager::InputEvent& event)
{
using InputEvent = MWBase::LuaManager::InputEvent;
switch (event.mType)
{
case InputEvent::KeyPressed:
callEngineHandlers(mKeyPressHandlers, std::get<SDL_Keysym>(event.mValue));
break;
case InputEvent::KeyReleased:
callEngineHandlers(mKeyReleaseHandlers, std::get<SDL_Keysym>(event.mValue));
break;
case InputEvent::ControllerPressed:
callEngineHandlers(mControllerButtonPressHandlers, std::get<int>(event.mValue));
break;
case InputEvent::ControllerReleased:
callEngineHandlers(mControllerButtonReleaseHandlers, std::get<int>(event.mValue));
break;
case InputEvent::Action:
callEngineHandlers(mActionHandlers, std::get<int>(event.mValue));
break;
case InputEvent::TouchPressed:
callEngineHandlers(mTouchpadPressed, std::get<SDLUtil::TouchEvent>(event.mValue));
break;
case InputEvent::TouchReleased:
callEngineHandlers(mTouchpadReleased, std::get<SDLUtil::TouchEvent>(event.mValue));
break;
case InputEvent::TouchMoved:
callEngineHandlers(mTouchpadMoved, std::get<SDLUtil::TouchEvent>(event.mValue));
break;
2021-06-26 23:10:24 +02:00
}
}
2020-12-18 23:21:10 +01:00
void onFrame(float dt) { callEngineHandlers(mOnFrameHandlers, dt); }
2022-04-09 23:07:57 +02:00
bool consoleCommand(
const std::string& consoleMode, const std::string& command, const sol::object& selectedObject)
{
callEngineHandlers(mConsoleCommandHandlers, consoleMode, command, selectedObject);
return !mConsoleCommandHandlers.mList.empty();
}
2020-12-18 23:21:10 +01:00
private:
2022-04-09 23:07:57 +02:00
EngineHandlerList mConsoleCommandHandlers{ "onConsoleCommand" };
2020-12-18 23:21:10 +01:00
EngineHandlerList mKeyPressHandlers{ "onKeyPress" };
2021-06-26 23:10:24 +02:00
EngineHandlerList mKeyReleaseHandlers{ "onKeyRelease" };
EngineHandlerList mControllerButtonPressHandlers{ "onControllerButtonPress" };
EngineHandlerList mControllerButtonReleaseHandlers{ "onControllerButtonRelease" };
EngineHandlerList mActionHandlers{ "onInputAction" };
EngineHandlerList mOnFrameHandlers{ "onFrame" };
EngineHandlerList mTouchpadPressed{ "onTouchPress" };
EngineHandlerList mTouchpadReleased{ "onTouchRelease" };
EngineHandlerList mTouchpadMoved{ "onTouchMove" };
2020-12-18 23:21:10 +01:00
};
}
#endif // MWLUA_PLAYERSCRIPTS_H