VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Achievement.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ACHIEVEMENT_H
18 #define ACHIEVEMENT_H
19 
20 #include <QString>
21 
22 class QJsonObject;
23 
36 class Achievement {
37 public:
58  UNKNOWN = 0,
68  };
69 
74  Achievement(const QString& name);
79  Achievement(const QJsonObject& json);
80 
85  void merge(const Achievement& achievement);
89  const QString& getName() const { return mName; }
100  bool hasBeenRevealed() const { return mHasBeenRevealed; }
104  bool hasBeenUnlocked() const { return mHasBeenUnlocked; }
110  int getMinStepsSet() const { return mMinStepsSet; }
116  int getStepsIncremented() const { return mStepsIncremented; }
117 
121  QJsonObject toJsonObject() const;
122 
127  void unlock(bool immediately);
132  void reveal(bool immediately);
138  void increment(int numSteps, bool immediately);
144  void setSteps(int numSteps, bool immediately);
145 
151  bool saveToCloud();
152 
153 private:
154  bool cloudUnlock();
155  bool cloudReveal();
156  bool cloudIncrement(int numSteps);
157  bool cloudSetSteps(int numSteps);
158 
159  QString mName;
160  bool mHasBeenRevealed = false;
161  bool mRevealIsDirty = false;
162  bool mHasBeenUnlocked = false;
163  bool mUnlockIsDirty = false;
164  int mMinStepsSet = 0;
165  bool mMinStepsDirty = false;
166  int mStepsIncremented = 0;
167  int mStepsIncrementedDirtiness = 0;
168 };
169 
170 #endif // ACHIEVEMENT_H
AchievementType getAchievementType() const
Returns the type of the Achievement.
QJsonObject toJsonObject() const
Returns the Achievement serialized as a JSON object.
Representation of a Google Play Games Services achievement.
Definition: Achievement.h:36
void increment(int numSteps, bool immediately)
Increments the incremental achievement.
Standard achievement that has binary state (i.e. "locked" vs. "unlocked").
Definition: Achievement.h:62
bool hasBeenRevealed() const
Returns whether or not the Achievement has been revealed through reveal().
Definition: Achievement.h:100
bool hasBeenUnlocked() const
Returns whether or not the Achievement has been unlocked through unlock().
Definition: Achievement.h:104
const QString & getName() const
Returns the name of the Achievement.
Definition: Achievement.h:89
void reveal(bool immediately)
Reveals the achievement.
void setSteps(int numSteps, bool immediately)
Sets the incremental achievement to minimally have numSteps.
No actions (i.e. increment()) have been performed on the achievement allowing its type to be distingu...
Definition: Achievement.h:58
Achievement whose progress advances incrementally and becomes "unlocked" after a certain number of pr...
Definition: Achievement.h:67
bool saveToCloud()
Saves any buffered achievement actions (i.e. state changed for which immediately was false) to the cl...
int getMinStepsSet() const
Returns the number of progress steps minimally set for the incremental Achievement through setSteps()...
Definition: Achievement.h:110
void merge(const Achievement &achievement)
Merges this with another set of achievement data.
AchievementType
Category of achievement.
Definition: Achievement.h:53
int getStepsIncremented() const
Returns the number of progress steps incremented for the incremental Achievement through increment()...
Definition: Achievement.h:116
void unlock(bool immediately)
Unlocks the achievement.
Achievement(const QString &name)
Constructs an achievement with the specified resource name.