stmm-games-doc  0.32.0
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
stmg::HighscoresDefinition Class Reference

Classes

struct  Discriminator
 Separates highscores according to preference values. More...
 
struct  Eligibility
 All constraints must be satisfied for a team to be added to the highscore. More...
 
struct  HighscoreConstraint
 All constraints must be satisfied for a highscore to be created. More...
 
struct  ScoreElement
 Element of a score for a team. More...
 

Public Types

enum  DISCRIMINATOR_TYPE {
  DISCRIMINATOR_TYPE_OPTION = 0, DISCRIMINATOR_TYPE_TOT_TEAMS = 1, DISCRIMINATOR_TYPE_TOT_HUMAN_TEAMS = 2, DISCRIMINATOR_TYPE_TOT_AI_TEAMS = 3,
  DISCRIMINATOR_TYPE_TOT_MATES_OF_HUMAN_TEAM = 4
}
 
enum  HIGHSCORE_CONSTRAINT_TYPE { HIGHSCORE_CONSTRAINT_TYPE_TOT_TEAMS = 0, HIGHSCORE_CONSTRAINT_TYPE_TOT_HUMAN_TEAMS = 1, HIGHSCORE_CONSTRAINT_TYPE_TOT_AI_TEAMS = 2, HIGHSCORE_CONSTRAINT_TYPE_TOT_MATES_OF_HUMAN_TEAM = 3 }
 

Public Member Functions

 HighscoresDefinition (const shared_ptr< AppConfig > &refAppConfig, const std::vector< HighscoreConstraint > &aHighscoreConstraints, const std::vector< Discriminator > &aDiscriminators, const std::vector< Eligibility > &aEligibilitys, const std::vector< ScoreElement > &aScoreElements, int32_t nMaxScores) noexcept
 Constructor. More...
 
const std::vector< Discriminator > & getDiscriminators () const noexcept
 
const std::vector< Eligibility > & getEligibilitys () const noexcept
 
const std::vector< ScoreElement > & getScoreElements () const noexcept
 
int32_t getMaxScores () const noexcept
 The maximum number of scores in a highscore. More...
 
bool satisfiesPreferences (const AppPreferences &oAppPreferences) const noexcept
 Whether this instance satisfies the given preferences. More...
 
std::pair< bool, std::string > getCodeFromPreferences (const AppPreferences &oAppPreferences) const noexcept
 Return a code string that can identify a highscore based on the preferences. More...
 
std::pair< bool, std::string > getTitleFromPreferences (const AppPreferences &oAppPreferences) const noexcept
 Return a title string that can identify a highscore based on the preferences. More...
 
bool isValidCode (const std::string &sCode) const noexcept
 Whether a code string is valid. More...
 
std::string isCompatibleWithGame (const Game &oGame) const noexcept
 Check compatibility with a game instance. More...
 
bool operator== (const HighscoresDefinition &oHS) const noexcept
 
void dump () noexcept
 

Protected Member Functions

void reInit (const shared_ptr< AppConfig > &refAppConfig, const std::vector< HighscoreConstraint > &aHighscoreConstraints, const std::vector< Discriminator > &aDiscriminators, const std::vector< Eligibility > &aEligibilitys, const std::vector< ScoreElement > &aScoreElements, int32_t nMaxScores) noexcept
 See constructor. More...
 

Member Enumeration Documentation

◆ DISCRIMINATOR_TYPE

Enumerator
DISCRIMINATOR_TYPE_OPTION 

The value of an option.

DISCRIMINATOR_TYPE_TOT_TEAMS 

Number of teams playing.

DISCRIMINATOR_TYPE_TOT_HUMAN_TEAMS 

Number of human teams playing.

DISCRIMINATOR_TYPE_TOT_AI_TEAMS 

Number of ai teams playing.

DISCRIMINATOR_TYPE_TOT_MATES_OF_HUMAN_TEAM 

Number of mates in human teams.

◆ HIGHSCORE_CONSTRAINT_TYPE

Enumerator
HIGHSCORE_CONSTRAINT_TYPE_TOT_TEAMS 

Number of teams playing.

HIGHSCORE_CONSTRAINT_TYPE_TOT_HUMAN_TEAMS 

Number of human teams playing.

HIGHSCORE_CONSTRAINT_TYPE_TOT_AI_TEAMS 

Number of ai teams playing.

HIGHSCORE_CONSTRAINT_TYPE_TOT_MATES_OF_HUMAN_TEAM 

Number of mates in human team.

Constructor & Destructor Documentation

◆ HighscoresDefinition()

stmg::HighscoresDefinition::HighscoresDefinition ( const shared_ptr< AppConfig > &  refAppConfig,
const std::vector< HighscoreConstraint > &  aHighscoreConstraints,
const std::vector< Discriminator > &  aDiscriminators,
const std::vector< Eligibility > &  aEligibilitys,
const std::vector< ScoreElement > &  aScoreElements,
int32_t  nMaxScores 
)
noexcept

Constructor.

If more than one ScoreElement is passed the one at index 0 (in the vector) is the most significant. Note: the variables are expected to be correct, this class doesn't check whether the Game really has them.

Since a highscore (file) might be created for each combination of Discriminators the total number should be kept low. So options that can take a huge amount of values shouldn't be used as discriminator. Example: an IntOption "Initial lives" that can take any positive number used as discriminator would create a highscore file for each value set in the preferences.

Parameters
refAppConfigThe config. Cannot be null.
aHighscoreConstraintsThe game type conditions for this definition to apply. All must be true. Can be empty.
aDiscriminatorsThe discriminators. Can be empty.
aEligibilitysConstraints for on a team to be eligible to a highscore. All must apply. If empty teams always eligible.
aScoreElementsThe elements of a score. From the most significant to the least significant. Cannot be empty.
nMaxScoresThe number of highscore entries.

Member Function Documentation

◆ dump()

void stmg::HighscoresDefinition::dump ( )
noexcept

◆ getCodeFromPreferences()

std::pair<bool, std::string> stmg::HighscoresDefinition::getCodeFromPreferences ( const AppPreferences oAppPreferences) const
inlinenoexcept

Return a code string that can identify a highscore based on the preferences.

This string can be used along with the game name (and the app name) to uniquely identify a highscore. It can be used to build the name of a highscore file or build the path of a key in a settings hierarchy like gconf.

Example: if HighscoresDefinition was initialized with one discriminator of type EnumOption (localized to french) with the name "Difficulty" and values (1,"Easy","Facile"), (2,"Medium","Moyen") and (3,"Hard","Difficile") this function would return "Medium" if the current value in the preferences for this option is 2. This string can then be used to define the highscore file name: for example "Jointris-Medium.sco".

If more discriminators are defined the values are separated with an "_" (underscore).

If one of the discriminator options is a not enabled slave option {false, ""} is returned.

Parameters
oAppPreferencesThe preferences.
Returns
Whether a string could be generated and the string. If no discriminators {true, ""} is returned.

◆ getDiscriminators()

const std::vector<Discriminator>& stmg::HighscoresDefinition::getDiscriminators ( ) const
inlinenoexcept

◆ getEligibilitys()

const std::vector<Eligibility>& stmg::HighscoresDefinition::getEligibilitys ( ) const
inlinenoexcept

◆ getMaxScores()

int32_t stmg::HighscoresDefinition::getMaxScores ( ) const
inlinenoexcept

The maximum number of scores in a highscore.

Returns
The maximum number.

◆ getScoreElements()

const std::vector<ScoreElement>& stmg::HighscoresDefinition::getScoreElements ( ) const
inlinenoexcept

◆ getTitleFromPreferences()

std::pair<bool, std::string> stmg::HighscoresDefinition::getTitleFromPreferences ( const AppPreferences oAppPreferences) const
inlinenoexcept

Return a title string that can identify a highscore based on the preferences.

This string can be used along with the game name (and the app name) as title of a highscore.

Example: if HighscoresDefinition was initialized with one discriminator of type EnumOption (localized to french) with the name "Difficulty", description "Difficulté" and values (1,"Easy","Facile"), (2,"Medium","Moyen") and (3,"Hard","Difficile") this function would return "Difficulté: Moyen" if the current value in the preferences for this option is 2. This string can then be used to define the title of a highscore dialog: for example "Jointris scores - Difficulté: Moyen".

If more discriminators are defined the values are separated with an ", ".

If one of the discriminator options is a not enabled slave option {false, ""} is returned.

Parameters
oAppPreferencesThe preferences.
Returns
Whether a string could be generated and the string. If no discriminators {true, ""} is returned.

◆ isCompatibleWithGame()

std::string stmg::HighscoresDefinition::isCompatibleWithGame ( const Game oGame) const
noexcept

Check compatibility with a game instance.

Checks whether all the variable names in Eligibility and ScoreElement are defined.

Parameters
oGameThe game.
Returns
The error string or empty if it's compatible.

◆ isValidCode()

bool stmg::HighscoresDefinition::isValidCode ( const std::string &  sCode) const
noexcept

Whether a code string is valid.

Parameters
sCodeThe code string. Can be empty.
Returns
Whether code could have been generated by getCodeFromPreferences().

◆ operator==()

bool stmg::HighscoresDefinition::operator== ( const HighscoresDefinition oHS) const
noexcept

◆ reInit()

void stmg::HighscoresDefinition::reInit ( const shared_ptr< AppConfig > &  refAppConfig,
const std::vector< HighscoreConstraint > &  aHighscoreConstraints,
const std::vector< Discriminator > &  aDiscriminators,
const std::vector< Eligibility > &  aEligibilitys,
const std::vector< ScoreElement > &  aScoreElements,
int32_t  nMaxScores 
)
protectednoexcept

See constructor.

◆ satisfiesPreferences()

bool stmg::HighscoresDefinition::satisfiesPreferences ( const AppPreferences oAppPreferences) const
inlinenoexcept

Whether this instance satisfies the given preferences.

The preferences must satisfy the constraints and all the discriminators by option must be either master or enabled slave option.

Parameters
oAppPreferencesThe preferences.
Returns
Whether this instance can be used to generate highscores.