#pragma once #include "CComponent.h" #include "CNode.h" #include "CWrapableBase.h" #include "CConVar.h" #include #include class CConVarManager : public CComponent //TODO cvar descriptions TODO const { public: using CVar = CWrapableBase; using CVarRawPtr = CVar*; using CVarPtr = std::unique_ptr; using RealCVar = CConVar; using RealCVarRawPtr = RealCVar*; using RealCVarPtr = std::unique_ptr; using CVarNode = CNode; bool V_Init() override; bool IsConVarExist(const std::string& path); CVarRawPtr GetConVar(const std::string& path); bool V_ScriptInit(std::shared_ptr state, sol::table table) override; CVarNode* AddConVar(const std::string& path, CVarRawPtr ptr); //ptr then will be handled by unique_ptr inside CConVarManager::Root bool DeleteConVar(const std::string& path); //true - deleted, false - error occured CVarNode* GetRealConVarNode(const std::string& path); RealCVar& GetRealConVar(const std::string& path); template T GetConVarValue(const std::string& path, T defval = T{}) { //std::shared_lock guard(m_Mutex); //TODO is required? CVarRawPtr cvar = GetConVar(path); if(!cvar) { return defval; } return cvar->GetCastValue(); } template bool SetConVarValue(const std::string& path, const T& _val) { //std::shared_lock guard(m_Mutex); //TODO is required? CVarRawPtr cvar = GetConVar(path); if(!cvar) { return false; } cvar->SetCastValue(_val); return true; } CVarNode Root; DEFINE_SOL_USERTYPE(); DEFINE_COMPONENT(); private: std::shared_mutex m_Mutex; };