-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandHandler.cpp
More file actions
92 lines (80 loc) · 1.91 KB
/
CommandHandler.cpp
File metadata and controls
92 lines (80 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "CommandHandler.h"
#include "Utilities.h"
#include <raylib.h>
CommandHandler::CommandHandler() {}
CommandHandler::~CommandHandler() {}
void CommandHandler::UpdateInput(Player* _player)
{
char key = GetCharPressed();
if (key >= 32 && key <= 125)
{
input.push_back(key);
}
if (IsKeyDown(KEY_BACKSPACE))
{
if (!isBackspacing)
{
isBackspacing = true;
backspaceHoldStart = std::chrono::high_resolution_clock::now();
backspaceRepeatStart = std::chrono::high_resolution_clock::now();
if (!input.empty()) input.pop_back();
}
else
{
std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now();
auto durationHold = std::chrono::duration_cast<std::chrono::milliseconds>(now - backspaceHoldStart).count();
auto durationRepeat = std::chrono::duration_cast<std::chrono::milliseconds>(now - backspaceRepeatStart).count();
if (durationHold > 200)
{
if (durationRepeat > 50)
{
if (!input.empty()) input.pop_back();
backspaceRepeatStart = std::chrono::high_resolution_clock::now();
}
}
}
}
else isBackspacing = false;
if (IsKeyPressed(KEY_ENTER))
{
if (inputActive == true)
{
if (ToLower(input) == "quit")
{
input.clear();
Quit();
}
else if (ToLower(input) == "test")
{
inputActive = false;
input.clear();
}
else if (ToLower(input) == "move north")
{
inputActive = false;
input.clear();
_player->SetRoom(_player->GetRoom()->GetConnectedRoom("north"));
}
else if (ToLower(input) == "move south")
{
inputActive = false;
input.clear();
_player->SetRoom(_player->GetRoom()->GetConnectedRoom("south"));
}
else input.clear();
}
else if (inputActive == false) inputActive = true;
}
}
std::string CommandHandler::GetInput() const
{
return input;
}
bool CommandHandler::GetInputActive()
{
return inputActive;
}
void CommandHandler::Quit()
{
WindowShouldClose();
}