From 5df0d0616ee3996add0b14e0fb0becd6257d04a2 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 21 Feb 2021 17:56:17 -0500 Subject: Added a debug console Open it by pressing backtick, close it by hitting escape. Pressing backtick does not open it in release builds. Current shortcomings: opening it for the first time also types a backtick for some reason, but not on subsequent times. Also, it doesn't create a coroutine, so any script function that yields is going to fail. This also added a "is gameplay paused" flag to Game, which will be useful for adding a pause menu. --- src/input_system.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'src/input_system.cpp') diff --git a/src/input_system.cpp b/src/input_system.cpp index 43c59dd..1b5b56b 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp @@ -16,12 +16,42 @@ struct Input { void InputSystem::tick(double dt) { SDL_Event e; while (SDL_PollEvent(&e)) { - if (e.type == SDL_QUIT || (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE)) { + if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) { + if (debugConsole_) { + debugConsole_ = false; + game_.unpauseGameplay(); + SDL_StopTextInput(); + debugText_.clear(); + } else { + game_.quit(); + } + } else if (e.type == SDL_QUIT) { game_.quit(); return; + } else if (e.type == SDL_TEXTINPUT) { + debugText_.append(e.text.text); } else if (e.type == SDL_KEYDOWN) { - if (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT) { + if (e.key.keysym.sym == SDLK_BACKQUOTE) { +#ifdef TANETANE_DEBUG + if (!debugConsole_) { + debugConsole_ = true; + game_.pauseGameplay(); + SDL_StartTextInput(); + debugText_.clear(); + } +#endif + } else if (debugConsole_ && e.key.keysym.sym == SDLK_RETURN) { + game_.getSystem().runDebugScript(debugText_); + debugText_.clear(); + } else if (debugConsole_ && e.key.keysym.sym == SDLK_BACKSPACE) { + // Make sure to keep the backtick/heart. + if (!debugText_.empty()) { + debugText_.pop_back(); + } + } else if (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT) { + if (game_.isGameplayPaused()) continue; + for (int spriteId : game_.getSprites()) { Sprite& sprite = game_.getSprite(spriteId); if (sprite.controllable) { @@ -29,6 +59,8 @@ void InputSystem::tick(double dt) { } } } else if (e.key.keysym.sym == SDLK_SPACE) { + if (game_.isGameplayPaused()) continue; + // If there is text on screen, try to advance it. if (game_.getSystem().getCutsceneBarsProgress() != 0.0) { game_.getSystem().advanceText(); @@ -75,15 +107,21 @@ void InputSystem::tick(double dt) { } } } else if (e.key.keysym.sym == SDLK_LEFT) { + if (game_.isGameplayPaused()) continue; + if (game_.getSystem().isChoiceActive()) { game_.getSystem().selectFirstChoice(); } } else if (e.key.keysym.sym == SDLK_RIGHT) { + if (game_.isGameplayPaused()) continue; + if (game_.getSystem().isChoiceActive()) { game_.getSystem().selectSecondChoice(); } } } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) { + if (game_.isGameplayPaused()) continue; + for (int spriteId : game_.getSprites()) { Sprite& sprite = game_.getSprite(spriteId); if (sprite.controllable) { @@ -93,6 +131,8 @@ void InputSystem::tick(double dt) { } } + if (game_.isGameplayPaused()) return; + Input keystate; const Uint8* state = SDL_GetKeyboardState(NULL); keystate.left = state[SDL_SCANCODE_LEFT]; -- cgit 1.4.1