-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ElunaConfig class and remove enabled bool
All config should be handled through this class. There is no need to check internally if Eluna is enabled, if Eluna wasn't enabled it wouldn't ever even reach said checks
- Loading branch information
Showing
18 changed files
with
122 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/> | ||
* This program is free software licensed under GPL version 3 | ||
* Please see the included DOCS/LICENSE.md for more information | ||
*/ | ||
|
||
#include "Config.h" | ||
#include "ElunaConfig.h" | ||
|
||
ElunaConfig::ElunaConfig() | ||
{ | ||
} | ||
|
||
ElunaConfig* ElunaConfig::instance() | ||
{ | ||
static ElunaConfig instance; | ||
return &instance; | ||
} | ||
|
||
ElunaConfig::~ElunaConfig() | ||
{ | ||
} | ||
|
||
void ElunaConfig::Initialize() | ||
{ | ||
// Load bools | ||
SetConfig(CONFIG_ELUNA_ENABLED, "Eluna.Enabled", true); | ||
SetConfig(CONFIG_ELUNA_COMPATIBILITY_MODE, "Eluna.CompatibilityMode", true); | ||
SetConfig(CONFIG_ELUNA_TRACEBACK, "Eluna.TraceBack", false); | ||
|
||
// Load strings | ||
SetConfig(CONFIG_ELUNA_SCRIPT_PATH, "Eluna.ScriptPath", "lua_scripts"); | ||
SetConfig(CONFIG_ELUNA_ONLY_ON_MAPS, "Eluna.OnlyOnMaps", ""); | ||
} | ||
|
||
void ElunaConfig::SetConfig(ElunaConfigBoolValues index, char const* fieldname, bool defvalue) | ||
{ | ||
#ifdef TRINITY | ||
SetConfig(index, sConfigMgr->GetBoolDefault(fieldname, defvalue)); | ||
#endif | ||
} | ||
|
||
void ElunaConfig::SetConfig(ElunaConfigStringValues index, char const* fieldname, std::string defvalue) | ||
{ | ||
#ifdef TRINITY | ||
SetConfig(index, sConfigMgr->GetStringDefault(fieldname, defvalue)); | ||
#endif | ||
} | ||
|
||
bool ElunaConfig::IsElunaEnabled() | ||
{ | ||
return GetConfig(CONFIG_ELUNA_ENABLED); | ||
} | ||
|
||
bool ElunaConfig::IsElunaCompatibilityMode() | ||
{ | ||
return GetConfig(CONFIG_ELUNA_COMPATIBILITY_MODE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/> | ||
* This program is free software licensed under GPL version 3 | ||
* Please see the included DOCS/LICENSE.md for more information | ||
*/ | ||
|
||
#ifndef _ELUNACONFIG_H | ||
#define _ELUNACONFIG_H | ||
|
||
#include "ElunaUtility.h" | ||
|
||
enum ElunaConfigBoolValues | ||
{ | ||
CONFIG_ELUNA_ENABLED, | ||
CONFIG_ELUNA_COMPATIBILITY_MODE, | ||
CONFIG_ELUNA_TRACEBACK, | ||
CONFIG_ELUNA_BOOL_COUNT | ||
}; | ||
|
||
enum ElunaConfigStringValues | ||
{ | ||
CONFIG_ELUNA_SCRIPT_PATH, | ||
CONFIG_ELUNA_ONLY_ON_MAPS, | ||
CONFIG_ELUNA_STRING_COUNT | ||
}; | ||
|
||
class ElunaConfig | ||
{ | ||
private: | ||
ElunaConfig(); | ||
~ElunaConfig(); | ||
ElunaConfig(ElunaConfig const&) = delete; | ||
ElunaConfig& operator=(ElunaConfig const&) = delete; | ||
|
||
public: | ||
static ElunaConfig* instance(); | ||
|
||
void Initialize(); | ||
|
||
bool GetConfig(ElunaConfigBoolValues index) const { return _configBoolValues[index]; } | ||
const std::string& GetConfig(ElunaConfigStringValues index) const { return _configStringValues[index]; } | ||
void SetConfig(ElunaConfigBoolValues index, bool value) { _configBoolValues[index] = value; } | ||
void SetConfig(ElunaConfigStringValues index, std::string value) { _configStringValues[index] = value; } | ||
|
||
bool IsElunaEnabled(); | ||
bool IsElunaCompatibilityMode(); | ||
|
||
private: | ||
bool _configBoolValues[CONFIG_ELUNA_BOOL_COUNT]; | ||
std::string _configStringValues[CONFIG_ELUNA_STRING_COUNT]; | ||
|
||
void SetConfig(ElunaConfigBoolValues index, char const* fieldname, bool defvalue); | ||
void SetConfig(ElunaConfigStringValues index, char const* fieldname, std::string defvalue); | ||
}; | ||
|
||
#define sElunaConfig ElunaConfig::instance() | ||
|
||
#endif //_ELUNACONFIG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.