]> git.localhorst.tv Git - blank.git/blob - src/ui/Keymap.hpp
more packet introspection from payload
[blank.git] / src / ui / Keymap.hpp
1 #ifndef BLANK_UI_KEYMAP_HPP_
2 #define BLANK_UI_KEYMAP_HPP_
3
4 #include <iosfwd>
5 #include <string>
6 #include <SDL.h>
7
8
9 namespace blank {
10
11 class Keymap {
12
13 public:
14         enum Action {
15                 NONE,
16
17                 MOVE_FORWARD,
18                 MOVE_BACKWARD,
19                 MOVE_LEFT,
20                 MOVE_RIGHT,
21                 MOVE_UP,
22                 MOVE_DOWN,
23
24                 BLOCK_FACE,
25                 BLOCK_TURN,
26                 BLOCK_NEXT,
27                 BLOCK_PREV,
28
29                 BLOCK_PLACE,
30                 BLOCK_PICK,
31                 BLOCK_REMOVE,
32
33                 TOGGLE_COLLISION,
34                 TOGGLE_AUDIO,
35                 TOGGLE_VISUAL,
36                 TOGGLE_DEBUG,
37
38                 EXIT,
39         };
40
41         static constexpr unsigned int MAX_SCANCODE = 0xFF;
42         static constexpr unsigned int NUM_SCANCODES = MAX_SCANCODE + 1;
43
44 public:
45         Keymap();
46
47         void Map(SDL_Scancode scancode, Action);
48         Action Lookup(SDL_Scancode scancode);
49         Action Lookup(const SDL_Keysym &s) { return Lookup(s.scancode); }
50         Action Lookup(const SDL_KeyboardEvent &e) { return Lookup(e.keysym); }
51
52         void LoadDefault();
53
54         void Load(std::istream &);
55         void Save(std::ostream &);
56
57         static const char *ActionToString(Action);
58         static Action StringToAction(const std::string &);
59
60 private:
61         Action codemap[NUM_SCANCODES];
62
63 };
64
65 }
66
67 #endif