mirror of
https://github.com/huderlem/porymap.git
synced 2026-04-22 01:27:33 -05:00
Fix empty initialization, fix Qt5 build, delete old config files
This commit is contained in:
parent
d33f5f3621
commit
189fbb83b5
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace BaseGame {
|
||||
enum Version {
|
||||
none, // TODO: Go through and make sure this is a valid state
|
||||
none,
|
||||
pokeruby,
|
||||
pokefirered,
|
||||
pokeemerald,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@
|
|||
#ifndef CONVERTER_H
|
||||
#define CONVERTER_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QJsonValue>
|
||||
#include <QUrl>
|
||||
#include <QVariant>
|
||||
#include <QVersionNumber>
|
||||
|
||||
#include "magic_enum.hpp"
|
||||
|
|
@ -49,7 +52,8 @@
|
|||
Appropriately implementing 'toString'/'fromString' has the added benefit that your type
|
||||
can automatically be used as a JSON key if it for example appears as the key in a QMap.
|
||||
|
||||
// TODO: Document clamp
|
||||
If a type doesn't support the '<'/'>' operators, 'clamp' can be reimplemented as well to allow
|
||||
the type to be used in range validation.
|
||||
|
||||
*/
|
||||
|
||||
|
|
@ -59,7 +63,7 @@ struct DefaultConverter {
|
|||
// Defaults to straightforward QJsonValue construction.
|
||||
// This handles most of the primitive types.
|
||||
static QJsonValue toJson(const T& value) {
|
||||
return QJsonValue{value};
|
||||
return QJsonValue(value);
|
||||
}
|
||||
static T fromJson(const QJsonValue& json, QStringList* errors = nullptr) {
|
||||
const QVariant v = json.toVariant();
|
||||
|
|
@ -218,7 +222,7 @@ struct Converter<std::optional<T>> : DefaultConverter<std::optional<T>> {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct Converter<QList<T>> : DefaultConverter<QList<T>> {
|
||||
struct ListConverter : DefaultConverter<QList<T>> {
|
||||
static QJsonValue toJson(const QList<T>& list) {
|
||||
QJsonArray arr;
|
||||
for (auto& elem : list) arr.append(Converter<T>::toJson(elem));
|
||||
|
|
@ -227,11 +231,18 @@ struct Converter<QList<T>> : DefaultConverter<QList<T>> {
|
|||
static QList<T> fromJson(const QJsonValue& json, QStringList* errors = nullptr) {
|
||||
const auto arr = Converter<QJsonArray>::fromJson(json, errors);
|
||||
QList<T> list;
|
||||
for (auto& elem : arr) list.append(Converter<T>::fromJson(elem, errors));
|
||||
for (const auto& elem : arr) list.append(Converter<T>::fromJson(elem, errors));
|
||||
return list;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Converter<QList<T>> : ListConverter<T> {};
|
||||
|
||||
// Only needed for Qt5
|
||||
template <>
|
||||
struct Converter<QStringList> : ListConverter<QString> {};
|
||||
|
||||
template <typename K, typename V>
|
||||
struct Converter<QMap<K,V>> : DefaultConverter<QMap<K,V>> {
|
||||
static QJsonObject toJson(const QMap<K,V>& map) {
|
||||
|
|
@ -285,7 +296,7 @@ struct Converter<OrderedSet<T>> : DefaultConverter<OrderedSet<T>> {
|
|||
static OrderedSet<T> fromJson(const QJsonValue& json, QStringList* errors = nullptr) {
|
||||
const auto arr = Converter<QJsonArray>::fromJson(json, errors);
|
||||
OrderedSet<T> set;
|
||||
for (auto& elem : arr) set.insert(Converter<T>::fromJson(elem, errors));
|
||||
for (const auto& elem : arr) set.insert(Converter<T>::fromJson(elem, errors));
|
||||
return set;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
#include "converter.h"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// A FieldInterface provides a simple interface for converting a field to/from JSON.
|
||||
// It's constructed with a pointer to some data, and has two functions:
|
||||
// - 'get' returns the pointed-to data, converted to JSON
|
||||
|
|
@ -27,7 +24,6 @@
|
|||
// FieldInterface* fi = makeFieldInterface(&someField, options);
|
||||
// fi->set(QJsonValue("5")); // someField is now "hello" (defaults to first element), error messages returned
|
||||
|
||||
|
||||
// Base class lets us use the interface without any type information.
|
||||
class FieldInterface {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include "log.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
|
||||
void KeyValueConfigBase::setRoot(const QString& root) {
|
||||
m_root = root;
|
||||
|
|
|
|||
|
|
@ -47,8 +47,9 @@ bool KeyValueConfigBase::loadLegacy() {
|
|||
logInfo(QString("Loaded legacy config file '%1'").arg(oldFilename));
|
||||
|
||||
// Save before deleting the old config file to ensure no data is lost.
|
||||
if (save()/* && !file.remove()*/) { // TODO: Once non-legacy loading is complete, we can uncomment this.
|
||||
//logWarn(QString("Failed to delete old config file '%1'.").arg(oldFilename));
|
||||
if (save()) {
|
||||
if (!file.remove()) logWarn(QString("Failed to delete legacy config file '%1'.").arg(oldFilename));
|
||||
else logInfo(QString("Deleted legacy config file '%1'.").arg(oldFilename));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -287,6 +287,7 @@ void ProjectConfig::initializeFromEmpty() {
|
|||
logWarn(QString("No base_game_version selected, using default '%1'").arg(BaseGame::versionToString(this->baseGameVersion)));
|
||||
}
|
||||
}
|
||||
setVersionSpecificDefaults(this->baseGameVersion);
|
||||
}
|
||||
|
||||
void ProjectConfig::setFilePath(ProjectFilePath pathId, const QString& path) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#include "shortcutsconfig.h"
|
||||
#include "shortcut.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QRegularExpression>
|
||||
|
||||
ShortcutsConfig shortcutsConfig;
|
||||
|
||||
void ShortcutsConfig::loadFromJson(const QJsonObject& obj) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user