aboutsummaryrefslogtreecommitdiff
path: root/src/sdl/action.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdl/action.c')
-rw-r--r--src/sdl/action.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/sdl/action.c b/src/sdl/action.c
index 415c3f5..18badc1 100644
--- a/src/sdl/action.c
+++ b/src/sdl/action.c
@@ -1,5 +1,8 @@
#include "../core/sok.h"
#include "action.h"
+#include "solve.h"
+#include "game-state.h"
+#include "util.h"
#define CASE_DIGIT \
case SDLK_0: \
@@ -94,20 +97,47 @@ get_wheel_action(
action_t
get_action(
- const SDL_Event * const ev
+ const game_state_t state,
+ const SDL_Event * const ev,
+ const Uint32 solve_event_type
) {
switch (ev->type) {
case SDL_QUIT:
return (action_t) { .type = ACTION_QUIT };
break;
- case SDL_KEYUP:
- return get_key_action(ev->key.keysym.sym);
- break;
case SDL_MOUSEWHEEL:
return get_wheel_action(ev->wheel.y);
break;
+ case SDL_KEYUP:
+ if (state == GAME_STATE_SOLVE) {
+ return (action_t) { .type = ACTION_SOLVE_CANCEL };
+ } else {
+ return get_key_action(ev->key.keysym.sym);
+ }
+ break;
default:
- // ignore event
- return (action_t) { .type = ACTION_NONE };
+ if (state == GAME_STATE_SOLVE && ev->type == solve_event_type) {
+ switch (ev->user.code) {
+ case SOLVE_EVENT_STEP:
+ return (action_t) {
+ .type = ACTION_SOLVE_EVENT_STEP,
+ .data = solve_get_num_steps(ev->user.data1),
+ };
+ break;
+ case SOLVE_EVENT_FAIL:
+ warn("solve failed: %s", ev->user.data2 ? ev->user.data2 : "unknown error");
+ return (action_t) { .type = ACTION_SOLVE_EVENT_FAIL };
+ break;
+ case SOLVE_EVENT_DONE:
+ return (action_t) { .type = ACTION_SOLVE_EVENT_DONE };
+ break;
+ default:
+ // ignore event
+ break;
+ }
+ }
}
+
+ // ignore event
+ return (action_t) { .type = ACTION_NONE };
}