Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
skhaz committed Dec 19, 2024
1 parent 72d438d commit f57a6b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ enum eventtype : Uint32 {
};

enum class keyevent : int32_t {
w = SDLK_w,
a = SDLK_a,
s = SDLK_s,
d = SDLK_d,
up = SDLK_UP,
left = SDLK_LEFT,
down = SDLK_DOWN,
right = SDLK_RIGHT,
space = SDLK_SPACE,
};

Expand Down
11 changes: 7 additions & 4 deletions src/eventmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "eventmanager.hpp"
#include <SDL_keycode.h>

using namespace input;

Expand All @@ -17,10 +18,10 @@ void eventmanager::update(float_t delta) {
UNUSED(delta);

static constexpr std::array<std::pair<Uint8, SDL_Keycode>, 6> mapping = {{
{SDL_CONTROLLER_BUTTON_DPAD_UP, SDLK_w},
{SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDLK_a},
{SDL_CONTROLLER_BUTTON_DPAD_DOWN, SDLK_s},
{SDL_CONTROLLER_BUTTON_DPAD_RIGHT, SDLK_d},
{SDL_CONTROLLER_BUTTON_DPAD_UP, SDLK_UP},
{SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDLK_LEFT},
{SDL_CONTROLLER_BUTTON_DPAD_DOWN, SDLK_DOWN},
{SDL_CONTROLLER_BUTTON_DPAD_RIGHT, SDLK_RIGHT},
{SDL_CONTROLLER_BUTTON_A, SDLK_SPACE},
{SDL_CONTROLLER_BUTTON_B, SDLK_SPACE},
}};
Expand All @@ -35,12 +36,14 @@ void eventmanager::update(float_t delta) {
break;

case SDL_KEYDOWN:
std::cout << "SDL_KEYDOWN " << event.key.keysym.sym << std::endl;
for (const auto &receiver : _receivers) {
receiver->on_keydown(keyevent(event.key.keysym.sym));
}
break;

case SDL_KEYUP:
std::cout << "SDL_KEYUP " << event.key.keysym.sym << std::endl;
for (const auto &receiver : _receivers) {
receiver->on_keyup(keyevent(event.key.keysym.sym));
}
Expand Down
8 changes: 4 additions & 4 deletions src/scriptengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,10 @@ void scriptengine::run() {

lua.new_enum(
"KeyEvent",
"w", keyevent::w,
"a", keyevent::a,
"s", keyevent::s,
"d", keyevent::d,
"up", keyevent::up,
"left", keyevent::left,
"down", keyevent::down,
"right", keyevent::right,
"space", keyevent::space
);

Expand Down

0 comments on commit f57a6b6

Please sign in to comment.