X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fshared%2FCLIContext.hpp;h=e07571fc331eafbeff45100f712ab6204a648625;hb=b00e4b77859d13bdf29bd50e91315a46a15bd01d;hp=8de432b7788adb966e0a890e45111e868290b0ca;hpb=fa3c4a14546d73ddc2671cd5cc58208839bf7173;p=blank.git diff --git a/src/shared/CLIContext.hpp b/src/shared/CLIContext.hpp index 8de432b..e07571f 100644 --- a/src/shared/CLIContext.hpp +++ b/src/shared/CLIContext.hpp @@ -7,15 +7,40 @@ namespace blank { class Player; +class Entity; class CLIContext { public: - explicit CLIContext(Player &p) - : player(p) { } + /// Create context with optional player and entity + /// entity defaults to the player's if given + /// Associated player or entity can be changed during + /// the context's lifetime and will assume the original + /// values when reset. + explicit CLIContext(Player *p = nullptr, Entity *e = nullptr); + /// check if this context associates a player + bool HasPlayer() { return effective_player; } /// get the player responsible for all this - Player &GetPlayer() { return player; } + /// only valid if HasPlayer() returns true + Player &GetPlayer() { return *effective_player; } + /// change the effective player of this context + /// note that this will *not* change the effective entity + void SetPlayer(Player &p) { effective_player = &p; } + + /// check if this context associates an entity + bool HasEntity() { return effective_entity; } + /// get the entity on which operations should be performed + /// only valid if HasPlayer() returns true + Entity &GetEntity() { return *effective_entity; } + /// change the effective player of this context + void SetEntity(Entity &e) { effective_entity = &e; } + + /// reset effective player and entity to their original values + void Reset() { + effective_player = original_player; + effective_player = original_player; + } /// an error has happened and the player should be notified virtual void Error(const std::string &) = 0; @@ -29,7 +54,10 @@ public: virtual void Broadcast(const std::string &) = 0; private: - Player &player; + Player *original_player; + Player *effective_player; + Entity *original_entity; + Entity *effective_entity; };