PGE API 0.4
PR00F's Game Engine full documentation
|
PR00F's Game Engine profile config handler class. More...
PR00F's Game Engine profile config handler class.
Definition at line 25 of file PGEcfgProfiles.h.
#include <PGEcfgProfiles.h>
Public Member Functions | |
PGEcfgProfiles () | |
virtual | ~PGEcfgProfiles () |
CConsole & | getConsole () const |
Returns access to console preset with logger module name as this class. | |
bool | reinitialize (const char *gameTitle) |
Resets initial state. | |
void | shutdown () |
Resets everything. | |
std::string | getLangFileName () const |
Returns the file name of the selected language file. | |
int | readLanguageData (std::string **&langTable) const |
Reads the language file into the given table. | |
bool | areProfilesInMyDocs () const |
Returns whether player profiles are stored in user documents folder. | |
std::string | getPathToProfiles () const |
Returns the path to the profiles. | |
int | getProfilesCount () const |
Returns the number of found profiles. | |
const std::string ** | getProfilesList () const |
Returns the found profile names. | |
const std::string ** | getProfilePlayersList () const |
Returns the found player names in profiles. | |
int | addProfile (const char *sUser, const char *sNick) |
Creates a new profile. | |
int | deleteProfile (int nIndex) |
Deletes the specified profile. | |
void | ProcessCommandLine (const char *szCmdLine) |
Application can pass command line to be parsed for extra one-time configuration. | |
const std::map< std::string, PGEcfgVariable > & | getCommandLineVars () const |
int | getProfileIndex () const |
Gets index of active profile. | |
const std::string | getProfileName () const |
Gets name of active profile. | |
bool | setProfile (int nIndex) |
Sets active profile by index. | |
bool | setProfile (const std::string &sProfileName) |
Sets active profileby name. | |
void | DeleteVar (const char *varName) |
Deletes a cvar by the given name. | |
bool | readConfiguration () |
Loads configuration for current profile from file. | |
bool | writeConfiguration () |
Saves configuration for current profile to file. | |
![]() | |
PGEcfgFile (bool bRequireAllAcceptedVarsDefineRequirement, bool bCaseSensitiveVars) | |
virtual | ~PGEcfgFile () |
CConsole & | getConsole () const |
Returns access to console preset with logger module name as this class. | |
std::map< std::string, PGEcfgVariable > & | getVars () |
const std::map< std::string, PGEcfgVariable > & | getVars () const |
bool | load (const char *fname) |
Loads variables from the given config file. | |
bool | save (const char *fname="") const |
Saves variables to the given config file. | |
const std::string & | getFilename () const |
const std::string & | getPathToFile () const |
bool | getAllAcceptedVarsDefineRequirement () const |
bool | getCaseSensitiveVars () const |
const std::set< std::string > & | getAcceptedVars () const |
bool | setAcceptedVars (const std::set< std::string > &newAcceptedVars) |
std::vector< std::string > & | getTemplate () |
Returns the lines of the template generated from the loaded config file. | |
const std::vector< std::string > & | getTemplate () const |
Returns the lines of the template generated from the loaded config file. | |
PGEcfgFile (const PGEcfgFile &other) | |
PGEcfgFile & | operator= (const PGEcfgFile &other) |
Static Public Member Functions | |
static const char * | getLoggerModuleName () |
Returns the logger module name of this class. | |
static std::string | getMyDocsFolder () |
Returns the path to user documents. | |
![]() | |
static const char * | getLoggerModuleName () |
Returns the logger module name of this class. | |
Protected Member Functions | |
virtual bool | validateOnLoad (std::ifstream &f) const override |
Validate the file being processed by load(). | |
virtual bool | validateOnSave (std::ofstream &f) const override |
Validate the file being processed by save(). | |
std::map< std::string, PGEcfgVariable > & | getCommandLineVars () |
![]() |
Private Member Functions | |
PGEcfgProfiles (const PGEcfgProfiles &) | |
PGEcfgProfiles & | operator= (const PGEcfgProfiles &) |
bool | getPlayerNameFromFile (const char *cFilename, std::string &sPlayerName) |
Gets player name from given cfg file. | |
void | LoadProfilesList () |
Fills up sFoundProfiles and sFoundProfilePlayerNames. | |
void | ClearVars () |
Removes all cvars. | |
Static Private Member Functions | |
static bool | findMyDocsFolder () |
Stores user docs folder path in sPathToMyDocs. | |
Private Attributes | |
std::string | sLangFileName |
Filename of language file. | |
bool | bMainCFGinMyDocs |
Do we store cfg file in user documents folder? | |
std::string | sPathToProfiles |
Search path for profiles based on bMainCFGinMyDocs and pPathToMyDocs. | |
int | nProfilesCount |
Number of found profiles. | |
std::string ** | sFoundProfiles |
Directory names of found profiles (just add ".cfg" for profile file). | |
std::string ** | sFoundProfilePlayerNames |
Found profile names (player names). | |
int | nActiveProfile |
Index of active profile. | |
std::string | m_sActiveProfile |
Name of active profile. | |
PGEcfgVariable | cvarWrong |
This is returned when trying to access an invalid cvar. | |
std::map< std::string, PGEcfgVariable > | m_commandLineVars |
Any added variables parsed by ProcessCommandLine(). | |
Static Private Attributes | |
static std::string | sPathToMyDocs |
Path to user documents. | |
Additional Inherited Members | |
![]() | |
static bool | lineIsValueAssignment (const std::string &sTrimmedLine, bool bCaseSensitiveVars, std::string &sVar, std::string &sValue, bool &bParseError) |
![]() | |
std::set< std::string > | m_acceptedVars |
std::map< std::string, PGEcfgVariable > | m_vars |
|
explicit |
Definition at line 22 of file PGEcfgProfiles.cpp.
|
virtual |
Definition at line 33 of file PGEcfgProfiles.cpp.
|
private |
Definition at line 752 of file PGEcfgProfiles.cpp.
int PGEcfgProfiles::addProfile | ( | const char * | sUser, |
const char * | sNick ) |
Creates a new profile.
This creates a profile directory and a profile file in it immediately. Only the mandatory CVAR containing the nickname of the profile is saved to the file, no other CVARs. You have to explicitly call writeConfiguration() to save all variables based on the config template.
Creating a new profile won't change the current profile. You have to manually switch to it instead. The current profile index may change but it will still index the original active profile.
sUser | The username for the profile, which will be used primarily for the filename. Thus some characters are restricted (?, *, etc ...). Cannot be empty. |
sNick | The nickname / player name for the profile, which can hold any character. This is what is shown in a game, for example in frag table. Cannot be empty. |
Definition at line 310 of file PGEcfgProfiles.cpp.
bool PGEcfgProfiles::areProfilesInMyDocs | ( | ) | const |
Returns whether player profiles are stored in user documents folder.
Example: if true, MyDocs/<GAMENAME>/profiles, otherwise program folder/gamedata/profiles.
Definition at line 246 of file PGEcfgProfiles.cpp.
|
private |
int PGEcfgProfiles::deleteProfile | ( | int | nIndex | ) |
Deletes the specified profile.
This deletes the profile directory and the profile file in it immediately. If the given index is the current profile, the current profile index will be -1 after deletion. Otherwise, the current profile and any loaded cvars won't be changed. The current profile index may change.
nIndex | The index of the profile to be deleted. Only non-negative values are accepted. |
Definition at line 405 of file PGEcfgProfiles.cpp.
void PGEcfgProfiles::DeleteVar | ( | const char * | varName | ) |
Deletes a cvar by the given name.
You cannot delete the cvar holding the name of the player because it would invalidate the profile. If you delete a cvar from the current profile, it will be deleted only on memory-level. To save changes made to the current profile, use writeConfiguration().
Definition at line 640 of file PGEcfgProfiles.cpp.
|
staticprivate |
Stores user docs folder path in sPathToMyDocs.
Definition at line 769 of file PGEcfgProfiles.cpp.
|
protected |
Definition at line 740 of file PGEcfgProfiles.cpp.
const std::map< std::string, PGEcfgVariable > & PGEcfgProfiles::getCommandLineVars | ( | ) | const |
Definition at line 496 of file PGEcfgProfiles.cpp.
CConsole & PGEcfgProfiles::getConsole | ( | ) | const |
Returns access to console preset with logger module name as this class.
Intentionally not virtual, so the getConsole() in derived class should hide this instead of overriding.
Definition at line 46 of file PGEcfgProfiles.cpp.
string PGEcfgProfiles::getLangFileName | ( | ) | const |
Returns the file name of the selected language file.
Definition at line 165 of file PGEcfgProfiles.cpp.
|
static |
Returns the logger module name of this class.
Intentionally not virtual, so derived class should hide this instead of overriding. Not even private, so user can also access this from outside, for any reason like controlling log filtering per logger module name.
Definition at line 59 of file PGEcfgProfiles.cpp.
|
static |
Returns the path to user documents.
Definition at line 69 of file PGEcfgProfiles.cpp.
string PGEcfgProfiles::getPathToProfiles | ( | ) | const |
Returns the path to the profiles.
Definition at line 256 of file PGEcfgProfiles.cpp.
|
private |
Gets player name from given cfg file.
Definition at line 798 of file PGEcfgProfiles.cpp.
int PGEcfgProfiles::getProfileIndex | ( | ) | const |
Gets index of active profile.
Definition at line 505 of file PGEcfgProfiles.cpp.
const std::string PGEcfgProfiles::getProfileName | ( | ) | const |
Gets name of active profile.
Definition at line 513 of file PGEcfgProfiles.cpp.
const string ** PGEcfgProfiles::getProfilePlayersList | ( | ) | const |
Returns the found player names in profiles.
Definition at line 283 of file PGEcfgProfiles.cpp.
int PGEcfgProfiles::getProfilesCount | ( | ) | const |
Returns the number of found profiles.
Definition at line 265 of file PGEcfgProfiles.cpp.
const string ** PGEcfgProfiles::getProfilesList | ( | ) | const |
Returns the found profile names.
Definition at line 274 of file PGEcfgProfiles.cpp.
|
private |
Fills up sFoundProfiles and sFoundProfilePlayerNames.
Counts the found profiles (directories with cfg file inside them with the same name), stores it in nProfilesCount. If the current profile index is valid, it may change during this function but the current profile and loaded cvars remain unchanged.
Definition at line 840 of file PGEcfgProfiles.cpp.
|
private |
Definition at line 759 of file PGEcfgProfiles.cpp.
void PGEcfgProfiles::ProcessCommandLine | ( | const char * | szCmdLine | ) |
Application can pass command line to be parsed for extra one-time configuration.
Definition at line 452 of file PGEcfgProfiles.cpp.
bool PGEcfgProfiles::readConfiguration | ( | ) |
Loads configuration for current profile from file.
Note that config variables parsed earlier by ProcessCommandLine() will overwrite the variables read from profile config file.
Definition at line 658 of file PGEcfgProfiles.cpp.
int PGEcfgProfiles::readLanguageData | ( | std::string **& | langTable | ) | const |
Reads the language file into the given table.
The given pointer will be valid only if the returned number is positive;
Definition at line 177 of file PGEcfgProfiles.cpp.
bool PGEcfgProfiles::reinitialize | ( | const char * | gameTitle | ) |
Resets initial state.
Unloads active profile and resets active profile index to -1 (no active profile selected), and re-reads profiles, language data, etc.
Definition at line 81 of file PGEcfgProfiles.cpp.
bool PGEcfgProfiles::setProfile | ( | const std::string & | sProfileName | ) |
Sets active profileby name.
Sets active profile by name.
This also implies reading the configuration data for the given profile. The active profile index will be -1 and active profile name will be empty if the given name is valid but an error occured while reading config data. Note that config variables parsed earlier by ProcessCommandLine() will overwrite the variables read from profile config file.
sProfileName | A valid profile name. Specifying an empty string will not load anything but erase all previously loaded config variables. |
Definition at line 586 of file PGEcfgProfiles.cpp.
bool PGEcfgProfiles::setProfile | ( | int | nIndex | ) |
Sets active profile by index.
This also implies reading the configuration data for the given profile. The active profile index will be -1 and active profile name will be empty if the given index is valid but an error occured while reading config data. Note that config variables parsed earlier by ProcessCommandLine() will overwrite the variables read from profile config file.
nIndex | A valid profile index in [0..getProfilesCount()-1] range. Specifying -1 will not load anything but erase all previously loaded config variables. Specifying index less than -1 will log error but leave the configuration unchanged. |
Definition at line 531 of file PGEcfgProfiles.cpp.
void PGEcfgProfiles::shutdown | ( | ) |
Resets everything.
Definition at line 137 of file PGEcfgProfiles.cpp.
|
overrideprotectedvirtual |
Validate the file being processed by load().
Derived class can override this to provide a validating function, e.g. special way to decide if the file being loaded actually has valid format. This is invoked by load() before trying to parse the file. The stream must be already opened prior to calling this function. This function must not open/close the given file stream. Upon success, load() will continue reading the file from the point until this function has read the file.
Reimplemented from PGEcfgFile.
Definition at line 717 of file PGEcfgProfiles.cpp.
|
overrideprotectedvirtual |
Validate the file being processed by save().
Derived class can override this to provide a validating function which makes the file compatible with the optionally overridden validateOnLoad() function. For example, if validateOnLoad() checks for a special header, then validateOnSave() is responsible for writing that special header into the file. This is invoked by save() when trying to write the file. The stream must be already opened prior to calling this function. This function must not open/close the given file stream. Upon success, save() will continue writing the file from the point this function has written the file.
Reimplemented from PGEcfgFile.
Definition at line 734 of file PGEcfgProfiles.cpp.
bool PGEcfgProfiles::writeConfiguration | ( | ) |
Saves configuration for current profile to file.
PGE never invokes this function, so it won't overwrite any file automatically. Application has to call this function whenever it wants to save to file.
Definition at line 693 of file PGEcfgProfiles.cpp.
|
private |
Do we store cfg file in user documents folder?
Definition at line 86 of file PGEcfgProfiles.h.
|
private |
This is returned when trying to access an invalid cvar.
Definition at line 93 of file PGEcfgProfiles.h.
|
private |
Any added variables parsed by ProcessCommandLine().
Definition at line 95 of file PGEcfgProfiles.h.
|
private |
Name of active profile.
Definition at line 92 of file PGEcfgProfiles.h.
|
private |
Index of active profile.
Definition at line 91 of file PGEcfgProfiles.h.
|
private |
Number of found profiles.
Definition at line 88 of file PGEcfgProfiles.h.
|
private |
Found profile names (player names).
Definition at line 90 of file PGEcfgProfiles.h.
|
private |
Directory names of found profiles (just add ".cfg" for profile file).
Definition at line 89 of file PGEcfgProfiles.h.
|
private |
Filename of language file.
Definition at line 85 of file PGEcfgProfiles.h.
|
staticprivate |
Path to user documents.
Definition at line 83 of file PGEcfgProfiles.h.
|
private |
Search path for profiles based on bMainCFGinMyDocs and pPathToMyDocs.
Definition at line 87 of file PGEcfgProfiles.h.