#include <stdio.h>
#include "game.h"
-#include "ui/edit_field.h"
#include "game/level.h"
-#include "ui/console.h"
#include "game/sound_samples.h"
#include "system/error.h"
+#include "system/log.h"
#include "system/lt.h"
+#include "system/nth_alloc.h"
+#include "ui/console.h"
+#include "ui/edit_field.h"
typedef enum Game_state {
GAME_STATE_RUNNING = 0,
return NULL;
}
- Game *game = PUSH_LT(lt, malloc(sizeof(Game)), free);
+ Game *game = PUSH_LT(lt, nth_alloc(sizeof(Game)), free);
if (game == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
RETURN_LT(lt, NULL);
}
- game->level_file_path = PUSH_LT(lt, malloc(sizeof(char) * (strlen(level_file_path) + 1)), free);
+ game->level_file_path = PUSH_LT(lt, nth_alloc(sizeof(char) * (strlen(level_file_path) + 1)), free);
if (game->level_file_path == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
case SDL_KEYDOWN:
switch (event->key.keysym.sym) {
case SDLK_r:
- printf("Reloading the level from '%s'...\n", game->level_file_path);
+ log_info("Reloading the level from '%s'...\n", game->level_file_path);
game->level = RESET_LT(
game->lt,
break;
case SDLK_q:
- printf("Reloading the level's platforms from '%s'...\n", game->level_file_path);
+ log_info("Reloading the level's platforms from '%s'...\n", game->level_file_path);
if (level_reload_preserve_player(game->level, game->level_file_path) < 0) {
print_current_error_msg("Could not reload the level");
game->state = GAME_STATE_QUIT;
camera_toggle_debug_mode(game->camera);
level_toggle_debug_mode(game->level);
break;
-
+ }
+ break;
+ case SDL_KEYUP:
+ switch (event->key.keysym.sym) {
case SDLK_BACKQUOTE:
case SDLK_c:
+ SDL_StartTextInput();
game->state = GAME_STATE_CONSOLE;
- /* TODO(#404): when console is enabled a backquote pressed event sneaks into edit_field a gets inserted */
console_slide_down(game->console);
break;
}
case SDL_KEYDOWN:
switch (event->key.keysym.sym) {
case SDLK_ESCAPE:
- case SDLK_BACKQUOTE:
- case SDLK_c:
+ SDL_StopTextInput();
game->state = GAME_STATE_RUNNING;
return 0;