mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-25 16:43:33 +00:00
Change argument of onKeyPress
This commit is contained in:
parent
b1a6441c23
commit
cc7dbabd19
@ -1,5 +1,7 @@
|
|||||||
#include "luabindings.hpp"
|
#include "luabindings.hpp"
|
||||||
|
|
||||||
|
#include <SDL_events.h>
|
||||||
|
|
||||||
#include <components/lua/luastate.hpp>
|
#include <components/lua/luastate.hpp>
|
||||||
#include <components/queries/luabindings.hpp>
|
#include <components/queries/luabindings.hpp>
|
||||||
|
|
||||||
@ -8,6 +10,12 @@
|
|||||||
#include "eventqueue.hpp"
|
#include "eventqueue.hpp"
|
||||||
#include "worldview.hpp"
|
#include "worldview.hpp"
|
||||||
|
|
||||||
|
namespace sol
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct is_automagical<SDL_Keysym> : std::false_type {};
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -160,5 +168,17 @@ namespace MWLua
|
|||||||
return context.mLua->makeReadOnly(res);
|
return context.mLua->makeReadOnly(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initInputBindings(const Context& context)
|
||||||
|
{
|
||||||
|
sol::usertype<SDL_Keysym> keyEvent = context.mLua->sol().new_usertype<SDL_Keysym>("KeyEvent");
|
||||||
|
keyEvent["symbol"] = sol::readonly_property([](const SDL_Keysym& e) { return std::string(1, static_cast<char>(e.sym)); });
|
||||||
|
keyEvent["code"] = sol::readonly_property([](const SDL_Keysym& e) -> int { return e.sym; });
|
||||||
|
keyEvent["modifiers"] = sol::readonly_property([](const SDL_Keysym& e) -> int { return e.mod; });
|
||||||
|
keyEvent["withShift"] = sol::readonly_property([](const SDL_Keysym& e) -> bool { return e.mod & KMOD_SHIFT; });
|
||||||
|
keyEvent["withCtrl"] = sol::readonly_property([](const SDL_Keysym& e) -> bool { return e.mod & KMOD_CTRL; });
|
||||||
|
keyEvent["withAlt"] = sol::readonly_property([](const SDL_Keysym& e) -> bool { return e.mod & KMOD_ALT; });
|
||||||
|
keyEvent["withSuper"] = sol::readonly_property([](const SDL_Keysym& e) -> bool { return e.mod & KMOD_GUI; });
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ namespace MWLua
|
|||||||
|
|
||||||
sol::table initFieldGroup(const Context&, const QueryFieldGroup&);
|
sol::table initFieldGroup(const Context&, const QueryFieldGroup&);
|
||||||
|
|
||||||
|
void initInputBindings(const Context&);
|
||||||
|
|
||||||
// Implemented in objectbindings.cpp
|
// Implemented in objectbindings.cpp
|
||||||
void initObjectBindingsForLocalScripts(const Context&);
|
void initObjectBindingsForLocalScripts(const Context&);
|
||||||
void initObjectBindingsForGlobalScripts(const Context&);
|
void initObjectBindingsForGlobalScripts(const Context&);
|
||||||
|
@ -48,6 +48,7 @@ namespace MWLua
|
|||||||
initObjectBindingsForLocalScripts(localContext);
|
initObjectBindingsForLocalScripts(localContext);
|
||||||
initCellBindingsForLocalScripts(localContext);
|
initCellBindingsForLocalScripts(localContext);
|
||||||
LocalScripts::initializeSelfPackage(localContext);
|
LocalScripts::initializeSelfPackage(localContext);
|
||||||
|
initInputBindings(localContext);
|
||||||
|
|
||||||
mLua.addCommonPackage("openmw.async", getAsyncPackageInitializer(context));
|
mLua.addCommonPackage("openmw.async", getAsyncPackageInitializer(context));
|
||||||
mLua.addCommonPackage("openmw.util", LuaUtil::initUtilPackage(mLua.sol()));
|
mLua.addCommonPackage("openmw.util", LuaUtil::initUtilPackage(mLua.sol()));
|
||||||
@ -153,8 +154,8 @@ namespace MWLua
|
|||||||
// Engine handlers in local scripts
|
// Engine handlers in local scripts
|
||||||
if (mPlayerScripts)
|
if (mPlayerScripts)
|
||||||
{
|
{
|
||||||
for (const SDL_Keysym key : mKeyPressEvents)
|
for (const SDL_Keysym& key : mKeyPressEvents)
|
||||||
mPlayerScripts->keyPress(key.sym, key.mod);
|
mPlayerScripts->keyPress(key);
|
||||||
}
|
}
|
||||||
mKeyPressEvents.clear();
|
mKeyPressEvents.clear();
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef MWLUA_PLAYERSCRIPTS_H
|
#ifndef MWLUA_PLAYERSCRIPTS_H
|
||||||
#define MWLUA_PLAYERSCRIPTS_H
|
#define MWLUA_PLAYERSCRIPTS_H
|
||||||
|
|
||||||
|
#include <SDL_events.h>
|
||||||
|
|
||||||
#include "localscripts.hpp"
|
#include "localscripts.hpp"
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
@ -14,7 +16,7 @@ namespace MWLua
|
|||||||
registerEngineHandlers({&mKeyPressHandlers});
|
registerEngineHandlers({&mKeyPressHandlers});
|
||||||
}
|
}
|
||||||
|
|
||||||
void keyPress(int sym, int mod) { callEngineHandlers(mKeyPressHandlers, sym, mod); }
|
void keyPress(const SDL_Keysym& key) { callEngineHandlers(mKeyPressHandlers, key); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EngineHandlerList mKeyPressHandlers{"onKeyPress"};
|
EngineHandlerList mKeyPressHandlers{"onKeyPress"};
|
||||||
|
@ -163,6 +163,7 @@ namespace LuaUtil
|
|||||||
void registerEngineHandlers(std::initializer_list<EngineHandlerList*> handlers);
|
void registerEngineHandlers(std::initializer_list<EngineHandlerList*> handlers);
|
||||||
|
|
||||||
const std::string mNamePrefix;
|
const std::string mNamePrefix;
|
||||||
|
LuaUtil::LuaState& mLua;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Script
|
struct Script
|
||||||
@ -190,7 +191,6 @@ namespace LuaUtil
|
|||||||
void updateTimerQueue(std::vector<Timer>& timerQueue, double time);
|
void updateTimerQueue(std::vector<Timer>& timerQueue, double time);
|
||||||
static void insertTimer(std::vector<Timer>& timerQueue, Timer&& t);
|
static void insertTimer(std::vector<Timer>& timerQueue, Timer&& t);
|
||||||
|
|
||||||
LuaUtil::LuaState& mLua;
|
|
||||||
const UserdataSerializer* mSerializer = nullptr;
|
const UserdataSerializer* mSerializer = nullptr;
|
||||||
std::map<std::string, sol::object> API;
|
std::map<std::string, sol::object> API;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user