HoverRace  2.0
Profile.h
Go to the documentation of this file.
1 
2 // Profile.h
3 //
4 // Copyright (c) 2014-2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <boost/uuid/uuid.hpp>
25 
26 #include "../Display/Color.h"
27 #include "../Display/Res.h"
28 #include "EditableProfile.h"
29 
30 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
31 # ifdef MR_ENGINE
32 # define MR_DllDeclare __declspec( dllexport )
33 # else
34 # define MR_DllDeclare __declspec( dllimport )
35 # endif
36 #else
37 # define MR_DllDeclare
38 #endif
39 
40 namespace HoverRace {
41  namespace Display {
42  class Texture;
43  }
44  namespace Player {
45  class AvatarGallery;
46  }
47 }
48 
49 namespace HoverRace {
50 namespace Player {
51 
57  protected EditableProfile,
58  protected RenamableProfile
59 {
60 public:
61  Profile(std::shared_ptr<AvatarGallery> avatarGallery = {});
62  Profile(std::shared_ptr<AvatarGallery> avatarGallery,
63  const boost::uuids::uuid &uid) :
64  Profile(avatarGallery, uid, "Player", {},
66  { }
67  Profile(std::shared_ptr<AvatarGallery> avatarGallery,
68  const boost::uuids::uuid &uid, const std::string &name,
69  const std::string &avatarName,
70  Display::Color primaryColor, Display::Color secondaryColor) :
71  avatarGallery(std::move(avatarGallery)),
72  uid(uid), name(name), avatarName(avatarName),
73  primaryColor(primaryColor), secondaryColor(secondaryColor) { }
74  virtual ~Profile() { }
75 
76 protected:
77  AvatarGallery *GetAvatarGallery() const { return avatarGallery.get(); }
78 
79 public:
84  const boost::uuids::uuid &GetUid() const { return uid; }
85 
86  const std::string GetUidStr() const;
87 
92  const std::string &GetName() const { return name; }
93 protected:
94  virtual void SetName(const std::string &name);
95 
96 public:
97  const std::string &GetAvatarName() const { return avatarName; }
98 protected:
99  void SetAvatarName(const std::string &avatarName) override;
100 
101 public:
102  Display::Color GetColor(size_t i) const;
103  void SetColor(size_t i, Display::Color color) override;
104 
105 public:
106  Display::Color GetPrimaryColor() const { return primaryColor; }
107 protected:
108  void SetPrimaryColor(Display::Color color) override;
109 
110 public:
111  Display::Color GetSecondaryColor() const { return secondaryColor; }
112 protected:
113  void SetSecondaryColor(Display::Color color) override;
114 
115 protected:
116  void Rename(const std::string &name) override { SetName(name); }
117 
118 public:
119  virtual std::shared_ptr<Display::Res<Display::Texture>>
120  GetAvatar() const;
121 
122 public:
128  virtual EditableProfile *Edit() { return nullptr; }
129 
135  virtual RenamableProfile *EditName() { return nullptr; }
136 
137 protected:
138  virtual void Save() = 0;
139 
140 public:
141  static const size_t MAX_NAME_LENGTH = 30;
142  static const size_t MAX_AVATAR_NAME_LENGTH = 16;
143 private:
144  std::shared_ptr<AvatarGallery> avatarGallery;
145  boost::uuids::uuid uid;
146  std::string name;
147  std::string avatarName;
150 };
151 
152 } // namespace Player
153 } // namespace HoverRace
154 
155 #undef MR_DllDeclare
std::string avatarName
Definition: Profile.h:147
Definition: Color.h:40
void Rename(const std::string &name) override
Attempt to rename the profile.
Definition: Profile.h:116
Display::Color GetPrimaryColor() const
Definition: Profile.h:106
constexpr Color COLOR_WHITE
Definition: Color.h:64
STL namespace.
AvatarGallery * GetAvatarGallery() const
Definition: Profile.h:77
const boost::uuids::uuid & GetUid() const
Retrieve the globally unique identifier for this profile.
Definition: Profile.h:84
const std::string & GetName() const
Retrieve the name of the player.
Definition: Profile.h:92
virtual EditableProfile * Edit()
Retrieve an editable view of this profile.
Definition: Profile.h:128
Display::Color secondaryColor
Definition: Profile.h:149
const std::string & GetAvatarName() const
Definition: Profile.h:97
std::string name
Definition: Profile.h:146
virtual RenamableProfile * EditName()
Retrieve an renamable view of this profile.
Definition: Profile.h:135
Display::Color primaryColor
Definition: Profile.h:148
std::shared_ptr< AvatarGallery > avatarGallery
Definition: Profile.h:144
virtual ~Profile()
Definition: Profile.h:74
Profile(std::shared_ptr< AvatarGallery > avatarGallery, const boost::uuids::uuid &uid)
Definition: Profile.h:62
Interface for profiles than can be renamed.
Definition: EditableProfile.h:59
#define MR_DllDeclare
Definition: Profile.h:37
Base class for player profiles.
Definition: Profile.h:56
Definition: Announcement.h:24
constexpr Color COLOR_BLACK
Definition: Color.h:65
Display::Color GetSecondaryColor() const
Definition: Profile.h:111
boost::uuids::uuid uid
Definition: Profile.h:145
Interface for profile editing.
Definition: EditableProfile.h:43
Profile(std::shared_ptr< AvatarGallery > avatarGallery, const boost::uuids::uuid &uid, const std::string &name, const std::string &avatarName, Display::Color primaryColor, Display::Color secondaryColor)
Definition: Profile.h:67