VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Types | Public Member Functions | List of all members
Achievement Class Reference

Representation of a Google Play Games Services achievement. More...

Public Types

enum  AchievementType { UNKNOWN = 0, REGULAR, INCREMENTAL }
 Category of achievement. More...
 

Public Member Functions

 Achievement (const QString &name)
 Constructs an achievement with the specified resource name. More...
 
 Achievement (const QJsonObject &json)
 Constructs an achievement from serialized JSON data. More...
 
void merge (const Achievement &achievement)
 Merges this with another set of achievement data. More...
 
const QStringgetName () const
 Returns the name of the Achievement. More...
 
AchievementType getAchievementType () const
 Returns the type of the Achievement. More...
 
bool hasBeenRevealed () const
 Returns whether or not the Achievement has been revealed through reveal(). More...
 
bool hasBeenUnlocked () const
 Returns whether or not the Achievement has been unlocked through unlock(). More...
 
int getMinStepsSet () const
 Returns the number of progress steps minimally set for the incremental Achievement through setSteps(). More...
 
int getStepsIncremented () const
 Returns the number of progress steps incremented for the incremental Achievement through increment(). More...
 
QJsonObject toJsonObject () const
 Returns the Achievement serialized as a JSON object. More...
 
void unlock (bool immediately)
 Unlocks the achievement. More...
 
void reveal (bool immediately)
 Reveals the achievement. More...
 
void increment (int numSteps, bool immediately)
 Increments the incremental achievement. More...
 
void setSteps (int numSteps, bool immediately)
 Sets the incremental achievement to minimally have numSteps. More...
 
bool saveToCloud ()
 Saves any buffered achievement actions (i.e. state changed for which immediately was false) to the cloud. More...
 

Detailed Description

Representation of a Google Play Games Services achievement.

This class represents the current state of an application-defined achievement and provides mechanisms for altering this state (e.g. unlocking, revealing, incrementing, etc.). Additionally, this class provides ways of storing this achievement state locally and syncing that state to the cloud on Android devices.

Note
This class uses all the fire-and-forget, non-blocking forms of the Google Play Games Services API where the status / time of completion of the operations are not immediately known.
See also
https://developer.android.com/reference/com/google/android/gms/games/achievement/Achievements.html

Member Enumeration Documentation

Category of achievement.

Achievements become bound to an AchievementType through actions performed on the achievement. Once an achievement has been bound to a certain AchievementType, future actions on the achievement are limited, with certain actions becoming undefined operations. For example, an achievement becomes AchievementType::INCREMENTAL after a call to increment(), at which time actions reserved for AchievementType::REGULAR achievements (e.g. unlock()) are no longer defined or allowed.

Note
The syncing of achievement data is one-directional (i.e. from local to cloud). This means that: (1) local achievement data may not be fully comprehensive of all achievement data currently represented in the cloud through AndroidActivity::showAchievements() and (2) incremental achievements have no ability to be unlocked "offline", as the pre-defined number of total progress steps is unknown.
Enumerator
UNKNOWN 

No actions (i.e. increment()) have been performed on the achievement allowing its type to be distinguished.

REGULAR 

Standard achievement that has binary state (i.e. "locked" vs. "unlocked").

INCREMENTAL 

Achievement whose progress advances incrementally and becomes "unlocked" after a certain number of pre-defined steps.

Constructor & Destructor Documentation

Achievement::Achievement ( const QString name)

Constructs an achievement with the specified resource name.

Parameters
nameAndroid resource name that can be used to locate the achievement id
Achievement::Achievement ( const QJsonObject json)

Constructs an achievement from serialized JSON data.

Parameters
jsonSerialized JSON representation of an achievement to load

Member Function Documentation

AchievementType Achievement::getAchievementType ( ) const

Returns the type of the Achievement.

int Achievement::getMinStepsSet ( ) const
inline

Returns the number of progress steps minimally set for the incremental Achievement through setSteps().

Note
This is separate from the current number of progress steps which is unavailable.
const QString& Achievement::getName ( ) const
inline

Returns the name of the Achievement.

int Achievement::getStepsIncremented ( ) const
inline

Returns the number of progress steps incremented for the incremental Achievement through increment().

Note
This is separate from the current number of progress steps which is unavailable.
bool Achievement::hasBeenRevealed ( ) const
inline

Returns whether or not the Achievement has been revealed through reveal().

Note
Due to one-directional syncing of achievement data, this method returning false does not guarantee the achievement in question is a "hidden" achievement – merely that there was no action actively made to reveal it with reveal().
bool Achievement::hasBeenUnlocked ( ) const
inline

Returns whether or not the Achievement has been unlocked through unlock().

void Achievement::increment ( int  numSteps,
bool  immediately 
)

Increments the incremental achievement.

Parameters
numStepsNumber of steps to increment the achievement
immediatelyWhether or not the achievement will be incremented directly in the cloud
void Achievement::merge ( const Achievement achievement)

Merges this with another set of achievement data.

Parameters
achievementAchievement whose state to merge
void Achievement::reveal ( bool  immediately)

Reveals the achievement.

Parameters
immediatelyWhether or not the achievement will be revealed directly in the cloud
bool Achievement::saveToCloud ( )

Saves any buffered achievement actions (i.e. state changed for which immediately was false) to the cloud.

Returns
Whether or not the cloud sync successful for all buffered actions
void Achievement::setSteps ( int  numSteps,
bool  immediately 
)

Sets the incremental achievement to minimally have numSteps.

Parameters
numStepsMinimum number of steps to set the progress of the achievement to
immediatelyWhether or not the achievement steps will be set directly in the cloud
QJsonObject Achievement::toJsonObject ( ) const

Returns the Achievement serialized as a JSON object.

void Achievement::unlock ( bool  immediately)

Unlocks the achievement.

Parameters
immediatelyWhether or not the achievement will be unlocked directly in the cloud