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>
|
|
|
|
|
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:
|
2021-09-25 10:46:47 +02:00
|
|
|
PlayerScripts(LuaUtil::LuaState* lua, const LObject& obj) : LocalScripts(lua, obj, ESM::LuaScriptCfg::sPlayer)
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
2021-06-26 23:10:24 +02:00
|
|
|
registerEngineHandlers({&mKeyPressHandlers, &mKeyReleaseHandlers,
|
|
|
|
&mControllerButtonPressHandlers, &mControllerButtonReleaseHandlers,
|
2021-11-17 03:05:50 +01:00
|
|
|
&mActionHandlers, &mInputUpdateHandlers});
|
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;
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 23:21:10 +01:00
|
|
|
|
2021-11-17 03:05:50 +01:00
|
|
|
void inputUpdate(float dt) { callEngineHandlers(mInputUpdateHandlers, dt); }
|
|
|
|
|
2020-12-18 23:21:10 +01:00
|
|
|
private:
|
|
|
|
EngineHandlerList mKeyPressHandlers{"onKeyPress"};
|
2021-06-26 23:10:24 +02:00
|
|
|
EngineHandlerList mKeyReleaseHandlers{"onKeyRelease"};
|
|
|
|
EngineHandlerList mControllerButtonPressHandlers{"onControllerButtonPress"};
|
|
|
|
EngineHandlerList mControllerButtonReleaseHandlers{"onControllerButtonRelease"};
|
|
|
|
EngineHandlerList mActionHandlers{"onInputAction"};
|
2021-11-17 03:05:50 +01:00
|
|
|
EngineHandlerList mInputUpdateHandlers{"onInputUpdate"};
|
2020-12-18 23:21:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MWLUA_PLAYERSCRIPTS_H
|