2016-03-04 23:02:44 +00:00
|
|
|
|
#include "hecl/hecl.hpp"
|
|
|
|
|
#include "hecl/CVar.hpp"
|
2018-01-22 02:40:11 +00:00
|
|
|
|
#include "hecl/CVarManager.hpp"
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2016-03-04 23:02:44 +00:00
|
|
|
|
#include <athena/Utility.hpp>
|
2015-12-02 21:11:10 +00:00
|
|
|
|
#include <algorithm>
|
2018-01-14 06:40:42 +00:00
|
|
|
|
#include <sstream>
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2016-03-04 23:02:44 +00:00
|
|
|
|
namespace hecl
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
extern CVar* com_developer;
|
|
|
|
|
extern CVar* com_enableCheats;
|
|
|
|
|
|
2017-11-13 06:13:53 +00:00
|
|
|
|
using namespace std::literals;
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
CVar::CVar(std::string_view name, std::string_view value, std::string_view help, EType type, EFlags flags, CVarManager& parent)
|
|
|
|
|
: m_mgr(parent)
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
m_name = std::string(name);
|
|
|
|
|
m_value = std::string(value);
|
|
|
|
|
m_defaultValue = std::string(value);
|
|
|
|
|
m_help = help;
|
|
|
|
|
m_type = type;
|
|
|
|
|
m_flags = flags;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
CVar::CVar(std::string_view name, std::string_view value, std::string_view help, CVar::EFlags flags, CVarManager& parent)
|
|
|
|
|
: m_mgr(parent)
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
m_flags = flags;
|
|
|
|
|
m_name = std::string(name);
|
|
|
|
|
m_help = help;
|
|
|
|
|
m_type = EType::Literal;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Unlock the cvar for writing if readonly
|
|
|
|
|
unlock();
|
2016-01-04 05:25:00 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
fromLiteral(value);
|
|
|
|
|
m_defaultValue = m_value;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Lock the cvar
|
|
|
|
|
lock();
|
|
|
|
|
// Clear the modified flag, just incase lock didn't do it.
|
|
|
|
|
m_flags = flags;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
CVar::CVar(std::string_view name, const atVec4f& value, std::string_view help, EFlags flags, CVarManager& parent)
|
|
|
|
|
: m_mgr(parent)
|
|
|
|
|
{
|
|
|
|
|
m_name = std::string(name);
|
|
|
|
|
m_help = help;
|
|
|
|
|
m_type = EType::Vec4f;
|
|
|
|
|
m_flags = flags;
|
2016-01-04 05:25:00 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Unlock the cvar for writing if readonly
|
|
|
|
|
unlock();
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
fromVec4f(value);
|
|
|
|
|
m_defaultValue = m_value;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Lock the cvar
|
|
|
|
|
lock();
|
|
|
|
|
// Clear the modified flag, just incase lock didn't do it.
|
|
|
|
|
m_flags = flags;
|
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
CVar::CVar(std::string_view name, float value, std::string_view help, EFlags flags, CVarManager& parent)
|
|
|
|
|
: m_mgr(parent)
|
|
|
|
|
{
|
|
|
|
|
m_name = std::string(name);
|
|
|
|
|
m_help = help;
|
|
|
|
|
m_type = EType::Float;
|
|
|
|
|
m_flags = flags;
|
2016-01-04 05:25:00 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Unlock the cvar for writing if readonly
|
|
|
|
|
unlock();
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
fromFloat(value);
|
|
|
|
|
m_defaultValue = m_value;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Lock the cvar
|
|
|
|
|
lock();
|
|
|
|
|
// Clear the modified flag, just incase lock didn't do it.
|
|
|
|
|
m_flags = flags;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
CVar::CVar(std::string_view name, bool value, std::string_view help, CVar::EFlags flags, CVarManager& parent)
|
|
|
|
|
: m_mgr(parent)
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
m_name = std::string(name);
|
|
|
|
|
m_help = help;
|
|
|
|
|
m_type = EType::Boolean;
|
|
|
|
|
m_flags = flags;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Unlock the cvar for writing if readonly
|
|
|
|
|
unlock();
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
fromBoolean(value);
|
|
|
|
|
m_defaultValue = m_value;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Lock the cvar
|
|
|
|
|
lock();
|
|
|
|
|
// Clear the modified flag, just incase lock didn't do it.
|
|
|
|
|
m_flags = flags;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
CVar::CVar(std::string_view name, int value, std::string_view help, CVar::EFlags flags, CVarManager& parent)
|
|
|
|
|
: m_mgr(parent)
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
m_name = std::string(name);
|
|
|
|
|
m_help = help;
|
|
|
|
|
m_type = EType::Integer;
|
|
|
|
|
m_flags = flags;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Unlock the cvar for writing if readonly
|
|
|
|
|
unlock();
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
fromInteger(value);
|
|
|
|
|
m_defaultValue = m_value;
|
|
|
|
|
|
|
|
|
|
// Lock the cvar
|
|
|
|
|
lock();
|
|
|
|
|
// Clear the modified flag, just incase lock didn't do it.
|
|
|
|
|
m_flags = flags;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
std::string CVar::help() const
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
return std::string(m_help + (m_defaultValue != std::string() ? "\ndefault: " + m_defaultValue : "") +
|
2018-05-02 00:41:51 +00:00
|
|
|
|
(isReadOnly() ? " [ReadOnly]" : ""));
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
atVec4f CVar::toVec4f(bool* isValid) const
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Vec4f)
|
|
|
|
|
{
|
|
|
|
|
if (isValid != nullptr)
|
|
|
|
|
*isValid = false;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
return atVec4f{};
|
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isValid != nullptr)
|
|
|
|
|
*isValid = true;
|
|
|
|
|
|
|
|
|
|
atVec4f vec;
|
|
|
|
|
std::sscanf(m_value.c_str(), "%f %f %f %f", &vec.vec[0], &vec.vec[1], &vec.vec[2], &vec.vec[3]);
|
|
|
|
|
|
|
|
|
|
return vec;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
float CVar::toFloat(bool* isValid) const
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Float)
|
|
|
|
|
{
|
|
|
|
|
if (isValid)
|
|
|
|
|
*isValid = false;
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return strtof(m_value.c_str(), nullptr);
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::toBoolean(bool* isValid) const
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Boolean)
|
|
|
|
|
{
|
|
|
|
|
if (isValid)
|
|
|
|
|
*isValid = false;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// We don't want to modify the original value;
|
|
|
|
|
std::string tmp = m_value;
|
|
|
|
|
athena::utility::tolower(tmp);
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (!tmp.compare("yes") || !tmp.compare("true") || !tmp.compare("1"))
|
|
|
|
|
{
|
|
|
|
|
if (isValid)
|
|
|
|
|
*isValid = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (!tmp.compare("no") || !tmp.compare("false") || !tmp.compare("0"))
|
|
|
|
|
{
|
|
|
|
|
if (isValid)
|
|
|
|
|
*isValid = true;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
return false;
|
2018-01-22 02:40:11 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isValid)
|
|
|
|
|
*isValid = false;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
return false;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
int CVar::toInteger(bool* isValid) const
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Integer)
|
|
|
|
|
{
|
|
|
|
|
if (isValid)
|
|
|
|
|
*isValid = false;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return strtol(m_value.c_str(), nullptr, 0);
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
const std::string CVar::toLiteral(bool* isValid) const
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Literal && (com_developer && com_developer->toBoolean()))
|
|
|
|
|
{
|
|
|
|
|
if (isValid != nullptr)
|
|
|
|
|
*isValid = false;
|
|
|
|
|
}
|
|
|
|
|
else if (isValid != nullptr)
|
|
|
|
|
*isValid = true;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
// Even if it's not a literal, it's still safe to return
|
|
|
|
|
return m_value;
|
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
const std::wstring CVar::toWideLiteral(bool* isValid) const
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Literal && (com_developer && com_developer->toBoolean()))
|
|
|
|
|
{
|
|
|
|
|
if (isValid != nullptr)
|
|
|
|
|
*isValid = false;
|
|
|
|
|
}
|
|
|
|
|
else if (isValid != nullptr)
|
|
|
|
|
*isValid = true;
|
|
|
|
|
|
|
|
|
|
// Even if it's not a literal, it's still safe to return
|
|
|
|
|
return hecl::UTF8ToWide(m_value);
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::fromVec4f(const atVec4f& val)
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
|
|
|
|
return false;
|
|
|
|
|
else if (isCheat())
|
2018-01-15 12:34:02 +00:00
|
|
|
|
return false;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Vec4f)
|
|
|
|
|
return false;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
|
|
|
|
return false;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
m_value.assign(hecl::Format("%f %f %f %f", val.vec[0], val.vec[1], val.vec[2], val.vec[3]));
|
|
|
|
|
m_flags |= EFlags::Modified;
|
|
|
|
|
return true;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::fromFloat(float val)
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
|
|
|
|
return false;
|
|
|
|
|
else if (isCheat())
|
|
|
|
|
return false;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Float)
|
|
|
|
|
return false;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
m_value.assign(hecl::Format("%f", val));
|
|
|
|
|
setModified();
|
|
|
|
|
return true;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::fromBoolean(bool val)
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
|
|
|
|
return false;
|
|
|
|
|
else if (isCheat())
|
2015-12-02 21:11:10 +00:00
|
|
|
|
return false;
|
2018-01-22 02:40:11 +00:00
|
|
|
|
|
|
|
|
|
if (m_type != EType::Boolean)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (val)
|
|
|
|
|
m_value = "true"sv;
|
|
|
|
|
else
|
|
|
|
|
m_value = "false"sv;
|
|
|
|
|
|
|
|
|
|
setModified();
|
2018-01-15 12:34:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::fromInteger(int val)
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
|
|
|
|
return false;
|
|
|
|
|
else if (isCheat())
|
|
|
|
|
return false;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Integer)
|
|
|
|
|
return false;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
m_value = hecl::Format("%i", val);
|
|
|
|
|
setModified();
|
|
|
|
|
return true;
|
2018-01-14 02:39:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::fromLiteral(std::string_view val)
|
2018-01-14 02:39:32 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean()))
|
|
|
|
|
return false;
|
|
|
|
|
else if (isCheat())
|
|
|
|
|
return false;
|
2018-01-14 02:39:32 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (m_type != EType::Literal)
|
|
|
|
|
return false;
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isReadOnly() && (com_developer && !com_developer->toBoolean()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
m_value.assign(val);
|
|
|
|
|
setModified();
|
|
|
|
|
return true;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::fromLiteral(std::wstring_view val)
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
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()))
|
2018-01-15 12:34:02 +00:00
|
|
|
|
return false;
|
2018-01-22 02:40:11 +00:00
|
|
|
|
|
|
|
|
|
m_value.assign(hecl::WideToUTF8(val));
|
|
|
|
|
setModified();
|
2018-01-15 12:34:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::fromLiteralToType(std::string_view val, bool setDefault)
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
switch (m_type)
|
|
|
|
|
{
|
|
|
|
|
case EType::Literal: return fromLiteral(val);
|
|
|
|
|
case EType::Boolean:
|
|
|
|
|
{
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << std::boolalpha << val;
|
|
|
|
|
bool v;
|
|
|
|
|
ss >> v;
|
|
|
|
|
return fromBoolean(v);
|
|
|
|
|
}
|
|
|
|
|
case EType::Float:
|
|
|
|
|
{
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << val;
|
|
|
|
|
float v;
|
|
|
|
|
ss >> v;
|
|
|
|
|
return fromFloat(v);
|
|
|
|
|
}
|
|
|
|
|
case EType::Integer:
|
|
|
|
|
{
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << val;
|
|
|
|
|
int v;
|
|
|
|
|
ss >> v;
|
|
|
|
|
return fromInteger(v);
|
|
|
|
|
}
|
|
|
|
|
case EType::Vec4f:
|
|
|
|
|
{
|
|
|
|
|
atVec4f vec;
|
|
|
|
|
std::sscanf(val.data(), "%f %f %f %f", &vec.vec[0], &vec.vec[1], &vec.vec[2], &vec.vec[3]);
|
|
|
|
|
return fromVec4f(vec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (setDefault)
|
|
|
|
|
m_value = m_defaultValue;
|
|
|
|
|
return false;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::fromLiteralToType(std::wstring_view val, bool setDefault)
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
switch (m_type)
|
|
|
|
|
{
|
|
|
|
|
case EType::Literal: return fromLiteral(val);
|
|
|
|
|
case EType::Boolean:
|
|
|
|
|
{
|
|
|
|
|
std::wstringstream ss;
|
|
|
|
|
ss << std::boolalpha << val;
|
|
|
|
|
bool v;
|
|
|
|
|
ss >> v;
|
|
|
|
|
return fromBoolean(v);
|
|
|
|
|
}
|
|
|
|
|
case EType::Float:
|
|
|
|
|
{
|
|
|
|
|
std::wstringstream ss;
|
|
|
|
|
ss << val;
|
|
|
|
|
float v;
|
|
|
|
|
ss >> v;
|
|
|
|
|
return fromFloat(v);
|
|
|
|
|
}
|
|
|
|
|
case EType::Integer:
|
|
|
|
|
{
|
|
|
|
|
std::wstringstream ss;
|
|
|
|
|
ss << val;
|
|
|
|
|
int v;
|
|
|
|
|
ss >> v;
|
|
|
|
|
return fromInteger(v);
|
|
|
|
|
}
|
|
|
|
|
case EType::Vec4f:
|
|
|
|
|
{
|
|
|
|
|
atVec4f vec;
|
|
|
|
|
std::swscanf(val.data(), L"%f %f %f %f", &vec.vec[0], &vec.vec[1], &vec.vec[2], &vec.vec[3]);
|
|
|
|
|
return fromVec4f(vec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (setDefault)
|
|
|
|
|
m_value = m_defaultValue;
|
|
|
|
|
return false;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::isModified() const { return int(m_flags & EFlags::Modified) != 0;}
|
|
|
|
|
bool CVar::modificationRequiresRestart() const { return int(m_flags & EFlags::ModifyRestart) != 0; }
|
2018-01-14 07:37:00 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::isReadOnly() const { return int(m_flags & EFlags::ReadOnly) != 0; }
|
2018-01-14 07:37:00 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::isCheat() const { return int(m_flags & EFlags::Cheat) != 0; }
|
2018-01-14 07:37:00 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::isHidden() const { return int(m_flags & EFlags::Hidden) != 0; }
|
|
|
|
|
|
|
|
|
|
bool CVar::isArchive() const { return int(m_flags & EFlags::Archive) != 0; }
|
|
|
|
|
|
|
|
|
|
bool CVar::isInternalArchivable() const { return int(m_flags & EFlags::InternalArchivable) != 0; }
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
bool CVar::wasDeserialized() const { return m_wasDeserialized; }
|
|
|
|
|
|
|
|
|
|
bool CVar::hasDefaultValue() const { return m_defaultValue == m_value; }
|
|
|
|
|
|
|
|
|
|
void CVar::clearModified()
|
2018-01-15 12:34:02 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (!modificationRequiresRestart())
|
|
|
|
|
m_flags &= ~EFlags::Modified;
|
2018-01-15 12:34:02 +00:00
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
void CVar::setModified() { m_flags |= EFlags::Modified; }
|
|
|
|
|
|
|
|
|
|
void CVar::unlock()
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (isReadOnly() && !m_unlocked)
|
|
|
|
|
{
|
|
|
|
|
m_oldFlags = m_flags;
|
|
|
|
|
m_flags &= ~EFlags::ReadOnly;
|
|
|
|
|
m_unlocked = true;
|
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
void CVar::lock()
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
if (!isReadOnly() && m_unlocked)
|
|
|
|
|
{
|
|
|
|
|
m_flags = m_oldFlags;
|
|
|
|
|
m_unlocked = false;
|
|
|
|
|
}
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 02:40:11 +00:00
|
|
|
|
void CVar::dispatch()
|
2015-12-02 21:11:10 +00:00
|
|
|
|
{
|
2018-01-22 02:40:11 +00:00
|
|
|
|
for (const ListenerFunc& listen : m_listeners)
|
|
|
|
|
listen(this);
|
2015-12-02 21:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|