mirror of https://github.com/AxioDL/metaforce.git
Restore old behavior
This commit is contained in:
parent
9422debddb
commit
9c053b53e8
|
@ -216,7 +216,7 @@ int CVar::toInteger(bool* isValid) const
|
||||||
|
|
||||||
const std::string CVar::toLiteral(bool* isValid) const
|
const std::string CVar::toLiteral(bool* isValid) const
|
||||||
{
|
{
|
||||||
if (m_type != EType::Literal /*&& (com_developer && com_developer->toBoolean())*/)
|
if (m_type != EType::Literal && (com_developer && com_developer->toBoolean()))
|
||||||
{
|
{
|
||||||
if (isValid != nullptr)
|
if (isValid != nullptr)
|
||||||
*isValid = false;
|
*isValid = false;
|
||||||
|
@ -230,7 +230,7 @@ const std::string CVar::toLiteral(bool* isValid) const
|
||||||
|
|
||||||
const std::wstring CVar::toWideLiteral(bool* isValid) const
|
const std::wstring CVar::toWideLiteral(bool* isValid) const
|
||||||
{
|
{
|
||||||
if (m_type != EType::Literal /*&& (com_developer && com_developer->toBoolean())*/)
|
if (m_type != EType::Literal && (com_developer && com_developer->toBoolean()))
|
||||||
{
|
{
|
||||||
if (isValid != nullptr)
|
if (isValid != nullptr)
|
||||||
*isValid = false;
|
*isValid = false;
|
||||||
|
@ -244,13 +244,15 @@ const std::wstring CVar::toWideLiteral(bool* isValid) const
|
||||||
|
|
||||||
bool CVar::fromColor(const Zeus::CColor& val)
|
bool CVar::fromColor(const Zeus::CColor& val)
|
||||||
{
|
{
|
||||||
if (isCheat())
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
||||||
|
return false;
|
||||||
|
else if (isCheat())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_type != EType::Color)
|
if (m_type != EType::Color)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isReadOnly())
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_value.assign(CBasics::Stringize("%i %i %i %i", unsigned(val.r), unsigned(val.g), unsigned(val.b), unsigned(val.a)));
|
m_value.assign(CBasics::Stringize("%i %i %i %i", unsigned(val.r), unsigned(val.g), unsigned(val.b), unsigned(val.a)));
|
||||||
|
@ -260,13 +262,15 @@ bool CVar::fromColor(const Zeus::CColor& val)
|
||||||
|
|
||||||
bool CVar::fromFloat(float val)
|
bool CVar::fromFloat(float val)
|
||||||
{
|
{
|
||||||
if (isCheat() /*&& (!com_developer->toBoolean() && !com_enableCheats->toBoolean())*/)
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
||||||
|
return false;
|
||||||
|
else if (isCheat())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_type != EType::Float)
|
if (m_type != EType::Float)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_value.assign(CBasics::Stringize("%f", val));
|
m_value.assign(CBasics::Stringize("%f", val));
|
||||||
|
@ -276,13 +280,15 @@ bool CVar::fromFloat(float val)
|
||||||
|
|
||||||
bool CVar::fromBoolean(bool val)
|
bool CVar::fromBoolean(bool val)
|
||||||
{
|
{
|
||||||
if (isCheat() /*&& (!com_developer->toBoolean() && !com_enableCheats->toBoolean())*/)
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
||||||
|
return false;
|
||||||
|
else if (isCheat())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_type != EType::Boolean)
|
if (m_type != EType::Boolean)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (val)
|
if (val)
|
||||||
|
@ -296,13 +302,15 @@ bool CVar::fromBoolean(bool val)
|
||||||
|
|
||||||
bool CVar::fromInteger(int val)
|
bool CVar::fromInteger(int val)
|
||||||
{
|
{
|
||||||
if (isCheat() /*&& (!com_developer->toBoolean() && !com_enableCheats->toBoolean())*/)
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
||||||
|
return false;
|
||||||
|
else if (isCheat())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_type != EType::Integer)
|
if (m_type != EType::Integer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_value = CBasics::Stringize("%i", val);
|
m_value = CBasics::Stringize("%i", val);
|
||||||
|
@ -312,13 +320,15 @@ bool CVar::fromInteger(int val)
|
||||||
|
|
||||||
bool CVar::fromLiteral(const std::string& val)
|
bool CVar::fromLiteral(const std::string& val)
|
||||||
{
|
{
|
||||||
if (isCheat() /*&& (!com_developer->toBoolean() && !com_enableCheats->toBoolean())*/)
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
||||||
|
return false;
|
||||||
|
else if (isCheat())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_type != EType::Literal)
|
if (m_type != EType::Literal)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_value.assign(val);
|
m_value.assign(val);
|
||||||
|
@ -328,13 +338,15 @@ bool CVar::fromLiteral(const std::string& val)
|
||||||
|
|
||||||
bool CVar::fromLiteral(const std::wstring& val)
|
bool CVar::fromLiteral(const std::wstring& val)
|
||||||
{
|
{
|
||||||
if (isCheat() /*&& (!com_developer->toBoolean() && !com_enableCheats->toBoolean())*/)
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
||||||
|
return false;
|
||||||
|
else if (isCheat())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_type != EType::Literal)
|
if (m_type != EType::Literal)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_value.assign(HECL::WideToUTF8(val));
|
m_value.assign(HECL::WideToUTF8(val));
|
||||||
|
@ -380,5 +392,11 @@ void CVar::lock()
|
||||||
clearModified();
|
clearModified();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CVar::dispatch()
|
||||||
|
{
|
||||||
|
for (const ListenerFunc& listen : m_listeners)
|
||||||
|
listen(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define CVAR_HPP
|
#define CVAR_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
#include "CColor.hpp"
|
#include "CColor.hpp"
|
||||||
#include "DataSpec/DNACommon/CVar.hpp"
|
#include "DataSpec/DNACommon/CVar.hpp"
|
||||||
|
|
||||||
|
@ -14,6 +15,8 @@ class CVar : protected DNACVAR::CVar
|
||||||
friend class CVarManager;
|
friend class CVarManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef std::function<void(CVar*)> ListenerFunc;
|
||||||
|
|
||||||
using EType = DNACVAR::EType;
|
using EType = DNACVAR::EType;
|
||||||
using EFlags = DNACVAR::EFlags;
|
using EFlags = DNACVAR::EFlags;
|
||||||
|
|
||||||
|
@ -46,7 +49,6 @@ public:
|
||||||
bool isBoolean() const { return m_type == EType::Boolean; }
|
bool isBoolean() const { return m_type == EType::Boolean; }
|
||||||
bool isInteger() const { return m_type == EType::Integer; }
|
bool isInteger() const { return m_type == EType::Integer; }
|
||||||
bool isLiteral() const { return m_type == EType::Literal; }
|
bool isLiteral() const { return m_type == EType::Literal; }
|
||||||
bool isBinding() const { return m_type == EType::Bind; }
|
|
||||||
bool isColor() const { return m_type == EType::Color; }
|
bool isColor() const { return m_type == EType::Color; }
|
||||||
bool isModified() const;
|
bool isModified() const;
|
||||||
bool isReadOnly() const;
|
bool isReadOnly() const;
|
||||||
|
@ -73,13 +75,19 @@ public:
|
||||||
* \see unlock
|
* \see unlock
|
||||||
*/
|
*/
|
||||||
void lock();
|
void lock();
|
||||||
|
|
||||||
|
void addListener(ListenerFunc func) { m_listeners.push_back(func); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void dispatch();
|
||||||
std::string m_help;
|
std::string m_help;
|
||||||
std::string m_defaultValue;
|
std::string m_defaultValue;
|
||||||
EFlags m_flags;
|
EFlags m_flags;
|
||||||
bool m_allowedWrite;
|
bool m_allowedWrite;
|
||||||
|
|
||||||
CVarManager& m_mgr;
|
CVarManager& m_mgr;
|
||||||
|
|
||||||
|
std::vector<ListenerFunc> m_listeners;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ CVarManager::CVarManager(HECL::Runtime::FileStoreManager& store, bool useBinary)
|
||||||
{
|
{
|
||||||
com_configfile = newCVar("config", "File to store configuration", std::string("config"), CVar::EFlags::System);
|
com_configfile = newCVar("config", "File to store configuration", std::string("config"), CVar::EFlags::System);
|
||||||
com_developer = newCVar("developer", "Enables developer mode", false, (CVar::EFlags::System | CVar::EFlags::Cheat | CVar::EFlags::ReadOnly));
|
com_developer = newCVar("developer", "Enables developer mode", false, (CVar::EFlags::System | CVar::EFlags::Cheat | CVar::EFlags::ReadOnly));
|
||||||
com_enableCheats = newCVar("iamaweiner", "Enable cheats", false, (CVar::EFlags::System | CVar::EFlags::Archive | CVar::EFlags::ReadOnly | CVar::EFlags::Hidden));
|
com_enableCheats = newCVar("iamaweiner", "Enable cheats", false, (CVar::EFlags::System | CVar::EFlags::ReadOnly | CVar::EFlags::Hidden));
|
||||||
r_clearColor = newCVar("r_clearcolor", "Sets the clear color for the frame buffer", Zeus::CColor{Zeus::Comp8(255), 255, 255}, (CVar::EFlags::System | CVar::EFlags::Archive));
|
r_clearColor = newCVar("r_clearcolor", "Sets the clear color for the frame buffer", Zeus::CColor{Zeus::Comp8(255), 255, 255}, (CVar::EFlags::System | CVar::EFlags::Archive));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,16 @@ CVarManager::~CVarManager()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CVarManager::update()
|
||||||
|
{
|
||||||
|
for (const std::pair<std::string, CVar*> pair : m_cvars)
|
||||||
|
if (pair.second->isModified())
|
||||||
|
{
|
||||||
|
pair.second->dispatch();
|
||||||
|
pair.second->clearModified();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CVarManager::registerCVar(CVar* cvar)
|
bool CVarManager::registerCVar(CVar* cvar)
|
||||||
{
|
{
|
||||||
std::string tmp = cvar->name();
|
std::string tmp = cvar->name();
|
||||||
|
|
|
@ -24,6 +24,7 @@ class CVarManager
|
||||||
CVar* ret(new CVar(name, value, help, flags, *this));
|
CVar* ret(new CVar(name, value, help, flags, *this));
|
||||||
if (registerCVar(ret))
|
if (registerCVar(ret))
|
||||||
{
|
{
|
||||||
|
if (ret->isArchive())
|
||||||
deserialize(ret);
|
deserialize(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +38,7 @@ public:
|
||||||
CVarManager(HECL::Runtime::FileStoreManager& store, bool useBinary = false);
|
CVarManager(HECL::Runtime::FileStoreManager& store, bool useBinary = false);
|
||||||
~CVarManager();
|
~CVarManager();
|
||||||
|
|
||||||
|
void update();
|
||||||
CVar* newCVar(const std::string& name, const std::string& help, const Zeus::CColor& value, CVar::EFlags flags)
|
CVar* newCVar(const std::string& name, const std::string& help, const Zeus::CColor& value, CVar::EFlags flags)
|
||||||
{ return _newCVar<Zeus::CColor>(name, help, value, flags); }
|
{ return _newCVar<Zeus::CColor>(name, help, value, flags); }
|
||||||
CVar* newCVar(const std::string& name, const std::string& help, const std::string& value, CVar::EFlags flags)
|
CVar* newCVar(const std::string& name, const std::string& help, const std::string& value, CVar::EFlags flags)
|
||||||
|
@ -50,7 +52,7 @@ public:
|
||||||
|
|
||||||
bool registerCVar(CVar* cvar);
|
bool registerCVar(CVar* cvar);
|
||||||
|
|
||||||
CVar*findCVar(const std::string& name);
|
CVar* findCVar(const std::string& name);
|
||||||
|
|
||||||
std::vector<CVar*> archivedCVars() const;
|
std::vector<CVar*> archivedCVars() const;
|
||||||
std::vector<CVar*> cvars() const;
|
std::vector<CVar*> cvars() const;
|
||||||
|
|
Loading…
Reference in New Issue