From 7b0a812db76a868ec48d1698166fdbd081f17c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 4 Feb 2019 00:18:42 +0100 Subject: [PATCH] WIP break stuff --- .../minecraft/gameoptions/GameOptions.cpp | 35 ++++++++--------- api/logic/minecraft/gameoptions/GameOptions.h | 39 ++++++++++++++++++- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/api/logic/minecraft/gameoptions/GameOptions.cpp b/api/logic/minecraft/gameoptions/GameOptions.cpp index e547b32a..e99f3035 100644 --- a/api/logic/minecraft/gameoptions/GameOptions.cpp +++ b/api/logic/minecraft/gameoptions/GameOptions.cpp @@ -4,7 +4,7 @@ #include namespace { -bool load(const QString& path, std::vector &contents, int & version) +bool load(const QString& path, RawGameOptions & contents) { contents.clear(); QFile file(path); @@ -13,7 +13,6 @@ bool load(const QString& path, std::vector &contents, int & vers qWarning() << "Failed to read options file."; return false; } - version = 0; while(!file.atEnd()) { auto line = file.readLine(); @@ -31,32 +30,32 @@ bool load(const QString& path, std::vector &contents, int & vers qDebug() << "!!" << key << "!!"; if(key == "version") { - version = value.toInt(); + contents.version = value.toInt(); continue; } - contents.emplace_back(GameOptionItem{key, value}); + contents.mapping[key] = value; } - qDebug() << "Loaded" << path << "with version:" << version; + qDebug() << "Loaded" << path << "with version:" << contents.version; return true; } -bool save(const QString& path, std::vector &mapping, int version) +bool save(const QString& path, RawGameOptions& contents) { QSaveFile out(path); if(!out.open(QIODevice::WriteOnly)) { return false; } - if(version != 0) + if(contents.version != 0) { - QString versionLine = QString("version:%1\n").arg(version); + QString versionLine = QString("version:%1\n").arg(contents.version); out.write(versionLine.toUtf8()); } - auto iter = mapping.begin(); - while (iter != mapping.end()) + auto iter = contents.mapping.begin(); + while (iter != contents.mapping.end()) { - out.write(iter->key.toUtf8()); + out.write(iter->first.toUtf8()); out.write(":"); - out.write(iter->value.toUtf8()); + out.write(iter->second.toUtf8()); out.write("\n"); iter++; } @@ -95,7 +94,7 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const int row = index.row(); int column = index.column(); - if (row < 0 || row >= int(contents.size())) + if (row < 0 || row >= rowCount()) return QVariant(); switch (role) @@ -103,11 +102,11 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const case Qt::DisplayRole: if(column == 0) { - return contents[row].key; + return cookedOptions.items[row].id; } else { - return contents[row].value; + return cookedOptions.items[row].default_value; } default: return QVariant(); @@ -117,7 +116,7 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const int GameOptions::rowCount(const QModelIndex&) const { - return contents.size(); + return cookedOptions.items.size(); } int GameOptions::columnCount(const QModelIndex&) const @@ -133,12 +132,12 @@ bool GameOptions::isLoaded() const bool GameOptions::reload() { beginResetModel(); - loaded = load(path, contents, version); + loaded = load(path, rawOptions); endResetModel(); return loaded; } bool GameOptions::save() { - return ::save(path, contents, version); + return ::save(path, rawOptions); } diff --git a/api/logic/minecraft/gameoptions/GameOptions.h b/api/logic/minecraft/gameoptions/GameOptions.h index c6d25492..76ecf8d6 100644 --- a/api/logic/minecraft/gameoptions/GameOptions.h +++ b/api/logic/minecraft/gameoptions/GameOptions.h @@ -4,12 +4,46 @@ #include #include +struct RawGameOptions +{ + void clear() + { + version = 0; + mapping.clear(); + } + std::map mapping; + int version = 0; +}; + struct GameOptionItem { + QString id; + enum ValueType + { + INT, + FLOAT, + BOOL, + FOV_MADNESS, + FPS_MADNESS + } value_type; + enum VisualType + { + + } visual_type; + QVariant null_value; + QVariant default_value; + QVariant min_value; + QVariant max_value; QString key; - QString value; }; +struct CookedGameOptions +{ + std::vector items; +}; + + + class GameOptions : public QAbstractListModel { Q_OBJECT @@ -27,7 +61,8 @@ public: bool save(); private: - std::vector contents; + RawGameOptions rawOptions; + CookedGameOptions cookedOptions; bool loaded = false; QString path; int version = 0;