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

Represents a player's profile or "save game" state. More...

Inheritance diagram for PlayerProfile:
QObject

Public Types

enum  LoadState { UNLOADED, LOADING, LOADED }
 Current status of persistent data in the player profile. More...
 

Signals

void newDataMerged ()
 Emitted when new data from either local or cloud storage has been merged into the PlayerProfile. More...
 

Public Member Functions

LoadState getLoadState () const
 Returns the current LoadState of the PlayerProfile. More...
 
LevelInfogetLastPlayedLevelInfo (const QString &progressionName) const
 Returns the LevelInfo of the level the player most recently played (or was set to play) in progressionName. More...
 
bool isEnvironmentUnlocked (const QString &progressionName, const QString &environmentName) const
 Returns whether or not the Environment denoted by environmentName in the LevelProgression denoted by progressionName is unlocked. More...
 
bool isLevelUnlocked (const QString &progressionName, const QString &levelName) const
 Returns whether or not the Environment denoted by levelName in the LevelProgression denoted by progressionName is unlocked. More...
 
int getCurrentPlayerScore (int playerId=0) const
 Returns the current score for playerId. More...
 
const QMap< int, int > & getCurrentPlayerScores () const
 Returns the scores for all players for the current level. More...
 
int updatePlayerScore (int playerId, int amountChanged)
 Updates the current level score for playerId by amountChanged. More...
 
int getNumStars (const QString &progressionName, const QString &levelName) const
 Returns the number of star achieved by the player on the level denoted by levelName in the LevelProgression denoted by progressionName. More...
 
bool hasMinStars (const QString &progressionName, int minStars) const
 Returns whether or not the player has achieved at least a minimum number of stars on each level in the LevelProgression. More...
 
bool hasMinStars (const QString &progressionName, const QString &environmentName, int minStars) const
 Returns whether or not the player has achieved a minimum number of stars on each level in the Environment. More...
 
void unlockAchievement (const QString &name, bool immediately)
 Unlocks a Google Play Games Services achievement. More...
 
void incrementAchievement (const QString &name, int numSteps, bool immediately)
 Increments a Google Play Games Services incremental achievement. More...
 
void setAchievementSteps (const QString &name, int minSteps, bool immediately)
 Sets a Google Play Games Services incremental achievement to have a minimum number of steps. More...
 
void revealAchievement (const QString &name, bool immediately)
 Reveals a Google Play Games Services achievement. More...
 
void showAchievements ()
 Requests that the PlayerProfile launch a view of the Google Play Games Services achievements. More...
 
void startLoad ()
 Asynchronously starts a full load of the PlayerProfile from local storage and, if available, cloud data. More...
 
bool tryFinishLoad ()
 Attempts to complete the loading of the PlayerProfile which was asynchronously started with startLoad(). More...
 
void save ()
 Saves the permanent state of the PlayerProfile to local storage and, if available, cloud storage. More...
 
void saveAchievementsToCloud ()
 Tries to push all buffered achievement state updates to the cloud. More...
 
void reset (bool permanently)
 Clears the temporary and permanent data loaded into the PlayerProfile. More...
 
bool hasCloudSave () const
 Returns whether or not the device supports cloud save. More...
 
bool isSignedIntoCloud () const
 Returns whether or not the player is signed into Google Play Games Services. More...
 
bool cloudSignInFailed () const
 Returns whether or not a previous attempt to sign into Google Play Games Services failed. More...
 
void signIntoCloud ()
 Attempts to sign the player into Google Play Games Services. More...
 
void signOutOfCloud ()
 Signs the player out of Google Play Games Services. More...
 
QJsonDocument toJsonDocument ()
 Returns the PlayerProfile serialized as a JSON document. More...
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
virtual const QMetaObjectmetaObject () const
 
QString objectName () const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const
 
bool blockSignals (bool block)
 
QThreadthread () const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, QFlags< Qt::FindChildOption > options) const
 
QList< T > findChildren (const QString &name, QFlags< Qt::FindChildOption > options) const
 
QList< T > findChildren (const QRegExp &regExp, QFlags< Qt::FindChildOption > options) const
 
QList< T > findChildren (const QRegularExpression &re, QFlags< Qt::FindChildOption > options) const
 
const QObjectList & children () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const
 
bool disconnect (const QObject *receiver, const char *method) const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const
 
bool inherits (const char *className) const
 
void deleteLater ()
 

Friends

class Game
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

Represents a player's profile or "save game" state.

This class contains logic for storing information on both temporary game state information (e.g. current Level scores) and more persistent game state information (e.g. which levels are unlocked, stars achieved for completed levels, etc.). This persistent game state information is saved both locally and to the cloud if on an Android device. To have cloud storage be successful, the Android device must be signed into Google Play Games Services – a process which can be started by using signIntoCloud(). Finally, this class provides a mechanism for affecting Achievement changes through Google Play Games Services.

Member Enumeration Documentation

Current status of persistent data in the player profile.

Enumerator
UNLOADED 

No state has been loaded.

LOADING 

In the process of loading state from local and/or cloud.

LOADED 

Available state has been loaded from local and cloud, if necessary.

Member Function Documentation

bool PlayerProfile::cloudSignInFailed ( ) const

Returns whether or not a previous attempt to sign into Google Play Games Services failed.

int PlayerProfile::getCurrentPlayerScore ( int  playerId = 0) const

Returns the current score for playerId.

Note
A default player ID of 0 is used for single player LevelProgressions.
Parameters
playerIdPlayer ID [0, 3] of player whose score to query
const QMap<int, int>& PlayerProfile::getCurrentPlayerScores ( ) const
inline

Returns the scores for all players for the current level.

The returned value is a map from player ID to score.

LevelInfo* PlayerProfile::getLastPlayedLevelInfo ( const QString progressionName) const

Returns the LevelInfo of the level the player most recently played (or was set to play) in progressionName.

Parameters
progressionNameName of the LevelProgression to get the last played LevelInfo for
LoadState PlayerProfile::getLoadState ( ) const
inline

Returns the current LoadState of the PlayerProfile.

int PlayerProfile::getNumStars ( const QString progressionName,
const QString levelName 
) const

Returns the number of star achieved by the player on the level denoted by levelName in the LevelProgression denoted by progressionName.

Note
progressionName must be the name of a single player LevelProgression, since star scores are only assigned for single player levels. -1 will be returned if getCurrentLevelProgression()'s LevelProgression::multiplayer property is true.
Parameters
progressionNameName of the LevelProgression in which levelName resides
levelNameName of the LevelInfo to query for highest number of stars achieved
bool PlayerProfile::hasCloudSave ( ) const

Returns whether or not the device supports cloud save.

bool PlayerProfile::hasMinStars ( const QString progressionName,
int  minStars 
) const

Returns whether or not the player has achieved at least a minimum number of stars on each level in the LevelProgression.

Parameters
progressionNameName of LevelProgression to query for a minimum number of stars
minStarsThreshold of stars to query for
bool PlayerProfile::hasMinStars ( const QString progressionName,
const QString environmentName,
int  minStars 
) const

Returns whether or not the player has achieved a minimum number of stars on each level in the Environment.

Parameters
progressionNameName of LevelProgression in which environmentName resides
environmentNameName of Envirionment to query for a minimum number of stars
minStarsThreshold of stars to query for
void PlayerProfile::incrementAchievement ( const QString name,
int  numSteps,
bool  immediately 
)

Increments a Google Play Games Services incremental achievement.

Note
This function only has an effect on an Android device.
Parameters
nameAndroid resource name used to locate the achievement id
numStepsNumber of steps to increment the achievement
immediatelyWhether or not to sync the achievement change with Google Play Games Services now
bool PlayerProfile::isEnvironmentUnlocked ( const QString progressionName,
const QString environmentName 
) const

Returns whether or not the Environment denoted by environmentName in the LevelProgression denoted by progressionName is unlocked.

Parameters
progressionNameName of LevelProgression in which environmentName resides
environmentNameName of Environment to query for locked state
bool PlayerProfile::isLevelUnlocked ( const QString progressionName,
const QString levelName 
) const

Returns whether or not the Environment denoted by levelName in the LevelProgression denoted by progressionName is unlocked.

Parameters
progressionNameName of LevelProgression in which levelName resides
levelNameName of LevelInfo to query for locked state
bool PlayerProfile::isSignedIntoCloud ( ) const

Returns whether or not the player is signed into Google Play Games Services.

void PlayerProfile::newDataMerged ( )
signal

Emitted when new data from either local or cloud storage has been merged into the PlayerProfile.

void PlayerProfile::reset ( bool  permanently)

Clears the temporary and permanent data loaded into the PlayerProfile.

Parameters
permanentlyWhether or not to wipe the PlayerProfile data from local and cloud storage
void PlayerProfile::revealAchievement ( const QString name,
bool  immediately 
)

Reveals a Google Play Games Services achievement.

Note
This function only has an effect on an Android device.
Parameters
nameAndroid resource name used to locate the achievement id
immediatelyWhether or not to sync the achievement change with Google Play Games Services now
void PlayerProfile::save ( )

Saves the permanent state of the PlayerProfile to local storage and, if available, cloud storage.

void PlayerProfile::saveAchievementsToCloud ( )

Tries to push all buffered achievement state updates to the cloud.

void PlayerProfile::setAchievementSteps ( const QString name,
int  minSteps,
bool  immediately 
)

Sets a Google Play Games Services incremental achievement to have a minimum number of steps.

Note
This function only has an effect on an Android device.
Parameters
nameAndroid resource name used to locate the achievement id
minStepsLower bound for incremental progress
immediatelyWhether or not to sync the achievement change with Google Play Games Services now
void PlayerProfile::showAchievements ( )

Requests that the PlayerProfile launch a view of the Google Play Games Services achievements.

Note
This function only has an effect on an Android device.
void PlayerProfile::signIntoCloud ( )

Attempts to sign the player into Google Play Games Services.

void PlayerProfile::signOutOfCloud ( )

Signs the player out of Google Play Games Services.

void PlayerProfile::startLoad ( )

Asynchronously starts a full load of the PlayerProfile from local storage and, if available, cloud data.

QJsonDocument PlayerProfile::toJsonDocument ( )

Returns the PlayerProfile serialized as a JSON document.

bool PlayerProfile::tryFinishLoad ( )

Attempts to complete the loading of the PlayerProfile which was asynchronously started with startLoad().

Note
This call is non-blocking, and is intended to be called over time in the application's main processing loop.
Returns
Whether or not the load has finished
void PlayerProfile::unlockAchievement ( const QString name,
bool  immediately 
)

Unlocks a Google Play Games Services achievement.

Note
This function only has an effect on an Android device.
Parameters
nameAndroid resource name used to locate the achievement id
immediatelyWhether or not to sync the achievement change with Google Play Games Services now
int PlayerProfile::updatePlayerScore ( int  playerId,
int  amountChanged 
)

Updates the current level score for playerId by amountChanged.

Parameters
playerIdPlayer ID [0, 3] of player whose score to change
amountChangedDelta value to change the score by