]> git.localhorst.tv Git - blank.git/blob - src/shared/CLIContext.hpp
e07571fc331eafbeff45100f712ab6204a648625
[blank.git] / src / shared / CLIContext.hpp
1 #ifndef BLANK_SHARED_CLICONTEXT_HPP_
2 #define BLANK_SHARED_CLICONTEXT_HPP_
3
4 #include <string>
5
6
7 namespace blank {
8
9 class Player;
10 class Entity;
11
12 class CLIContext {
13
14 public:
15         /// Create context with optional player and entity
16         /// entity defaults to the player's if given
17         /// Associated player or entity can be changed during
18         /// the context's lifetime and will assume the original
19         /// values when reset.
20         explicit CLIContext(Player *p = nullptr, Entity *e = nullptr);
21
22         /// check if this context associates a player
23         bool HasPlayer() { return effective_player; }
24         /// get the player responsible for all this
25         /// only valid if HasPlayer() returns true
26         Player &GetPlayer() { return *effective_player; }
27         /// change the effective player of this context
28         /// note that this will *not* change the effective entity
29         void SetPlayer(Player &p) { effective_player = &p; }
30
31         /// check if this context associates an entity
32         bool HasEntity() { return effective_entity; }
33         /// get the entity on which operations should be performed
34         /// only valid if HasPlayer() returns true
35         Entity &GetEntity() { return *effective_entity; }
36         /// change the effective player of this context
37         void SetEntity(Entity &e) { effective_entity = &e; }
38
39         /// reset effective player and entity to their original values
40         void Reset() {
41                 effective_player = original_player;
42                 effective_player = original_player;
43         }
44
45         /// an error has happened and the player should be notified
46         virtual void Error(const std::string &) = 0;
47
48         /// return to sender
49         /// use this for output concerning the originator of a command
50         virtual void Message(const std::string &) = 0;
51
52         /// send a status message to all players
53         /// use this to announce stuff which may be interesting to anyone
54         virtual void Broadcast(const std::string &) = 0;
55
56 private:
57         Player *original_player;
58         Player *effective_player;
59         Entity *original_entity;
60         Entity *effective_entity;
61
62 };
63
64 }
65
66 #endif