summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-07-06 14:40:01 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2021-07-06 14:40:01 -0400
commit73411749a50f523fb56b2cfda78d759b667b811f (patch)
treebc1b0b76d17590f95530f949ac83a194bd948b8b
parent45f6bfffd8940cb71dbff8224566aa3292bbb98f (diff)
downloadtanetane-73411749a50f523fb56b2cfda78d759b667b811f.tar.gz
tanetane-73411749a50f523fb56b2cfda78d759b667b811f.tar.bz2
tanetane-73411749a50f523fb56b2cfda78d759b667b811f.zip
Added debug console command history HEAD main
#5
-rw-r--r--src/input_system.cpp16
-rw-r--r--src/input_system.h3
2 files changed, 19 insertions, 0 deletions
diff --git a/src/input_system.cpp b/src/input_system.cpp index 56516ac..0758cda 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp
@@ -27,6 +27,7 @@ void InputSystem::tick(double dt) {
27 if (e.key.keysym.sym == SDLK_ESCAPE) { 27 if (e.key.keysym.sym == SDLK_ESCAPE) {
28 if (debugConsole_) { 28 if (debugConsole_) {
29 debugConsole_ = false; 29 debugConsole_ = false;
30 debugHistory_.pop_front();
30 game_.unpauseGameplay(); 31 game_.unpauseGameplay();
31 SDL_StopTextInput(); 32 SDL_StopTextInput();
32 debugText_.clear(); 33 debugText_.clear();
@@ -41,6 +42,8 @@ void InputSystem::tick(double dt) {
41#ifdef TANETANE_DEBUG 42#ifdef TANETANE_DEBUG
42 if (!debugConsole_ && !game_.isGameplayPaused()) { 43 if (!debugConsole_ && !game_.isGameplayPaused()) {
43 debugConsole_ = true; 44 debugConsole_ = true;
45 debugHistorySelection_ = 0;
46 debugHistory_.push_front("");
44 game_.pauseGameplay(); 47 game_.pauseGameplay();
45 SDL_StartTextInput(); 48 SDL_StartTextInput();
46 debugText_.clear(); 49 debugText_.clear();
@@ -48,7 +51,10 @@ void InputSystem::tick(double dt) {
48#endif 51#endif
49 } else if (debugConsole_ && e.key.keysym.sym == SDLK_RETURN) { 52 } else if (debugConsole_ && e.key.keysym.sym == SDLK_RETURN) {
50 game_.getSystem<ScriptSystem>().runDebugScript(debugText_); 53 game_.getSystem<ScriptSystem>().runDebugScript(debugText_);
54 debugHistory_[0] = debugText_;
51 debugText_.clear(); 55 debugText_.clear();
56 debugHistorySelection_ = 0;
57 debugHistory_.push_front("");
52 } else if (debugConsole_ && e.key.keysym.sym == SDLK_BACKSPACE) { 58 } else if (debugConsole_ && e.key.keysym.sym == SDLK_BACKSPACE) {
53 // Make sure to keep the backtick/heart. 59 // Make sure to keep the backtick/heart.
54 if (!debugText_.empty()) { 60 if (!debugText_.empty()) {
@@ -141,10 +147,20 @@ void InputSystem::tick(double dt) {
141 game_.getSystem<MessageSystem>().selectSecondChoice(); 147 game_.getSystem<MessageSystem>().selectSecondChoice();
142 } 148 }
143 } else if (e.key.keysym.sym == SDLK_UP) { 149 } else if (e.key.keysym.sym == SDLK_UP) {
150 if (debugConsole_ && debugHistorySelection_ < (debugHistory_.size() - 1)) {
151 debugHistory_[debugHistorySelection_] = debugText_;
152 debugHistorySelection_++;
153 debugText_ = debugHistory_[debugHistorySelection_];
154 }
144 if (game_.getSystem<MenuSystem>().isMenuOpen()) { 155 if (game_.getSystem<MenuSystem>().isMenuOpen()) {
145 game_.getSystem<MenuSystem>().pressedUp(); 156 game_.getSystem<MenuSystem>().pressedUp();
146 } 157 }
147 } else if (e.key.keysym.sym == SDLK_DOWN) { 158 } else if (e.key.keysym.sym == SDLK_DOWN) {
159 if (debugConsole_ && debugHistorySelection_ > 0) {
160 debugHistory_[debugHistorySelection_] = debugText_;
161 debugHistorySelection_--;
162 debugText_ = debugHistory_[debugHistorySelection_];
163 }
148 if (game_.getSystem<MenuSystem>().isMenuOpen()) { 164 if (game_.getSystem<MenuSystem>().isMenuOpen()) {
149 game_.getSystem<MenuSystem>().pressedDown(); 165 game_.getSystem<MenuSystem>().pressedDown();
150 } 166 }
diff --git a/src/input_system.h b/src/input_system.h index a7757b8..c8e0d8c 100644 --- a/src/input_system.h +++ b/src/input_system.h
@@ -1,6 +1,7 @@
1#ifndef INPUT_SYSTEM_H_47764575 1#ifndef INPUT_SYSTEM_H_47764575
2#define INPUT_SYSTEM_H_47764575 2#define INPUT_SYSTEM_H_47764575
3 3
4#include <deque>
4#include <string> 5#include <string>
5#include "system.h" 6#include "system.h"
6 7
@@ -24,6 +25,8 @@ private:
24 Game& game_; 25 Game& game_;
25 bool debugConsole_ = false; 26 bool debugConsole_ = false;
26 std::string debugText_; 27 std::string debugText_;
28 std::deque<std::string> debugHistory_;
29 int debugHistorySelection_ = 0;
27}; 30};
28 31
29#endif /* end of include guard: INPUT_SYSTEM_H_47764575 */ 32#endif /* end of include guard: INPUT_SYSTEM_H_47764575 */