Skip to content

Commit

Permalink
fix unrepeatable keybinds
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Jan 28, 2024
1 parent bc76aa1 commit 76d33f4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/Keybinds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ namespace keybinds {
geode::EventListener<PressBindFilter> m_listener =
geode::EventListener<PressBindFilter>(this, &BindManager::onDispatch);
std::vector<std::pair<ActionID, float>> m_repeating;
std::unordered_set<ActionID> m_held;

BindManager();

Expand Down
12 changes: 11 additions & 1 deletion src/Keybinds.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../include/Keybinds.hpp"
#include "Geode/cocos/robtop/keyboard_dispatcher/CCKeyboardDelegate.h"
#include "Geode/cocos/sprite_nodes/CCSprite.h"
#include "Geode/loader/Event.hpp"
#include <Geode/utils/ranges.hpp>
#include <Geode/utils/string.hpp>
#include <Geode/loader/ModEvent.hpp>
Expand Down Expand Up @@ -750,8 +751,12 @@ void BindManager::setRepeatOptionsFor(ActionID const& action, RepeatOptions cons
ListenerResult BindManager::onDispatch(PressBindEvent* event) {
if (m_binds.contains(event->getBind())) {
for (auto& action : m_binds.at(event->getBind())) {
bool inserted = false;
if (event->isDown()) {
// Ignore OS autorepeating for repeat stuff
if (!m_held.contains(action)) {
m_held.insert(action);
inserted = true;
}
if (auto options = this->getRepeatOptionsFor(action)) {
if (options.value().enabled && ranges::contains(m_repeating, [=](auto const& p) { return p.first == action; })) {
return ListenerResult::Stop;
Expand All @@ -760,8 +765,13 @@ ListenerResult BindManager::onDispatch(PressBindEvent* event) {
this->repeat(action);
}
else {
m_held.erase(action);
this->unrepeat(action);
}
auto options = this->getRepeatOptionsFor(action);
if ((!options.has_value() || !options.value().enabled) && !inserted && m_held.contains(action)) {
return ListenerResult::Stop;
}
if (InvokeBindEvent(action, event->isDown()).post() == ListenerResult::Stop) {
return ListenerResult::Stop;
}
Expand Down
23 changes: 14 additions & 9 deletions src/UILayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,12 @@ struct $modify(UILayer) {
"robtop.geometry-dash/jump-p1",
"Jump P1",
"Player 1 Jump",
{ Keybind::create(KEY_Space), ControllerBind::create(CONTROLLER_A), ControllerBind::create(CONTROLLER_RB) },
{
Keybind::create(KEY_Space),
Keybind::create(KEY_W),
ControllerBind::create(CONTROLLER_A),
ControllerBind::create(CONTROLLER_RB)
},
Category::PLAY,
false
});
Expand All @@ -234,35 +239,35 @@ struct $modify(UILayer) {
});
BindManager::get()->registerBindable({
"robtop.geometry-dash/move-left-p1",
"Move left",
"Move left P1",
"Moves P1 left in platformer mode",
{ Keybind::create(cocos2d::KEY_A), ControllerBind::create(CONTROLLER_Left), ControllerBind::create(CONTROLLER_LTHUMBSTICK_LEFT) },
Category::PLAY,
true
false
});
BindManager::get()->registerBindable({
"robtop.geometry-dash/move-right-p1",
"Move right",
"Move right P1",
"Moves P1 right in platformer mode",
{ Keybind::create(cocos2d::KEY_D), ControllerBind::create(CONTROLLER_Right), ControllerBind::create(CONTROLLER_LTHUMBSTICK_RIGHT) },
Category::PLAY,
true
false
});
BindManager::get()->registerBindable({
"robtop.geometry-dash/move-left-p2",
"Move left",
"Move left P2",
"Moves P2 left in platformer mode",
{ Keybind::create(KEY_Left), ControllerBind::create(CONTROLLER_RTHUMBSTICK_LEFT) },
Category::PLAY,
true
false
});
BindManager::get()->registerBindable({
"robtop.geometry-dash/move-right-p2",
"Move right",
"Move right P2",
"Moves P2 right in platformer mode",
{ Keybind::create(KEY_Right), ControllerBind::create(CONTROLLER_RTHUMBSTICK_RIGHT) },
Category::PLAY,
true
false
});
BindManager::get()->registerBindable({
"robtop.geometry-dash/place-checkpoint",
Expand Down

0 comments on commit 76d33f4

Please sign in to comment.