Can now unload a Config by config:unload()
This commit is contained in:
		
							parent
							
								
									2d84fae2c8
								
							
						
					
					
						commit
						8b3f3b11f0
					
				|  | @ -22,6 +22,7 @@ | |||
| 
 | ||||
| #include "config.h" | ||||
| #include "resourcemanager.h" | ||||
| #include "configmanager.h" | ||||
| 
 | ||||
| #include <framework/otml/otml.h> | ||||
| 
 | ||||
|  | @ -54,6 +55,7 @@ bool Config::unload() | |||
|     if(isLoaded()) { | ||||
|         m_confsDoc = nullptr; | ||||
|         m_fileName = ""; | ||||
|         g_configs.remove(this); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
|  | @ -148,7 +150,7 @@ OTMLNodePtr Config::getNode(const std::string& key) | |||
| 
 | ||||
| bool Config::isLoaded() | ||||
| { | ||||
|     return !m_fileName.empty(); | ||||
|     return !m_fileName.empty() && m_confsDoc; | ||||
| } | ||||
| 
 | ||||
| std::string Config::getFileName() | ||||
|  |  | |||
|  | @ -117,9 +117,13 @@ bool ConfigManager::unload(const std::string& file) | |||
|     ConfigPtr config = get(file); | ||||
|     if(config) { | ||||
|         config->unload(); | ||||
|         m_configs.remove(config); | ||||
|         config = nullptr; | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| void ConfigManager::remove(const ConfigPtr config) | ||||
| { | ||||
|     m_configs.remove(config); | ||||
| } | ||||
|  |  | |||
|  | @ -38,7 +38,9 @@ public: | |||
|     ConfigPtr create(const std::string& file); | ||||
|     ConfigPtr loadSettings(const std::string file); | ||||
|     ConfigPtr load(const std::string& file); | ||||
| 
 | ||||
|     bool unload(const std::string& file); | ||||
|     void remove(const ConfigPtr config); | ||||
| 
 | ||||
| protected: | ||||
|     ConfigPtr m_settings; | ||||
|  |  | |||
|  | @ -194,6 +194,7 @@ void Application::registerLuaFunctions() | |||
|     // Config
 | ||||
|     g_lua.registerClass<Config>(); | ||||
|     g_lua.bindClassMemberFunction<Config>("save", &Config::save); | ||||
|     g_lua.bindClassMemberFunction<Config>("unload", &Config::unload); | ||||
|     g_lua.bindClassMemberFunction<Config>("setValue", &Config::setValue); | ||||
|     g_lua.bindClassMemberFunction<Config>("setList", &Config::setList); | ||||
|     g_lua.bindClassMemberFunction<Config>("getValue", &Config::getValue); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 BenDol
						BenDol