diff --git a/src/game.c b/src/game.c index 20ac6a09..9c45c05d 100644 --- a/src/game.c +++ b/src/game.c @@ -19,14 +19,6 @@ #include "game/settings.h" #include "game/credits.h" -typedef enum Game_state { - GAME_STATE_LEVEL = 0, - GAME_STATE_LEVEL_PICKER, - GAME_STATE_LEVEL_EDITOR, - GAME_STATE_CREDITS, - GAME_STATE_SETTINGS, - GAME_STATE_QUIT -} Game_state; typedef struct Game { Lt *lt; @@ -46,7 +38,6 @@ typedef struct Game { int console_enabled; } Game; -static void game_switch_state(Game *game, Game_state state) { game->camera = create_camera(game->renderer, game->font); @@ -368,7 +359,6 @@ static int game_event_level_picker(Game *game, const SDL_Event *event) return -1; } - level_picker_clean_selection(game->level_picker); game_switch_state(game, GAME_STATE_LEVEL); } break; @@ -462,15 +452,6 @@ int game_event(Game *game, const SDL_Event *event) } break; } } break; - case SDL_KEYDOWN: { - switch (event->key.keysym.sym) { - case SDLK_ESCAPE: { - if (game->state == GAME_STATE_LEVEL) { - game_switch_state(game, GAME_STATE_LEVEL_PICKER); - } - } break; - } - } break; } } @@ -594,7 +575,6 @@ int game_load_level(Game *game, const char *level_filename) return -1; } - level_picker_clean_selection(game->level_picker); game_switch_state(game, GAME_STATE_LEVEL); return 0; diff --git a/src/game.h b/src/game.h index 49359823..0770dd81 100644 --- a/src/game.h +++ b/src/game.h @@ -24,6 +24,16 @@ int game_input(Game *game, int game_over_check(const Game *game); +typedef enum Game_state { + GAME_STATE_LEVEL = 0, + GAME_STATE_LEVEL_PICKER, + GAME_STATE_LEVEL_EDITOR, + GAME_STATE_CREDITS, + GAME_STATE_SETTINGS, + GAME_STATE_QUIT +} Game_state; + +void game_switch_state(Game *game, Game_state state); int game_load_level(Game *game, const char *filepath); // defined in main.c. is there a better place for this to be declared? diff --git a/src/ui/console.c b/src/ui/console.c index 7040e313..e3802722 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -170,6 +170,10 @@ static int console_eval_input(Console *console) if (game_load_level(console->game, level_name) < 0) { console_log_push_line(console->console_log, "Could not load level", NULL, CONSOLE_ERROR); } + } else if (token_equals_str(command, "menu")) { + console_log_push_line(console->console_log, "Loading menu", NULL, CONSOLE_FOREGROUND); + level_picker_clean_selection(console->game->level_picker); + game_switch_state(console->game, GAME_STATE_LEVEL_PICKER); } else { console_log_push_line(console->console_log, "Unknown command", NULL, CONSOLE_ERROR); }