fix 'mouse:' input prefix is not available

This commit is contained in:
MihailRis 2026-10-06 12:53:50 +03:00
parent 99a62710b8
commit cf35023adf
6 changed files with 18 additions and 7 deletions

View file

@ -8,7 +8,7 @@ using runnable = std::function<void()>;
template<class T> using supplier = std::function<T()>; template<class T> using supplier = std::function<T()>;
template<class T> using consumer = std::function<void(T)>; template<class T> using consumer = std::function<void(T)>;
using KeyCallback = std::function<bool()>; using InputCallback = std::function<bool()>;
// data sources // data sources
using wstringsupplier = std::function<std::wstring()>; using wstringsupplier = std::function<std::wstring()>;

View file

@ -44,10 +44,13 @@ static int l_add_callback(lua::State* L) {
auto& input = engine->getInput(); auto& input = engine->getInput();
if (pos != std::string::npos) { if (pos != std::string::npos) {
std::string prefix = bindname.substr(0, pos); auto prefix = std::string_view(bindname).substr(0, pos);
if (prefix == "key") { if (prefix == "key") {
auto key = input_util::keycode_from(bindname.substr(pos + 1)); auto key = input_util::keycode_from(bindname.substr(pos + 1));
handler = input.addKeyCallback(key, actual_callback); handler = input.addKeyCallback(key, actual_callback);
} else if (prefix == "mouse") {
auto mouse = input_util::mousecode_from(bindname.substr(pos + 1));
handler = input.addMouseCallback(mouse, actual_callback);
} }
} }

View file

@ -263,7 +263,7 @@ runnable lua::create_runnable(State* L) {
}; };
} }
KeyCallback lua::create_simple_handler(State* L) { InputCallback lua::create_simple_handler(State* L) {
auto funcptr = create_lambda_handler(L); auto funcptr = create_lambda_handler(L);
return [=]() -> bool { return [=]() -> bool {
if (!get_from_registry(L, LAMBDAS_TABLE, *funcptr, false)) { if (!get_from_registry(L, LAMBDAS_TABLE, *funcptr, false)) {

View file

@ -665,7 +665,7 @@ namespace lua {
} }
runnable create_runnable(lua::State*); runnable create_runnable(lua::State*);
KeyCallback create_simple_handler(lua::State*); InputCallback create_simple_handler(lua::State*);
scripting::common_func create_lambda(lua::State*); scripting::common_func create_lambda(lua::State*);
scripting::common_func create_lambda_nothrow(lua::State*); scripting::common_func create_lambda_nothrow(lua::State*);

View file

@ -216,10 +216,17 @@ public:
return bindings; return bindings;
} }
ObserverHandler addKeyCallback(Keycode key, KeyCallback callback) override { ObserverHandler addKeyCallback(Keycode key, InputCallback callback) override {
return keyCallbacks[key].add(std::move(callback)); return keyCallbacks[key].add(std::move(callback));
} }
ObserverHandler addMouseCallback(Mousecode button, InputCallback callback) override {
return addKeyCallback(
static_cast<Keycode>(MOUSE_KEYS_OFFSET + static_cast<int>(button)),
std::move(callback)
);
}
const std::vector<Keycode>& getPressedKeys() const override { const std::vector<Keycode>& getPressedKeys() const override {
return pressedKeys; return pressedKeys;
} }

View file

@ -288,12 +288,13 @@ public:
virtual const Bindings& getBindings() const = 0; virtual const Bindings& getBindings() const = 0;
virtual ObserverHandler addKeyCallback(Keycode key, KeyCallback callback) = 0; virtual ObserverHandler addKeyCallback(Keycode key, InputCallback callback) = 0;
virtual ObserverHandler addMouseCallback(Mousecode button, InputCallback callback) = 0;
virtual const std::vector<Keycode>& getPressedKeys() const = 0; virtual const std::vector<Keycode>& getPressedKeys() const = 0;
virtual const std::vector<uint>& getCodepoints() const = 0; virtual const std::vector<uint>& getCodepoints() const = 0;
ObserverHandler addCallback(const std::string& name, KeyCallback callback) { ObserverHandler addCallback(const std::string& name, InputCallback callback) {
return getBindings().require(name).onactived.add(callback); return getBindings().require(name).onactived.add(callback);
} }
}; };