From c3973ae02bbf98c9a23d66b35bc8ab0287876c61 Mon Sep 17 00:00:00 2001 From: Luka Jankovic Date: Sat, 27 Sep 2025 16:42:59 +0200 Subject: [PATCH] added kubo_state_wall_new --- kubo_context.c | 11 ----------- kubo_input.c | 14 +++----------- states/CMakeLists.txt | 1 + states/kubo_state_command.c | 1 - states/kubo_state_normal.c | 17 +++++++++++++++++ states/kubo_state_normal.h | 7 +++++-- states/kubo_state_wall_new.c | 36 ++++++++++++++++++++++++++++++++++++ states/kubo_state_wall_new.h | 32 ++++++++++++++++++++++++++++++++ states/kubo_states.h | 3 ++- 9 files changed, 96 insertions(+), 26 deletions(-) create mode 100644 states/kubo_state_wall_new.c create mode 100644 states/kubo_state_wall_new.h diff --git a/kubo_context.c b/kubo_context.c index ef1adb3..3259afc 100644 --- a/kubo_context.c +++ b/kubo_context.c @@ -46,17 +46,6 @@ void kubo_context_set_state(struct kubo_context *context, enum kubo_context_state state) { context->state = kubo_context_states[state]; - // switch (context->state.id) { - // case KUBO_CONTEXT_COMMAND: - // break; - // - // case KUBO_CONTEXT_WALL_NEW: - // break; - // - // default: - // break; - // } - for (unsigned i = 0; i < kubo_state_data_length; i++) { if (context->state.id == kubo_state_data[i].id && kubo_state_data[i].data.state_entered != NULL) { diff --git a/kubo_input.c b/kubo_input.c index 32d9f7a..0ca009d 100644 --- a/kubo_input.c +++ b/kubo_input.c @@ -50,17 +50,9 @@ static void key_input(struct kubo_context *context, Camera2D *camera) { kubo_context_set_state(context, KUBO_CONTEXT_NORMAL); break; - case KEY_W: - kubo_context_set_state(context, KUBO_CONTEXT_WALL_NEW); - break; - - case KEY_S: - kubo_context_set_state(context, KUBO_CONTEXT_WALL_SELECT); - break; - - case KEY_T: - kubo_mouse_snap = !kubo_mouse_snap; - break; + // case KEY_T: + // kubo_mouse_snap = !kubo_mouse_snap; + // break; case KEY_SPACE: kubo_camera_reset(camera); diff --git a/states/CMakeLists.txt b/states/CMakeLists.txt index bae1297..fe38e91 100644 --- a/states/CMakeLists.txt +++ b/states/CMakeLists.txt @@ -1,6 +1,7 @@ set(STATES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/kubo_state_normal.c ${CMAKE_CURRENT_SOURCE_DIR}/kubo_state_command.c + ${CMAKE_CURRENT_SOURCE_DIR}/kubo_state_wall_new.c ${CMAKE_CURRENT_SOURCE_DIR}/kubo_state_wall_select.c PARENT_SCOPE ) diff --git a/states/kubo_state_command.c b/states/kubo_state_command.c index d30c114..9301a52 100644 --- a/states/kubo_state_command.c +++ b/states/kubo_state_command.c @@ -22,5 +22,4 @@ void kubo_state_command_entered(void *context_data) { struct kubo_context *context = (struct kubo_context *)context_data; (void)context; - printf("hello from state command\n"); } diff --git a/states/kubo_state_normal.c b/states/kubo_state_normal.c index 7692c95..5627629 100644 --- a/states/kubo_state_normal.c +++ b/states/kubo_state_normal.c @@ -17,3 +17,20 @@ */ #include "kubo_state_normal.h" +#include "../kubo_context.h" + +void kubo_state_normal_entered(void *context_data) { (void)context_data; } + +void kubo_state_normal_key(void *context_data, int key_code) { + struct kubo_context *context = (struct kubo_context *)context_data; + + switch (key_code) { + case KEY_W: + kubo_context_set_state(context, KUBO_CONTEXT_WALL_NEW); + break; + + case KEY_S: + kubo_context_set_state(context, KUBO_CONTEXT_WALL_SELECT); + break; + } +} diff --git a/states/kubo_state_normal.h b/states/kubo_state_normal.h index c492ae4..b9cb32e 100644 --- a/states/kubo_state_normal.h +++ b/states/kubo_state_normal.h @@ -23,9 +23,12 @@ #include "kubo_state_data.h" +void kubo_state_normal_entered(void *context_data); +void kubo_state_normal_key(void *context_data, int key_code); + static const struct kubo_state_data kubo_state_normal_data = { - .state_entered = NULL, - .state_key = NULL + .state_entered = kubo_state_normal_entered, + .state_key = kubo_state_normal_key }; #endif diff --git a/states/kubo_state_wall_new.c b/states/kubo_state_wall_new.c new file mode 100644 index 0000000..4692c95 --- /dev/null +++ b/states/kubo_state_wall_new.c @@ -0,0 +1,36 @@ +/* + * Copyright Luka Jankovic 2025 + * + * This file is part of Kubo. + * + * Kubo is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * Kubo is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * Kubo. If not, see . +*/ + +#include "kubo_state_wall_new.h" +#include "../kubo_context.h" + +extern bool kubo_mouse_snap; + +void kubo_state_wall_new_entered(void *context_data) { + struct kubo_context *context = (struct kubo_context *)context_data; + (void)context; +} + +void kubo_state_wall_new_key(void *context_data, int key_code) { + struct kubo_context *context = (struct kubo_context *)context_data; + (void)context; + + if (key_code == KEY_S) { + kubo_mouse_snap = !kubo_mouse_snap; + } +} diff --git a/states/kubo_state_wall_new.h b/states/kubo_state_wall_new.h new file mode 100644 index 0000000..37c029d --- /dev/null +++ b/states/kubo_state_wall_new.h @@ -0,0 +1,32 @@ +/* + * Copyright Luka Jankovic 2025 + * + * This file is part of Kubo. + * + * Kubo is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * Kubo is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * Kubo. If not, see . + */ + +#ifndef KUBO_STATE_WALL_NEW_H +#define KUBO_STATE_WALL_NEW_H + +#include "kubo_state_data.h" + +void kubo_state_wall_new_entered(void *context_data); +void kubo_state_wall_new_key(void *context_data, int key_code); + +static const struct kubo_state_data kubo_state_wall_new_data = { + .state_entered = kubo_state_wall_new_entered, + .state_key = kubo_state_wall_new_key +}; + +#endif diff --git a/states/kubo_states.h b/states/kubo_states.h index 19b9a41..439a7c5 100644 --- a/states/kubo_states.h +++ b/states/kubo_states.h @@ -21,6 +21,7 @@ #include "kubo_state_command.h" #include "kubo_state_normal.h" +#include "kubo_state_wall_new.h" #include "kubo_state_wall_select.h" enum kubo_context_state { @@ -38,7 +39,7 @@ struct kubo_state_list_entry { static const struct kubo_state_list_entry kubo_state_data[] = { { KUBO_CONTEXT_NORMAL, kubo_state_normal_data }, { KUBO_CONTEXT_COMMAND, kubo_state_command_data }, - { KUBO_CONTEXT_WALL_NEW, kubo_state_wall_select_data }, + { KUBO_CONTEXT_WALL_NEW, kubo_state_wall_new_data }, { KUBO_CONTEXT_WALL_SELECT, kubo_state_wall_select_data } };