Skip to content

Commit

Permalink
Replace Qt types in game.cpp (and related)
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed May 12, 2018
1 parent 6208c96 commit 98eedf3
Show file tree
Hide file tree
Showing 22 changed files with 342 additions and 336 deletions.
92 changes: 6 additions & 86 deletions lib/framework/wzconfig.cpp
Expand Up @@ -141,11 +141,6 @@ WzConfig::WzConfig(const WzString &name, WzConfig::warning warning)
pCurrentObj = &mRoot;
}

WzConfig::WzConfig(const QString &name, WzConfig::warning warning)
: WzConfig(WzString::fromUtf8(name.toUtf8().constData()), warning)
{
}

std::vector<WzString> WzConfig::childGroups() const
{
std::vector<WzString> keys;
Expand Down Expand Up @@ -174,19 +169,10 @@ bool WzConfig::contains(const WzString &key) const
return pCurrentObj->find(key.toUtf8()) != pCurrentObj->end();
}

bool WzConfig::contains(const QString &key) const
{
return contains(WzString::fromUtf8(key.toUtf8().constData()));
}

json_variant WzConfig::value(const WzString &key, const json_variant &defaultValue) const
{
return json_getValue(*pCurrentObj, key, defaultValue);
}
json_variant WzConfig::value(const QString &key, const json_variant &defaultValue) const
{
return value(WzString::fromUtf8(key.toUtf8().constData()), defaultValue);
}

nlohmann::json WzConfig::json(const WzString &key, const nlohmann::json &defaultValue) const
{
Expand All @@ -201,38 +187,29 @@ nlohmann::json WzConfig::json(const WzString &key, const nlohmann::json &default
}
}

nlohmann::json WzConfig::json(const QString &key, const nlohmann::json &defaultValue) const
{
return WzConfig::json(WzString::fromUtf8(key.toUtf8().constData()), defaultValue);
}

WzString WzConfig::string(const std::string &key, const std::string &defaultValue) const
WzString WzConfig::string(const WzString &key, const WzString &defaultValue) const
{
auto it = pCurrentObj->find(key);
// TODO: Should this use json_variant to support conversion from other types to string?
auto it = pCurrentObj->find(key.toUtf8());
if (it == pCurrentObj->end())
{
return WzString::fromUtf8(defaultValue.c_str());
return defaultValue;
}
else
{
try {
return it.value().get<WzString>();
}
catch (const std::exception &e) {
return WzString::fromUtf8(defaultValue.c_str());
return defaultValue;
}
catch (...) {
debug(LOG_FATAL, "Unexpected exception encountered");
return WzString::fromUtf8(defaultValue.c_str());
return defaultValue;
}
}
}

WzString WzConfig::string(const WzString &key, const WzString &defaultValue) const
{
return string(key.toUtf8(), defaultValue.toUtf8());
}

void WzConfig::setVector3f(const WzString &name, const Vector3f &v)
{
(*pCurrentObj)[name.toUtf8()] = nlohmann::json::array({ v.x, v.y, v.z });
Expand Down Expand Up @@ -319,37 +296,6 @@ Vector2i WzConfig::vector2i(const WzString &name)
return r;
}

// temporary overloads that take QString
void WzConfig::setVector3f(const QString &name, const Vector3f &v)
{
setVector3f(WzString::fromUtf8(name.toUtf8().constData()), v);
}

Vector3f WzConfig::vector3f(const QString &name)
{
return vector3f(WzString::fromUtf8(name.toUtf8().constData()));
}

void WzConfig::setVector3i(const QString &name, const Vector3i &v)
{
setVector3i(WzString::fromUtf8(name.toUtf8().constData()), v);
}

Vector3i WzConfig::vector3i(const QString &name)
{
return vector3i(WzString::fromUtf8(name.toUtf8().constData()));
}

void WzConfig::setVector2i(const QString &name, const Vector2i &v)
{
setVector2i(WzString::fromUtf8(name.toUtf8().constData()), v);
}

Vector2i WzConfig::vector2i(const QString &name)
{
return vector2i(WzString::fromUtf8(name.toUtf8().constData()));
}

bool WzConfig::beginGroup(const WzString &prefix)
{
mObjNameStack.push_back(mName);
Expand All @@ -376,11 +322,6 @@ bool WzConfig::beginGroup(const WzString &prefix)
return true;
}

bool WzConfig::beginGroup(const QString &prefix)
{
return beginGroup(WzString::fromUtf8(prefix.toUtf8().constData()));
}

void WzConfig::endGroup()
{
ASSERT(!mObjStack.empty(), "An endGroup() too much!");
Expand Down Expand Up @@ -460,11 +401,6 @@ void WzConfig::beginArray(const WzString &name)
}
}

void WzConfig::beginArray(const QString &name)
{
return beginArray(WzString::fromUtf8(name.toUtf8().constData()));
}

void WzConfig::nextArrayItem()
{
if (mWarning == ReadAndWrite)
Expand Down Expand Up @@ -542,27 +478,11 @@ void WzConfig::setValue(const WzString &key, const nlohmann::json &value)
(*pCurrentObj)[key.toUtf8()] = value;
}

void WzConfig::setValue(const char *key, const nlohmann::json &value)
{
// Note: This makes an assumption that char * values in the files are in UTF-8
setValue(WzString::fromUtf8(key), value);
}

void WzConfig::setValue(const QString &key, const nlohmann::json &value)
{
setValue(WzString::fromUtf8(key.toUtf8().constData()), value);
}

void WzConfig::set(const WzString &key, const nlohmann::json &value)
{
setValue(key, value);
}

void WzConfig::set(const QString &key, const nlohmann::json &value)
{
setValue(key, value);
}

// MARK: json_variant

json_variant::json_variant(int i)
Expand Down
19 changes: 0 additions & 19 deletions lib/framework/wzconfig.h
Expand Up @@ -88,8 +88,6 @@ class WzConfig

public:
WzConfig(const WzString &name, WzConfig::warning warning);
// temporarily add a constructor that takes a QString
WzConfig(const QString &name, WzConfig::warning warning);
~WzConfig();

Vector3f vector3f(const WzString &name);
Expand All @@ -99,33 +97,19 @@ class WzConfig
Vector2i vector2i(const WzString &name);
void setVector2i(const WzString &name, const Vector2i &v);

// temporary overloads that take QString
Vector3f vector3f(const QString &name);
void setVector3f(const QString &name, const Vector3f &v);
Vector3i vector3i(const QString &name);
void setVector3i(const QString &name, const Vector3i &v);
Vector2i vector2i(const QString &name);
void setVector2i(const QString &name, const Vector2i &v);

std::vector<WzString> childGroups() const;
std::vector<WzString> childKeys() const;
bool contains(const WzString &key) const;
bool contains(const QString &key) const;
json_variant value(const WzString &key, const json_variant &defaultValue = json_variant()) const;
json_variant value(const QString &key, const json_variant &defaultValue = json_variant()) const;
nlohmann::json json(const WzString &key, const nlohmann::json &defaultValue = nlohmann::json()) const;
nlohmann::json json(const QString &key, const nlohmann::json &defaultValue = nlohmann::json()) const;
WzString string(const WzString &key, const WzString &defaultValue = WzString()) const;
WzString string(const std::string &key, const std::string &defaultValue = std::string()) const;

void beginArray(const WzString &name);
void beginArray(const QString &name);
void nextArrayItem();
void endArray();
int remainingArrayItems();

bool beginGroup(const WzString &name);
bool beginGroup(const QString &name);
void endGroup();

WzString fileName() const
Expand All @@ -139,10 +123,7 @@ class WzConfig
}

void setValue(const WzString &key, const nlohmann::json &value);
void setValue(const char *key, const nlohmann::json &value);
void setValue(const QString &key, const nlohmann::json &value);
void set(const WzString &key, const nlohmann::json &value);
void set(const QString &key, const nlohmann::json &value);

WzString group()
{
Expand Down

0 comments on commit 98eedf3

Please sign in to comment.