diff options
Diffstat (limited to 'source/game/scripting')
-rw-r--r-- | source/game/scripting/StarInputLuaBindings.cpp | 36 | ||||
-rw-r--r-- | source/game/scripting/StarInputLuaBindings.hpp | 17 | ||||
-rw-r--r-- | source/game/scripting/StarLuaComponents.hpp | 8 |
3 files changed, 61 insertions, 0 deletions
diff --git a/source/game/scripting/StarInputLuaBindings.cpp b/source/game/scripting/StarInputLuaBindings.cpp new file mode 100644 index 0000000..5195e31 --- /dev/null +++ b/source/game/scripting/StarInputLuaBindings.cpp @@ -0,0 +1,36 @@ +#include "StarInputLuaBindings.hpp" +#include "StarLuaGameConverters.hpp" +#include "StarInput.hpp" + +namespace Star { + +LuaCallbacks LuaBindings::makeInputCallbacks() { + LuaCallbacks callbacks; + + auto input = Input::singletonPtr(); + + callbacks.registerCallbackWithSignature<Maybe<unsigned>, String, String>("bindDown", bind(mem_fn(&Input::bindDown), input, _1, _2)); + callbacks.registerCallbackWithSignature<bool, String, String>("bindHeld", bind(mem_fn(&Input::bindHeld), input, _1, _2)); + callbacks.registerCallbackWithSignature<Maybe<unsigned>, String, String>("bindUp", bind(mem_fn(&Input::bindUp), input, _1, _2)); + + callbacks.registerCallbackWithSignature<void, String, String>("resetBinds", bind(mem_fn(&Input::resetBinds), input, _1, _2)); + callbacks.registerCallbackWithSignature<void, String, String, Json>("setBinds", bind(mem_fn(&Input::setBinds), input, _1, _2, _3)); + callbacks.registerCallbackWithSignature<Json, String, String>("getDefaultBinds", bind(mem_fn(&Input::getDefaultBinds), input, _1, _2)); + callbacks.registerCallbackWithSignature<Json, String, String>("getBinds", bind(mem_fn(&Input::getBinds), input, _1, _2)); + + callbacks.registerCallback("events", [input]() -> Json { + JsonArray result; + + for (auto& pair : input->inputEventsThisFrame()) { + if (auto jEvent = Input::inputEventToJson(pair.first)) + result.emplace_back(jEvent.set("processed", pair.second)); + } + + return move(result); + }); + + return callbacks; +} + + +} diff --git a/source/game/scripting/StarInputLuaBindings.hpp b/source/game/scripting/StarInputLuaBindings.hpp new file mode 100644 index 0000000..f0c1f4d --- /dev/null +++ b/source/game/scripting/StarInputLuaBindings.hpp @@ -0,0 +1,17 @@ +#ifndef STAR_INPUT_LUA_BINDINGS_HPP +#define STAR_INPUT_LUA_BINDINGS_HPP + +#include "StarGameTypes.hpp" +#include "StarLua.hpp" + +namespace Star { + +STAR_CLASS(Input); + +namespace LuaBindings { + LuaCallbacks makeInputCallbacks(); +} + +} + +#endif diff --git a/source/game/scripting/StarLuaComponents.hpp b/source/game/scripting/StarLuaComponents.hpp index f370679..ac18106 100644 --- a/source/game/scripting/StarLuaComponents.hpp +++ b/source/game/scripting/StarLuaComponents.hpp @@ -6,6 +6,7 @@ #include "StarListener.hpp" #include "StarWorld.hpp" #include "StarWorldLuaBindings.hpp" +#include "StarInputLuaBindings.hpp" namespace Star { @@ -282,6 +283,11 @@ void LuaWorldComponent<Base>::init(World* world) { Base::setLuaRoot(world->luaRoot()); Base::addCallbacks("world", LuaBindings::makeWorldCallbacks(world)); + + if (world->isClient()) { + Base::addCallbacks("input", LuaBindings::makeInputCallbacks()); + } + Base::init(); } @@ -289,6 +295,8 @@ template <typename Base> void LuaWorldComponent<Base>::uninit() { Base::uninit(); Base::removeCallbacks("world"); + + Base::removeCallbacks("input"); } template <typename Base> |