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
|
||||
{
|
||||
if (m_type != EType::Literal /*&& (com_developer && com_developer->toBoolean())*/)
|
||||
if (m_type != EType::Literal && (com_developer && com_developer->toBoolean()))
|
||||
{
|
||||
if (isValid != nullptr)
|
||||
*isValid = false;
|
||||
|
@ -230,7 +230,7 @@ const std::string CVar::toLiteral(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)
|
||||
*isValid = false;
|
||||
|
@ -244,13 +244,15 @@ const std::wstring CVar::toWideLiteral(bool* isValid) const
|
|||
|
||||
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;
|
||||
|
||||
if (m_type != EType::Color)
|
||||
return false;
|
||||
|
||||
if (isReadOnly())
|
||||
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||
return false;
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
if (m_type != EType::Float)
|
||||
return false;
|
||||
|
||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
||||
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||
return false;
|
||||
|
||||
m_value.assign(CBasics::Stringize("%f", val));
|
||||
|
@ -276,13 +280,15 @@ bool CVar::fromFloat(float 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;
|
||||
|
||||
if (m_type != EType::Boolean)
|
||||
return false;
|
||||
|
||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
||||
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||
return false;
|
||||
|
||||
if (val)
|
||||
|
@ -296,13 +302,15 @@ bool CVar::fromBoolean(bool 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;
|
||||
|
||||
if (m_type != EType::Integer)
|
||||
return false;
|
||||
|
||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
||||
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||
return false;
|
||||
|
||||
m_value = CBasics::Stringize("%i", val);
|
||||
|
@ -312,13 +320,15 @@ bool CVar::fromInteger(int 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;
|
||||
|
||||
if (m_type != EType::Literal)
|
||||
return false;
|
||||
|
||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
||||
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||
return false;
|
||||
|
||||
m_value.assign(val);
|
||||
|
@ -328,13 +338,15 @@ bool CVar::fromLiteral(const std::string& 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;
|
||||
|
||||
if (m_type != EType::Literal)
|
||||
return false;
|
||||
|
||||
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
||||
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
||||
return false;
|
||||
|
||||
m_value.assign(HECL::WideToUTF8(val));
|
||||
|
@ -380,5 +392,11 @@ void CVar::lock()
|
|||
clearModified();
|
||||
}
|
||||
}
|
||||
|
||||
void CVar::dispatch()
|
||||
{
|
||||
for (const ListenerFunc& listen : m_listeners)
|
||||
listen(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define CVAR_HPP
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include "CColor.hpp"
|
||||
#include "DataSpec/DNACommon/CVar.hpp"
|
||||
|
||||
|
@ -14,6 +15,8 @@ class CVar : protected DNACVAR::CVar
|
|||
friend class CVarManager;
|
||||
|
||||
public:
|
||||
typedef std::function<void(CVar*)> ListenerFunc;
|
||||
|
||||
using EType = DNACVAR::EType;
|
||||
using EFlags = DNACVAR::EFlags;
|
||||
|
||||
|
@ -46,7 +49,6 @@ public:
|
|||
bool isBoolean() const { return m_type == EType::Boolean; }
|
||||
bool isInteger() const { return m_type == EType::Integer; }
|
||||
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 isModified() const;
|
||||
bool isReadOnly() const;
|
||||
|
@ -73,13 +75,19 @@ public:
|
|||
* \see unlock
|
||||
*/
|
||||
void lock();
|
||||
|
||||
void addListener(ListenerFunc func) { m_listeners.push_back(func); }
|
||||
|
||||
private:
|
||||
void dispatch();
|
||||
std::string m_help;
|
||||
std::string m_defaultValue;
|
||||
EFlags m_flags;
|
||||
bool m_allowedWrite;
|
||||
|
||||
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_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));
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
std::string tmp = cvar->name();
|
||||
|
|
|
@ -24,6 +24,7 @@ class CVarManager
|
|||
CVar* ret(new CVar(name, value, help, flags, *this));
|
||||
if (registerCVar(ret))
|
||||
{
|
||||
if (ret->isArchive())
|
||||
deserialize(ret);
|
||||
return ret;
|
||||
}
|
||||
|
@ -37,6 +38,7 @@ public:
|
|||
CVarManager(HECL::Runtime::FileStoreManager& store, bool useBinary = false);
|
||||
~CVarManager();
|
||||
|
||||
void update();
|
||||
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); }
|
||||
CVar* newCVar(const std::string& name, const std::string& help, const std::string& value, CVar::EFlags flags)
|
||||
|
|
Loading…
Reference in New Issue