reworked context state handling
This commit is contained in:
parent
5eb4437ac4
commit
7528ed007e
4 changed files with 28 additions and 30 deletions
|
|
@ -18,6 +18,12 @@
|
|||
|
||||
#include "kubo_context.h"
|
||||
|
||||
const struct kubo_context_state_data kubo_context_states[] = {
|
||||
{.id = KUBO_CONTEXT_NORMAL, .label = "Normal", .color = BLACK},
|
||||
{.id = KUBO_CONTEXT_COMMAND, .label = "Command", .color = RED},
|
||||
{.id = KUBO_CONTEXT_WALL_NEW, .label = "Wall New", .color = GREEN},
|
||||
{.id = KUBO_CONTEXT_WALL_SELECT, .label = "Wall Select", .color = BLUE}};
|
||||
|
||||
void kubo_context_init(struct kubo_context *context) {
|
||||
if (!context) {
|
||||
return;
|
||||
|
|
@ -28,7 +34,7 @@ void kubo_context_init(struct kubo_context *context) {
|
|||
context->wall_select_index = 0;
|
||||
context->exit_pending = false;
|
||||
|
||||
context->state = KUBO_CONTEXT_NORMAL;
|
||||
context->state = kubo_context_states[KUBO_CONTEXT_NORMAL];
|
||||
}
|
||||
|
||||
void kubo_context_cleanup(struct kubo_context *context) {
|
||||
|
|
@ -39,9 +45,9 @@ void kubo_context_cleanup(struct kubo_context *context) {
|
|||
void kubo_context_set_state(struct kubo_context *context,
|
||||
enum kubo_context_state state) {
|
||||
kubo_char_arr_clear(&context->command);
|
||||
context->state = state;
|
||||
context->state = kubo_context_states[state];
|
||||
|
||||
switch (context->state) {
|
||||
switch (context->state.id) {
|
||||
case KUBO_CONTEXT_COMMAND:
|
||||
kubo_char_arr_add(&context->command, ':');
|
||||
break;
|
||||
|
|
@ -58,14 +64,6 @@ void kubo_context_set_state(struct kubo_context *context,
|
|||
}
|
||||
}
|
||||
|
||||
const char *kubo_context_get_label(enum kubo_context_state state) {
|
||||
return kubo_context_labels[state];
|
||||
}
|
||||
|
||||
Color kubo_context_get_color(enum kubo_context_state state) {
|
||||
return kubo_context_colors[state];
|
||||
}
|
||||
|
||||
void kubo_context_accept_cmd(struct kubo_context *context) {
|
||||
printf("accepting cmd %s\n", kubo_char_arr_build_str(&context->command));
|
||||
kubo_context_set_state(context, KUBO_CONTEXT_NORMAL);
|
||||
|
|
@ -73,7 +71,7 @@ void kubo_context_accept_cmd(struct kubo_context *context) {
|
|||
|
||||
struct kubo_wall *kubo_context_get_pending_wall(struct kubo_context *context) {
|
||||
|
||||
if (context->state != KUBO_CONTEXT_WALL_NEW) {
|
||||
if (context->state.id != KUBO_CONTEXT_WALL_NEW) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +95,8 @@ struct kubo_wall *kubo_context_get_pending_wall(struct kubo_context *context) {
|
|||
}
|
||||
|
||||
void kubo_context_select_next_wall(struct kubo_context *context) {
|
||||
if (context->state != KUBO_CONTEXT_WALL_SELECT || !context->walls.count) {
|
||||
if (context->state.id != KUBO_CONTEXT_WALL_SELECT ||
|
||||
!context->walls.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +107,8 @@ void kubo_context_select_next_wall(struct kubo_context *context) {
|
|||
}
|
||||
|
||||
void kubo_context_select_prev_wall(struct kubo_context *context) {
|
||||
if (context->state != KUBO_CONTEXT_WALL_SELECT || !context->walls.count) {
|
||||
if (context->state.id != KUBO_CONTEXT_WALL_SELECT ||
|
||||
!context->walls.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue