RVars: Set "defaults" to the value provided by the constructor
Fixes an issue where all default keys are null when preloading cathook. Loading a config would've unbinded all keys.
This commit is contained in:
parent
a6462dd26f
commit
e9b9cf16b1
@ -30,6 +30,7 @@ public:
|
|||||||
struct VariableDescriptor
|
struct VariableDescriptor
|
||||||
{
|
{
|
||||||
explicit VariableDescriptor(IVariable &variable);
|
explicit VariableDescriptor(IVariable &variable);
|
||||||
|
VariableDescriptor(IVariable &variable, std::string value);
|
||||||
|
|
||||||
bool isChanged();
|
bool isChanged();
|
||||||
|
|
||||||
@ -42,8 +43,9 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void add(IVariable &me, std::string name);
|
void add(IVariable &me, std::string name);
|
||||||
|
void add(IVariable &me, std::string name, std::string value);
|
||||||
IVariable *lookup(const std::string &string);
|
IVariable *lookup(const std::string &string);
|
||||||
|
|
||||||
std::unordered_map<std::string, VariableDescriptor> registered{};
|
std::unordered_map<std::string, VariableDescriptor> registered{};
|
||||||
};
|
};
|
||||||
} // namespace settings
|
} // namespace settings
|
||||||
|
@ -10,6 +10,7 @@ namespace settings
|
|||||||
{
|
{
|
||||||
|
|
||||||
void registerVariable(IVariable &variable, std::string name);
|
void registerVariable(IVariable &variable, std::string name);
|
||||||
|
void registerVariable(IVariable &variable, std::string name, std::string value);
|
||||||
|
|
||||||
template <typename T> class RegisteredVariableProxy : public Variable<T>
|
template <typename T> class RegisteredVariableProxy : public Variable<T>
|
||||||
{
|
{
|
||||||
@ -24,7 +25,7 @@ public:
|
|||||||
RegisteredVariableProxy(std::string name, std::string value)
|
RegisteredVariableProxy(std::string name, std::string value)
|
||||||
{
|
{
|
||||||
this->fromString(value);
|
this->fromString(value);
|
||||||
registerVariable(*this, name);
|
registerVariable(*this, name, value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,6 +24,16 @@ void Manager::add(IVariable &me, std::string name)
|
|||||||
registered.emplace(name, me);
|
registered.emplace(name, me);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::add(IVariable &me, std::string name, std::string value)
|
||||||
|
{
|
||||||
|
if (registered.find(name) != registered.end())
|
||||||
|
{
|
||||||
|
logging::Info(("Double registering variable: " + name).c_str());
|
||||||
|
throw std::runtime_error("Double registering variable: " + name);
|
||||||
|
}
|
||||||
|
registered.emplace(name, Manager::VariableDescriptor{ me, value });
|
||||||
|
}
|
||||||
|
|
||||||
IVariable *Manager::lookup(const std::string &string)
|
IVariable *Manager::lookup(const std::string &string)
|
||||||
{
|
{
|
||||||
auto it = registered.find(string);
|
auto it = registered.find(string);
|
||||||
@ -38,6 +48,12 @@ Manager::VariableDescriptor::VariableDescriptor(IVariable &variable) : variable(
|
|||||||
defaults = variable.toString();
|
defaults = variable.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Manager::VariableDescriptor::VariableDescriptor(IVariable &variable, std::string value) : variable(variable)
|
||||||
|
{
|
||||||
|
type = variable.getType();
|
||||||
|
defaults = value;
|
||||||
|
}
|
||||||
|
|
||||||
bool Manager::VariableDescriptor::isChanged()
|
bool Manager::VariableDescriptor::isChanged()
|
||||||
{
|
{
|
||||||
return variable.toString() != defaults;
|
return variable.toString() != defaults;
|
||||||
|
@ -8,3 +8,8 @@ void settings::registerVariable(IVariable &variable, std::string name)
|
|||||||
{
|
{
|
||||||
Manager::instance().add(variable, name);
|
Manager::instance().add(variable, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void settings::registerVariable(IVariable &variable, std::string name, std::string value)
|
||||||
|
{
|
||||||
|
Manager::instance().add(variable, name, value);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user