rename g_config
This commit is contained in:
parent
5ab943ce13
commit
b1ec45783e
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
Configs g_config;
|
||||
Configs g_configs;
|
||||
|
||||
bool Configs::load(const std::string& fileName)
|
||||
{
|
||||
|
@ -99,43 +99,43 @@ void Configs::setValue(const std::string &key, bool value)
|
|||
setValue(key,"false");
|
||||
}
|
||||
|
||||
const std::string &Configs::getString(const std::string &key)
|
||||
const std::string &Configs::getString(const std::string &key) const
|
||||
{
|
||||
auto iter = m_confsMap.find(key);
|
||||
if(iter == m_confsMap.end()) {
|
||||
auto it = m_confsMap.find(key);
|
||||
if(it == m_confsMap.end()) {
|
||||
warning("Config value %s not found", key.c_str());
|
||||
static std::string emptystr;
|
||||
return emptystr;
|
||||
}
|
||||
return iter->second;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
float Configs::getFloat(const std::string &key)
|
||||
float Configs::getFloat(const std::string &key) const
|
||||
{
|
||||
auto iter = m_confsMap.find(key);
|
||||
if(iter == m_confsMap.end()) {
|
||||
auto it = m_confsMap.find(key);
|
||||
if(it == m_confsMap.end()) {
|
||||
warning("Config value %s not found", key.c_str());
|
||||
return 0;
|
||||
}
|
||||
return convertType<float, std::string>(iter->second);
|
||||
return convertType<float, std::string>(it->second);
|
||||
}
|
||||
|
||||
bool Configs::getBoolean(const std::string &key)
|
||||
bool Configs::getBoolean(const std::string &key) const
|
||||
{
|
||||
auto iter = m_confsMap.find(key);
|
||||
if(iter == m_confsMap.end()) {
|
||||
auto it = m_confsMap.find(key);
|
||||
if(it == m_confsMap.end()) {
|
||||
warning("Config value %s not found", key.c_str());
|
||||
return 0;
|
||||
}
|
||||
return (iter->second == "true");
|
||||
return (it->second == "true");
|
||||
}
|
||||
|
||||
int Configs::getInteger(const std::string &key)
|
||||
int Configs::getInteger(const std::string &key) const
|
||||
{
|
||||
auto iter = m_confsMap.find(key);
|
||||
if(iter == m_confsMap.end()) {
|
||||
auto it = m_confsMap.find(key);
|
||||
if(it == m_confsMap.end()) {
|
||||
warning("Config value %s not found", key.c_str());
|
||||
return 0;
|
||||
}
|
||||
return convertType<int, std::string>(iter->second);
|
||||
return convertType<int, std::string>(it->second);
|
||||
}
|
||||
|
|
|
@ -44,16 +44,16 @@ public:
|
|||
void setValue(const std::string &key, bool value);
|
||||
void setValue(const std::string &key, int value);
|
||||
|
||||
const std::string &getString(const std::string &key);
|
||||
float getFloat(const std::string &key);
|
||||
bool getBoolean(const std::string &key);
|
||||
int getInteger(const std::string &key);
|
||||
const std::string &getString(const std::string &key) const;
|
||||
float getFloat(const std::string &key) const;
|
||||
bool getBoolean(const std::string &key) const;
|
||||
int getInteger(const std::string &key) const;
|
||||
|
||||
private:
|
||||
std::string m_fileName;
|
||||
std::map<std::string, std::string> m_confsMap;
|
||||
};
|
||||
|
||||
extern Configs g_config;
|
||||
extern Configs g_configs;
|
||||
|
||||
#endif // CONFIGS_H
|
||||
|
|
|
@ -36,12 +36,10 @@ public:
|
|||
/// Load font from file
|
||||
bool load(const std::string &file);
|
||||
|
||||
std::string& getName() { return m_name; }
|
||||
const std::string& getName() const { return m_name; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Font> FontPtr;
|
||||
|
||||
#endif // FONT_H
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
void init();
|
||||
void terminate();
|
||||
|
||||
/// Check if a GL extension is supported
|
||||
bool isExtensionSupported(const char *extension);
|
||||
|
||||
/// Called after every window resize
|
||||
|
|
32
src/main.cpp
32
src/main.cpp
|
@ -53,22 +53,22 @@ void setDefaultConfigs()
|
|||
int defHeight = 480;
|
||||
|
||||
// init on screen center
|
||||
g_config.setValue("window x", (Platform::getDisplayWidth() - defWidth)/2);
|
||||
g_config.setValue("window y", (Platform::getDisplayHeight() - defHeight)/2);
|
||||
g_configs.setValue("window x", (Platform::getDisplayWidth() - defWidth)/2);
|
||||
g_configs.setValue("window y", (Platform::getDisplayHeight() - defHeight)/2);
|
||||
|
||||
g_config.setValue("window width", defWidth);
|
||||
g_config.setValue("window height", defHeight);
|
||||
g_config.setValue("window maximized", false);
|
||||
g_configs.setValue("window width", defWidth);
|
||||
g_configs.setValue("window height", defHeight);
|
||||
g_configs.setValue("window maximized", false);
|
||||
}
|
||||
|
||||
void saveConfigs()
|
||||
{
|
||||
g_config.setValue("window x", Platform::getWindowX());
|
||||
g_config.setValue("window y", Platform::getWindowY());
|
||||
g_config.setValue("window width", Platform::getWindowWidth());
|
||||
g_config.setValue("window height", Platform::getWindowHeight());
|
||||
g_config.setValue("window maximized", Platform::isWindowMaximized());
|
||||
g_config.save();
|
||||
g_configs.setValue("window x", Platform::getWindowX());
|
||||
g_configs.setValue("window y", Platform::getWindowY());
|
||||
g_configs.setValue("window width", Platform::getWindowWidth());
|
||||
g_configs.setValue("window height", Platform::getWindowHeight());
|
||||
g_configs.setValue("window maximized", Platform::isWindowMaximized());
|
||||
g_configs.save();
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
|
@ -90,16 +90,16 @@ int main(int argc, const char *argv[])
|
|||
setDefaultConfigs();
|
||||
|
||||
// load configurations
|
||||
if(!g_config.load("config.yml"))
|
||||
if(!g_configs.load("config.yml"))
|
||||
notice("Could not read configuration file, default configurations will be used.");
|
||||
|
||||
notice("OTClient 0.1.0");
|
||||
|
||||
// create the window
|
||||
Platform::createWindow(g_config.getInteger("window x"), g_config.getInteger("window y"),
|
||||
g_config.getInteger("window width"), g_config.getInteger("window height"),
|
||||
Platform::createWindow(g_configs.getInteger("window x"), g_configs.getInteger("window y"),
|
||||
g_configs.getInteger("window width"), g_configs.getInteger("window height"),
|
||||
640, 480,
|
||||
g_config.getBoolean("window maximized"));
|
||||
g_configs.getBoolean("window maximized"));
|
||||
Platform::setWindowTitle("OTClient");
|
||||
Platform::setVsync();
|
||||
|
||||
|
@ -108,7 +108,7 @@ int main(int argc, const char *argv[])
|
|||
|
||||
// state scope
|
||||
{
|
||||
std::shared_ptr<MenuState> menuState(new MenuState());
|
||||
std::shared_ptr<MenuState> menuState(new MenuState);
|
||||
g_engine.changeState(menuState.get());
|
||||
|
||||
Platform::showWindow();
|
||||
|
|
Loading…
Reference in New Issue