mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-14 04:46:49 -05:00
Merge pull request #713 from GriffinRichards/custom-json-data
Preserve custom JSON data
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <QPointer>
|
||||
|
||||
#include "orderedjson.h"
|
||||
#include "parseutil.h"
|
||||
|
||||
|
||||
class Project;
|
||||
@@ -139,15 +140,14 @@ public:
|
||||
Event::Type getEventType() const { return this->eventType; }
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) = 0;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) = 0;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) = 0;
|
||||
|
||||
virtual void setDefaultValues(Project *project);
|
||||
|
||||
virtual QSet<QString> getExpectedFields() = 0;
|
||||
void readCustomAttributes(const QJsonObject &json);
|
||||
void addCustomAttributesTo(OrderedJson::object *obj) const;
|
||||
const QMap<QString, QJsonValue> getCustomAttributes() const { return this->customAttributes; }
|
||||
void setCustomAttributes(const QMap<QString, QJsonValue> newCustomAttributes) { this->customAttributes = newCustomAttributes; }
|
||||
|
||||
QJsonObject getCustomAttributes() const { return this->customAttributes; }
|
||||
void setCustomAttributes(const QJsonObject &newCustomAttributes) { this->customAttributes = newCustomAttributes; }
|
||||
|
||||
virtual void loadPixmap(Project *project);
|
||||
|
||||
@@ -191,12 +191,16 @@ protected:
|
||||
// When deleting events like this we want to warn the user that the #define may also be deleted.
|
||||
QString idName;
|
||||
|
||||
QMap<QString, QJsonValue> customAttributes;
|
||||
QJsonObject customAttributes;
|
||||
|
||||
QPixmap pixmap;
|
||||
DraggablePixmapItem *pixmapItem = nullptr;
|
||||
|
||||
QPointer<EventFrame> eventFrame;
|
||||
|
||||
static QString readString(QJsonObject *object, const QString &key) { return ParseUtil::jsonToQString(object->take(key)); }
|
||||
static int readInt(QJsonObject *object, const QString &key) { return ParseUtil::jsonToInt(object->take(key)); }
|
||||
static bool readBool(QJsonObject *object, const QString &key) { return ParseUtil::jsonToBool(object->take(key)); }
|
||||
};
|
||||
|
||||
|
||||
@@ -219,7 +223,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override;
|
||||
|
||||
@@ -286,7 +290,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override;
|
||||
|
||||
@@ -324,7 +328,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override;
|
||||
|
||||
@@ -361,7 +365,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override = 0;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override = 0;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override = 0;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override = 0;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override = 0;
|
||||
|
||||
@@ -389,7 +393,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override;
|
||||
|
||||
@@ -429,7 +433,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override;
|
||||
|
||||
@@ -460,7 +464,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override = 0;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override = 0;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override = 0;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override = 0;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override = 0;
|
||||
|
||||
@@ -487,7 +491,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override;
|
||||
|
||||
@@ -522,7 +526,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override;
|
||||
|
||||
@@ -567,7 +571,7 @@ public:
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
virtual bool loadFromJson(const QJsonObject &json, Project *project) override;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override;
|
||||
|
||||
@@ -599,12 +603,15 @@ public:
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
virtual bool loadFromJson(const QJsonObject &, Project *) override;
|
||||
virtual bool loadFromJson(QJsonObject json, Project *project) override;
|
||||
|
||||
virtual void setDefaultValues(Project *project) override;
|
||||
|
||||
virtual QSet<QString> getExpectedFields() override;
|
||||
|
||||
void setHostMapName(QString newHostMapName) { this->hostMapName = newHostMapName; }
|
||||
QString getHostMapName() const;
|
||||
|
||||
void setRespawnMapName(QString newRespawnMapName) { this->respawnMapName = newRespawnMapName; }
|
||||
QString getRespawnMapName() const { return this->respawnMapName; }
|
||||
|
||||
@@ -614,6 +621,7 @@ public:
|
||||
private:
|
||||
QString respawnMapName;
|
||||
QString respawnNPC;
|
||||
QString hostMapName; // Only needed if the host map fails to load.
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -100,8 +100,8 @@ public:
|
||||
bool hasUnsavedChanges() const;
|
||||
void pruneEditHistory();
|
||||
|
||||
void setCustomAttributes(const QMap<QString, QJsonValue> &attributes) { m_customAttributes = attributes; }
|
||||
QMap<QString, QJsonValue> customAttributes() const { return m_customAttributes; }
|
||||
void setCustomAttributes(const QJsonObject &attributes) { m_customAttributes = attributes; }
|
||||
QJsonObject customAttributes() const { return m_customAttributes; }
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
@@ -110,7 +110,7 @@ private:
|
||||
QString m_sharedScriptsMap = "";
|
||||
|
||||
QStringList m_scriptsFileLabels;
|
||||
QMap<QString, QJsonValue> m_customAttributes;
|
||||
QJsonObject m_customAttributes;
|
||||
|
||||
MapHeader *m_header = nullptr;
|
||||
Layout *m_layout = nullptr;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QJsonObject>
|
||||
|
||||
class Project;
|
||||
class Map;
|
||||
@@ -34,6 +35,9 @@ public:
|
||||
int offset() const { return m_offset; }
|
||||
void setOffset(int offset, bool mirror = true);
|
||||
|
||||
QJsonObject customData() const { return m_customData; }
|
||||
void setCustomData(const QJsonObject &customData) { m_customData = customData; }
|
||||
|
||||
MapConnection* findMirror();
|
||||
MapConnection* createMirror();
|
||||
|
||||
@@ -55,6 +59,7 @@ private:
|
||||
QString m_targetMapName;
|
||||
QString m_direction;
|
||||
int m_offset;
|
||||
QJsonObject m_customData;
|
||||
|
||||
void markMapEdited();
|
||||
Map* getMap(const QString& mapName) const;
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
Tileset *tileset_primary = nullptr;
|
||||
Tileset *tileset_secondary = nullptr;
|
||||
|
||||
QJsonObject customData;
|
||||
|
||||
Blockdata blockdata;
|
||||
|
||||
QImage image;
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
QMap<QString, int> readCDefinesByRegex(const QString &filename, const QSet<QString> ®exList, QString *error = nullptr);
|
||||
QMap<QString, int> readCDefinesByName(const QString &filename, const QSet<QString> &names, QString *error = nullptr);
|
||||
QStringList readCDefineNames(const QString &filename, const QSet<QString> ®exList, QString *error = nullptr);
|
||||
tsl::ordered_map<QString, QHash<QString, QString>> readCStructs(const QString &, const QString & = "", const QHash<int, QString>& = {});
|
||||
OrderedMap<QString, QHash<QString, QString>> readCStructs(const QString &, const QString & = "", const QHash<int, QString>& = {});
|
||||
QList<QStringList> getLabelMacros(const QList<QStringList>&, const QString&);
|
||||
QStringList getLabelValues(const QList<QStringList>&, const QString&);
|
||||
bool tryParseJsonFile(QJsonDocument *out, const QString &filepath, QString *error = nullptr);
|
||||
|
||||
@@ -56,8 +56,8 @@ public:
|
||||
bool loadLayout(poryjson::Json);
|
||||
bool loadEntries();
|
||||
|
||||
void setEntries(QMap<QString, MapSectionEntry> *entries) { this->region_map_entries = entries; }
|
||||
void setEntries(const QMap<QString, MapSectionEntry> &entries) { *(this->region_map_entries) = entries; }
|
||||
void setEntries(QHash<QString, MapSectionEntry> *entries) { this->region_map_entries = entries; }
|
||||
void setEntries(const QHash<QString, MapSectionEntry> &entries) { *(this->region_map_entries) = entries; }
|
||||
void clearEntries() { this->region_map_entries->clear(); }
|
||||
MapSectionEntry getEntry(QString section);
|
||||
void setEntry(QString section, MapSectionEntry entry);
|
||||
@@ -151,7 +151,7 @@ signals:
|
||||
void mapNeedsDisplaying();
|
||||
|
||||
private:
|
||||
QMap<QString, MapSectionEntry> *region_map_entries = nullptr;
|
||||
QHash<QString, MapSectionEntry> *region_map_entries = nullptr;
|
||||
|
||||
QString alias = "";
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ private:
|
||||
/// ClearEntries
|
||||
class ClearEntries : public QUndoCommand {
|
||||
public:
|
||||
ClearEntries(RegionMap *map, QMap<QString, MapSectionEntry>, QUndoCommand *parent = nullptr);
|
||||
ClearEntries(RegionMap *map, QHash<QString, MapSectionEntry>, QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
|
||||
private:
|
||||
RegionMap *map;
|
||||
QMap<QString, MapSectionEntry> entries;
|
||||
QHash<QString, MapSectionEntry> entries;
|
||||
};
|
||||
|
||||
#endif // REGIONMAPEDITCOMMANDS_H
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#define GUARD_WILDMONINFO_H
|
||||
|
||||
#include <QtWidgets>
|
||||
#include "orderedmap.h"
|
||||
#include "orderedjson.h"
|
||||
|
||||
class WildPokemon {
|
||||
public:
|
||||
@@ -13,22 +13,26 @@ public:
|
||||
int minLevel;
|
||||
int maxLevel;
|
||||
QString species;
|
||||
OrderedJson::object customData;
|
||||
};
|
||||
|
||||
struct WildMonInfo {
|
||||
bool active = false;
|
||||
int encounterRate = 0;
|
||||
QVector<WildPokemon> wildPokemon;
|
||||
OrderedJson::object customData;
|
||||
};
|
||||
|
||||
struct WildPokemonHeader {
|
||||
tsl::ordered_map<QString, WildMonInfo> wildMons;
|
||||
OrderedMap<QString, WildMonInfo> wildMons;
|
||||
OrderedJson::object customData;
|
||||
};
|
||||
|
||||
struct EncounterField {
|
||||
QString name; // Ex: "fishing_mons"
|
||||
QVector<int> encounterRates;
|
||||
tsl::ordered_map<QString, QVector<int>> groups; // Ex: "good_rod", {2, 3, 4}
|
||||
OrderedMap<QString, QVector<int>> groups; // Ex: "good_rod", {2, 3, 4}
|
||||
OrderedJson::object customData;
|
||||
};
|
||||
|
||||
typedef QVector<EncounterField> EncounterFields;
|
||||
|
||||
Reference in New Issue
Block a user