stmm-games-doc  0.32.0
Classes | Public Member Functions | List of all members
stmg::StdPreferences Class Reference
Inheritance diagram for stmg::StdPreferences:
Inheritance graph
[legend]

Classes

class  Player
 
class  Team
 

Public Member Functions

 StdPreferences (const shared_ptr< StdConfig > &refStdConfig) noexcept
 Constructor. More...
 
 StdPreferences (const StdPreferences &oSource) noexcept
 Copy constructor. More...
 
StdPreferencesoperator= (const StdPreferences &oSource) noexcept
 Copy assignment. More...
 
bool isInEditMode () const noexcept
 Get edit mode. More...
 
void setEditMode (bool bInEditMode) noexcept
 Set edit mode. More...
 
int32_t getMaxPlayerNameLength () const noexcept
 The player name maximum length in unicode characters. More...
 
int32_t getMaxTeamNameLength () const noexcept
 The team name maximum length in unicode characters. More...
 
bool playerMoveUp (const std::string &sPlayerName) noexcept
 Move a player up in the hierarchy. More...
 
bool playerMoveDown (const std::string &sPlayerName) noexcept
 Move a player down in the hierarchy. More...
 
bool playerTeamUp (const std::string &sPlayerName) noexcept
 Move a player to the preceding team in the hierarchy. More...
 
bool playerTeamDown (const std::string &sPlayerName) noexcept
 Move a player to the following team in the hierarchy. More...
 
const shared_ptr< Player > & getPlayerFull (int32_t nPlayer) const noexcept
 Get the player. More...
 
const shared_ptr< Player > & getPlayerFull (const std::string &sPlayerName) const noexcept
 Get the player. More...
 
const shared_ptr< Team > & getTeamFull (int32_t nTeam) const noexcept
 Get the team. More...
 
const shared_ptr< Team > & getTeamFull (const std::string &sTeamName) const noexcept
 Get the team. More...
 
bool setTotTeams (int32_t nTeams) noexcept
 Set the total number of teams. More...
 
bool setTotPlayers (int32_t nPlayers) noexcept
 Set the the total number of players. More...
 
int32_t getTotTeams () const noexcept override
 The total number of teams. More...
 
const shared_ptr< PrefTeamgetTeam (int32_t nTeam) const noexcept override
 Get team by number. More...
 
const shared_ptr< PrefTeamgetTeam (const std::string &sTeamName) const noexcept override
 Get team by name. More...
 
std::vector< std::string > getTeamNames () const noexcept override
 The number of teams. More...
 
int32_t getTotPlayers () const noexcept override
 The number of players. More...
 
const shared_ptr< PrefPlayergetPlayer (int32_t nPlayer) const noexcept override
 Get player by number. More...
 
const shared_ptr< PrefPlayergetPlayer (const std::string &sPlayerName) const noexcept override
 Get player by name. More...
 
void getTeammate (int32_t nPlayer, int32_t &nTeam, int32_t &nMate) const noexcept override
 Get team an mate number from player number. More...
 
int32_t getTotHumanPlayers () const noexcept override
 The number of human players. More...
 
int32_t getTotAIPlayers () const noexcept override
 The number of AI players. More...
 
int32_t getTotHumanTeams () const noexcept override
 The number of human teams. More...
 
int32_t getTotAITeams () const noexcept override
 The number of AI teams. More...
 
Variant getOptionValue (const std::string &sOptionName) const noexcept override
 Returns value of a game option. More...
 
bool setOptionValue (const std::string &sOptionName, const Variant &oValue) noexcept
 Set the value of a game's option. More...
 
bool getPlayerKeyActionFromCapabilityKey (int32_t nCapabilityId, stmi::HARDWARE_KEY eKey, shared_ptr< PrefPlayer > &refPlayer, int32_t &nKeyActionId) const noexcept override
 Given a key generated by a capability, return the player's key action. More...
 
bool getPlayerKeyActionFromCapabilityKey (int32_t nCapabilityId, stmi::HARDWARE_KEY eKey, int32_t &nTeam, int32_t &nMate, int32_t &nKeyActionId) const noexcept override
 Given a key generated by a capability, return the player's key action. More...
 
bool getCapabilityPlayer (int32_t nCapabilityId, shared_ptr< PrefPlayer > &refPlayer) const noexcept override
 The player to which a capability is assigned. More...
 
bool getCapabilityPlayer (int32_t nCapabilityId, int32_t &nTeam, int32_t &nMate) const noexcept override
 The player to which a capability is assigned. More...
 
bool getCapabilityPlayerFull (int32_t nCapabilityId, shared_ptr< Player > &refPlayer) const noexcept
 The player to which a capability is assigned. More...
 
std::vector< stmi::Capability::ClassgetCapabilityClasses () const noexcept
 Get all the capability classes handled by the preferences. More...
 
int32_t getCapabilityClassDeviceIdx (stmi::Capability const *p0Capability) const noexcept
 Get the capability class device index of a capability. More...
 
shared_ptr< stmi::CapabilitygetCapabilityFromClassDeviceIdx (const stmi::Capability::Class &oCapaClass, int32_t nDeviceIdx) const noexcept
 Get the capability from the capability class device index. More...
 
const shared_ptr< AppConfig > & getAppConfig () const noexcept override
 The application config. More...
 
const shared_ptr< StdConfig > & getStdConfig () noexcept
 
- Public Member Functions inherited from stmg::AppPreferences
virtual ~AppPreferences () noexcept=default
 

Constructor & Destructor Documentation

◆ StdPreferences() [1/2]

stmg::StdPreferences::StdPreferences ( const shared_ptr< StdConfig > &  refStdConfig)
explicitnoexcept

Constructor.

The initial number of teams is defined by AppConstraints::m_nTeamsMin which is obtained with refStdConfig->getAppConstraints(). Initially each team has one human player.

The instance is created in edit mode.

Parameters
refStdConfigThe configuration. Cannot be null.

◆ StdPreferences() [2/2]

stmg::StdPreferences::StdPreferences ( const StdPreferences oSource)
noexcept

Copy constructor.

Parameters
oSourceThe source.

Member Function Documentation

◆ getAppConfig()

const shared_ptr<AppConfig>& stmg::StdPreferences::getAppConfig ( ) const
inlineoverridevirtualnoexcept

The application config.

Returns
The app config. Is not null.

Implements stmg::AppPreferences.

◆ getCapabilityClassDeviceIdx()

int32_t stmg::StdPreferences::getCapabilityClassDeviceIdx ( stmi::Capability const *  p0Capability) const
noexcept

Get the capability class device index of a capability.

The device index is not the device id. The device index is an internal representation of the preferences. All the capabilities of the same capability class are assigned indexes 0, 1, and so on.

This can be used to serialize the preferences.

Parameters
p0CapabilityThe capability. Cannot be null.
Returns
The device index. Is >= 0 for a supported capability or -1 if not found (the corresponding device was removed).

◆ getCapabilityClasses()

std::vector<stmi::Capability::Class> stmg::StdPreferences::getCapabilityClasses ( ) const
noexcept

Get all the capability classes handled by the preferences.

These are the classes of devices that can be assigned to key actions and players.

Returns
The capability classes.

◆ getCapabilityFromClassDeviceIdx()

shared_ptr<stmi::Capability> stmg::StdPreferences::getCapabilityFromClassDeviceIdx ( const stmi::Capability::Class oCapaClass,
int32_t  nDeviceIdx 
) const
noexcept

Get the capability from the capability class device index.

It is the inverse of getCapabilityClassDeviceIdx().

This can be used to serialize the preferences.

Parameters
oCapaClassThe capability class. Must be in getCapabilityClasses().
nDeviceIdxThe device index. Must be >= 0.
Returns
The capability or null if not found (device index too high).

◆ getCapabilityPlayer() [1/2]

bool stmg::StdPreferences::getCapabilityPlayer ( int32_t  nCapabilityId,
shared_ptr< PrefPlayer > &  refPlayer 
) const
overridevirtualnoexcept

The player to which a capability is assigned.

Parameters
nCapabilityIdThe id of the capability.
refPlayerThe player the capability is assigned to or unchanged.
Returns
Whether the capability is assigned to a player.

Implements stmg::AppPreferences.

◆ getCapabilityPlayer() [2/2]

bool stmg::StdPreferences::getCapabilityPlayer ( int32_t  nCapabilityId,
int32_t &  nTeam,
int32_t &  nMate 
) const
overridevirtualnoexcept

The player to which a capability is assigned.

Parameters
nCapabilityIdThe id of the capability.
nTeamThe team of the player the capability is assigned to or unchanged.
nMateThe mate of the player the capability is assigned to or unchanged.
Returns
Whether the capability is assigned to a player.

Implements stmg::AppPreferences.

◆ getCapabilityPlayerFull()

bool stmg::StdPreferences::getCapabilityPlayerFull ( int32_t  nCapabilityId,
shared_ptr< Player > &  refPlayer 
) const
noexcept

The player to which a capability is assigned.

Parameters
nCapabilityIdThe id of the capability.
refPlayer(output) The player the capability is assigned to or unchanged.
Returns
Whether the capability is assigned to a player.

◆ getMaxPlayerNameLength()

int32_t stmg::StdPreferences::getMaxPlayerNameLength ( ) const
noexcept

The player name maximum length in unicode characters.

Returns
The max length.

◆ getMaxTeamNameLength()

int32_t stmg::StdPreferences::getMaxTeamNameLength ( ) const
noexcept

The team name maximum length in unicode characters.

Returns
The max length.

◆ getOptionValue()

Variant stmg::StdPreferences::getOptionValue ( const std::string &  sName) const
overridevirtualnoexcept

Returns value of a game option.

Parameters
sNameThe option name.
Returns
The value. Null if option name not defined.

Implements stmg::AppPreferences.

◆ getPlayer() [1/2]

const shared_ptr<PrefPlayer> stmg::StdPreferences::getPlayer ( int32_t  nPlayer) const
overridevirtualnoexcept

Get player by number.

Parameters
nPlayerThe player number. Must be >=0 and < AppPreferences::getTotPlayers().
Returns
The player. Is not null.

Implements stmg::AppPreferences.

◆ getPlayer() [2/2]

const shared_ptr<PrefPlayer> stmg::StdPreferences::getPlayer ( const std::string &  sPlayerName) const
overridevirtualnoexcept

Get player by name.

Player names are unique.

Parameters
sPlayerNameThe name of the player. Cannot be empty.
Returns
The player or null if not found.

Implements stmg::AppPreferences.

◆ getPlayerFull() [1/2]

const shared_ptr<Player>& stmg::StdPreferences::getPlayerFull ( int32_t  nPlayer) const
noexcept

Get the player.

Parameters
nPlayerThe player number. Must be valid.
Returns
The player. Is not null.

◆ getPlayerFull() [2/2]

const shared_ptr<Player>& stmg::StdPreferences::getPlayerFull ( const std::string &  sPlayerName) const
noexcept

Get the player.

Parameters
sPlayerNameThe player name. Must exist.
Returns
The player. Is not null.

◆ getPlayerKeyActionFromCapabilityKey() [1/2]

bool stmg::StdPreferences::getPlayerKeyActionFromCapabilityKey ( int32_t  nCapabilityId,
stmi::HARDWARE_KEY  eKey,
shared_ptr< PrefPlayer > &  refPlayer,
int32_t &  nKeyActionId 
) const
overridevirtualnoexcept

Given a key generated by a capability, return the player's key action.

Parameters
nCapabilityIdThe id of the capability.
eKeyThe key. Cannot be stmi::HK_NULL.
refPlayerThe player associated with the key. Unchanged if not found.
nKeyActionIdThe key action associated with the key. Unchanged if not found.
Returns
Whether a key action is associated with the capability key.

Implements stmg::AppPreferences.

◆ getPlayerKeyActionFromCapabilityKey() [2/2]

bool stmg::StdPreferences::getPlayerKeyActionFromCapabilityKey ( int32_t  nCapabilityId,
stmi::HARDWARE_KEY  eKey,
int32_t &  nTeam,
int32_t &  nMate,
int32_t &  nKeyActionId 
) const
overridevirtualnoexcept

Given a key generated by a capability, return the player's key action.

Parameters
nCapabilityIdThe id of the capability.
eKeyThe key. Cannot be stmi::HK_NULL.
nTeamThe player's team associated with the key, unchanged if not found.
nMateThe player's mate associated with the key, unchanged if not found.
nKeyActionIdThe key action associated with the key. Unchanged if not found.
Returns
Whether a key action is associated with the capability key.

Implements stmg::AppPreferences.

◆ getStdConfig()

const shared_ptr<StdConfig>& stmg::StdPreferences::getStdConfig ( )
inlinenoexcept

◆ getTeam() [1/2]

const shared_ptr<PrefTeam> stmg::StdPreferences::getTeam ( int32_t  nTeam) const
overridevirtualnoexcept

Get team by number.

Parameters
nTeamThe team number. Must be >=0 and < AppPreferences::getTotTeams().
Returns
The team. Is not null.

Implements stmg::AppPreferences.

◆ getTeam() [2/2]

const shared_ptr<PrefTeam> stmg::StdPreferences::getTeam ( const std::string &  sTeamName) const
overridevirtualnoexcept

Get team by name.

Team names are unique.

Parameters
sTeamNameThe name of the team. Cannot be empty.
Returns
The team or null if not found.

Implements stmg::AppPreferences.

◆ getTeamFull() [1/2]

const shared_ptr<Team>& stmg::StdPreferences::getTeamFull ( int32_t  nTeam) const
noexcept

Get the team.

Parameters
nTeamThe team number. Must be valid.
Returns
The team. Is not null.

◆ getTeamFull() [2/2]

const shared_ptr<Team>& stmg::StdPreferences::getTeamFull ( const std::string &  sTeamName) const
noexcept

Get the team.

Parameters
sTeamNameThe team name. Must exist.
Returns
The team. Is not null.

◆ getTeammate()

void stmg::StdPreferences::getTeammate ( int32_t  nPlayer,
int32_t &  nTeam,
int32_t &  nMate 
) const
overridevirtualnoexcept

Get team an mate number from player number.

Parameters
nPlayerThe player number. Must be valid.
nTeam(output) The team of the player.
nMate(output) The mate number within the team of the player.

Implements stmg::AppPreferences.

◆ getTeamNames()

std::vector<std::string> stmg::StdPreferences::getTeamNames ( ) const
overridevirtualnoexcept

The number of teams.

Returns
Total number of teams. Is always >= 1.

Implements stmg::AppPreferences.

◆ getTotAIPlayers()

int32_t stmg::StdPreferences::getTotAIPlayers ( ) const
overridevirtualnoexcept

The number of AI players.

Returns
Number of non human players.

Implements stmg::AppPreferences.

◆ getTotAITeams()

int32_t stmg::StdPreferences::getTotAITeams ( ) const
overridevirtualnoexcept

The number of AI teams.

Returns
Number of non human teams.

Implements stmg::AppPreferences.

◆ getTotHumanPlayers()

int32_t stmg::StdPreferences::getTotHumanPlayers ( ) const
overridevirtualnoexcept

The number of human players.

Returns
Number of non AI players.

Implements stmg::AppPreferences.

◆ getTotHumanTeams()

int32_t stmg::StdPreferences::getTotHumanTeams ( ) const
overridevirtualnoexcept

The number of human teams.

Returns
Number of non AI teams.

Implements stmg::AppPreferences.

◆ getTotPlayers()

int32_t stmg::StdPreferences::getTotPlayers ( ) const
overridevirtualnoexcept

The number of players.

Returns
Total number of players. Is always >= 1.

Implements stmg::AppPreferences.

◆ getTotTeams()

int32_t stmg::StdPreferences::getTotTeams ( ) const
overridevirtualnoexcept

The total number of teams.

Returns
The number of teams. Is always >= 1.

Implements stmg::AppPreferences.

◆ isInEditMode()

bool stmg::StdPreferences::isInEditMode ( ) const
inlinenoexcept

Get edit mode.

Returns
Whether in edit mode.

◆ operator=()

StdPreferences& stmg::StdPreferences::operator= ( const StdPreferences oSource)
noexcept

Copy assignment.

Parameters
oSourceThe source.
Returns
The copy.

◆ playerMoveDown()

bool stmg::StdPreferences::playerMoveDown ( const std::string &  sPlayerName)
noexcept

Move a player down in the hierarchy.

If the player is not the last mate of the team it is swapped with the following mate. If the player is the last mate of the team it is swapped with the first mate of the following team. The swap is only allowed if it doesn't violate some AI player constraint.

The last player of the last team cannot be moved down.

Parameters
sPlayerNameThe player's name. Must exist.
Returns
Whether the player could be moved down.

◆ playerMoveUp()

bool stmg::StdPreferences::playerMoveUp ( const std::string &  sPlayerName)
noexcept

Move a player up in the hierarchy.

If the player is not the first mate of the team it is swapped with the preceding mate. If the player is the first mate of the team it is swapped with the last mate of the preceding team. The swap is only allowed if it doesn't violate some AI player constraint.

The first player of the first team cannot be moved up.

Parameters
sPlayerNameThe player's name. Must exist.
Returns
Whether the player could be moved up.

◆ playerTeamDown()

bool stmg::StdPreferences::playerTeamDown ( const std::string &  sPlayerName)
noexcept

Move a player to the following team in the hierarchy.

If a player violates some AI constraints the function might fail.

A player of the last team cannot "team down".

Parameters
sPlayerNameThe player's name. Must exist.
Returns
Whether the player could be moved to the following team.

◆ playerTeamUp()

bool stmg::StdPreferences::playerTeamUp ( const std::string &  sPlayerName)
noexcept

Move a player to the preceding team in the hierarchy.

If a player violates some AI constraints the function might fail.

A player of the first team cannot "team up".

Parameters
sPlayerNameThe player's name. Must exist.
Returns
Whether the player could be moved to the preceding team.

◆ setEditMode()

void stmg::StdPreferences::setEditMode ( bool  bInEditMode)
noexcept

Set edit mode.

The instance can be either in edit or in running mode. In running mode players and teams cannot be added or removed, options cannot be changed. In running mode removed and then re-added devices are automatically assigned to a player.

Parameters
bInEditModeThe chosen mode.

◆ setOptionValue()

bool stmg::StdPreferences::setOptionValue ( const std::string &  sOptionName,
const Variant oValue 
)
noexcept

Set the value of a game's option.

Parameters
sOptionNameThe name of the option (OwnerType::GAME). Must exist and not be read-only.
oValueThe new value.
Returns
Whether the operation succeeded.

◆ setTotPlayers()

bool stmg::StdPreferences::setTotPlayers ( int32_t  nPlayers)
noexcept

Set the the total number of players.

If the constraints limited the addition or removal of players false is returned. The limiting factors might be the minimum number of teams, the maximum number of AI mates, etc.

Unless it's full, new players are added to the last team, otherwise to the preceding team and so on.

Parameters
nPlayersThe number of players. Must be >= 0.
Returns
Whether the desired number could be set.

◆ setTotTeams()

bool stmg::StdPreferences::setTotTeams ( int32_t  nTeams)
noexcept

Set the total number of teams.

If the constraints limited the addition or removal of teams false is returned. The limiting factor might be the minimum or maximum number of teams.

Parameters
nTeamsThe number of teams. Must be >= 0.
Returns
Whether the desired number could be set.