Convert JSON values by type, except events
This commit is contained in:
parent
239f3935bf
commit
6ffcb58e5e
7 changed files with 134 additions and 82 deletions
|
@ -71,7 +71,11 @@ public:
|
||||||
static QString removeLineComments(QString text, const QStringList &commentSymbols);
|
static QString removeLineComments(QString text, const QStringList &commentSymbols);
|
||||||
|
|
||||||
static QStringList splitShellCommand(QStringView command);
|
static QStringList splitShellCommand(QStringView command);
|
||||||
|
static int gameStringToInt(QString gameString, bool * ok = nullptr);
|
||||||
static bool gameStringToBool(QString gameString, bool * ok = nullptr);
|
static bool gameStringToBool(QString gameString, bool * ok = nullptr);
|
||||||
|
static QString jsonToQString(QJsonValue value, bool * ok = nullptr);
|
||||||
|
static int jsonToInt(QJsonValue value, bool * ok = nullptr);
|
||||||
|
static bool jsonToBool(QJsonValue value, bool * ok = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString root;
|
QString root;
|
||||||
|
|
|
@ -134,7 +134,7 @@ public:
|
||||||
bool readSpeciesIconPaths();
|
bool readSpeciesIconPaths();
|
||||||
QMap<QString, QString> speciesToIconPath;
|
QMap<QString, QString> speciesToIconPath;
|
||||||
|
|
||||||
QMap<QString, bool> getTopLevelMapFields();
|
QSet<QString> getTopLevelMapFields();
|
||||||
bool loadMapData(Map*);
|
bool loadMapData(Map*);
|
||||||
bool readMapLayouts();
|
bool readMapLayouts();
|
||||||
bool loadLayout(MapLayout *);
|
bool loadLayout(MapLayout *);
|
||||||
|
|
|
@ -402,13 +402,17 @@ QMap<QString, QString> ParseUtil::readNamedIndexCArray(const QString &filename,
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParseUtil::gameStringToBool(QString gameString, bool * ok) {
|
int ParseUtil::gameStringToInt(QString gameString, bool * ok) {
|
||||||
if (ok) *ok = true;
|
if (ok) *ok = true;
|
||||||
if (QString::compare(gameString, "TRUE", Qt::CaseInsensitive) == 0)
|
if (QString::compare(gameString, "TRUE", Qt::CaseInsensitive) == 0)
|
||||||
return true;
|
return 1;
|
||||||
if (QString::compare(gameString, "FALSE", Qt::CaseInsensitive) == 0)
|
if (QString::compare(gameString, "FALSE", Qt::CaseInsensitive) == 0)
|
||||||
return false;
|
return 0;
|
||||||
return gameString.toInt(ok) != 0;
|
return gameString.toInt(ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParseUtil::gameStringToBool(QString gameString, bool * ok) {
|
||||||
|
return gameStringToInt(gameString, ok) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QHash<QString, QString>> ParseUtil::readCStructs(const QString &filename, const QString &label, const QHash<int, QString> memberMap) {
|
QMap<QString, QHash<QString, QString>> ParseUtil::readCStructs(const QString &filename, const QString &label, const QHash<int, QString> memberMap) {
|
||||||
|
@ -520,6 +524,48 @@ bool ParseUtil::ensureFieldsExist(const QJsonObject &obj, const QList<QString> &
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QJsonValues are strictly typed, and so will not attempt any implicit conversions.
|
||||||
|
// The below functions are for attempting to convert a JSON value read from the user's
|
||||||
|
// project to a QString, int, or bool (whichever Porymap expects).
|
||||||
|
QString ParseUtil::jsonToQString(QJsonValue value, bool * ok) {
|
||||||
|
if (ok) *ok = true;
|
||||||
|
switch (value.type())
|
||||||
|
{
|
||||||
|
case QJsonValue::String: return value.toString();
|
||||||
|
case QJsonValue::Double: return QString::number(value.toInt());
|
||||||
|
case QJsonValue::Bool: return QString::number(value.toBool());
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
if (ok) *ok = false;
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ParseUtil::jsonToInt(QJsonValue value, bool * ok) {
|
||||||
|
if (ok) *ok = true;
|
||||||
|
switch (value.type())
|
||||||
|
{
|
||||||
|
case QJsonValue::String: return ParseUtil::gameStringToInt(value.toString(), ok);
|
||||||
|
case QJsonValue::Double: return value.toInt();
|
||||||
|
case QJsonValue::Bool: return value.toBool();
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
if (ok) *ok = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParseUtil::jsonToBool(QJsonValue value, bool * ok) {
|
||||||
|
if (ok) *ok = true;
|
||||||
|
switch (value.type())
|
||||||
|
{
|
||||||
|
case QJsonValue::String: return ParseUtil::gameStringToBool(value.toString(), ok);
|
||||||
|
case QJsonValue::Double: return value.toInt() != 0;
|
||||||
|
case QJsonValue::Bool: return value.toBool();
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
if (ok) *ok = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int ParseUtil::getScriptLineNumber(const QString &filePath, const QString &scriptLabel) {
|
int ParseUtil::getScriptLineNumber(const QString &filePath, const QString &scriptLabel) {
|
||||||
if (scriptLabel.isEmpty())
|
if (scriptLabel.isEmpty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1574,8 +1574,8 @@ void MainWindow::paste() {
|
||||||
}
|
}
|
||||||
QJsonArray metatilesArray = pasteObject["metatile_selection"].toArray();
|
QJsonArray metatilesArray = pasteObject["metatile_selection"].toArray();
|
||||||
QJsonArray collisionsArray = pasteObject["collision_selection"].toArray();
|
QJsonArray collisionsArray = pasteObject["collision_selection"].toArray();
|
||||||
int width = pasteObject["width"].toInt();
|
int width = ParseUtil::jsonToInt(pasteObject["width"]);
|
||||||
int height = pasteObject["height"].toInt();
|
int height = ParseUtil::jsonToInt(pasteObject["height"]);
|
||||||
QList<uint16_t> metatiles;
|
QList<uint16_t> metatiles;
|
||||||
QList<QPair<uint16_t, uint16_t>> collisions;
|
QList<QPair<uint16_t, uint16_t>> collisions;
|
||||||
for (auto tile : metatilesArray) {
|
for (auto tile : metatilesArray) {
|
||||||
|
|
118
src/project.cpp
118
src/project.cpp
|
@ -142,36 +142,37 @@ void Project::setNewMapConnections(Map *map) {
|
||||||
map->connections.clear();
|
map->connections.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static QMap<QString, bool> defaultTopLevelMapFields {
|
const QSet<QString> defaultTopLevelMapFields = {
|
||||||
{"id", true},
|
"id",
|
||||||
{"name", true},
|
"name",
|
||||||
{"layout", true},
|
"layout",
|
||||||
{"music", true},
|
"music",
|
||||||
{"region_map_section", true},
|
"region_map_section",
|
||||||
{"requires_flash", true},
|
"requires_flash",
|
||||||
{"weather", true},
|
"weather",
|
||||||
{"map_type", true},
|
"map_type",
|
||||||
{"show_map_name", true},
|
"show_map_name",
|
||||||
{"battle_scene", true},
|
"battle_scene",
|
||||||
{"connections", true},
|
"connections",
|
||||||
{"object_events", true},
|
"object_events",
|
||||||
{"warp_events", true},
|
"warp_events",
|
||||||
{"coord_events", true},
|
"coord_events",
|
||||||
{"bg_events", true},
|
"bg_events",
|
||||||
{"shared_events_map", true},
|
"shared_events_map",
|
||||||
{"shared_scripts_map", true},
|
"shared_scripts_map",
|
||||||
|
"test",
|
||||||
};
|
};
|
||||||
|
|
||||||
QMap<QString, bool> Project::getTopLevelMapFields() {
|
QSet<QString> Project::getTopLevelMapFields() {
|
||||||
QMap<QString, bool> topLevelMapFields = defaultTopLevelMapFields;
|
QSet<QString> topLevelMapFields = defaultTopLevelMapFields;
|
||||||
if (projectConfig.getBaseGameVersion() != BaseGameVersion::pokeruby) {
|
if (projectConfig.getBaseGameVersion() != BaseGameVersion::pokeruby) {
|
||||||
topLevelMapFields.insert("allow_cycling", true);
|
topLevelMapFields.insert("allow_cycling");
|
||||||
topLevelMapFields.insert("allow_escaping", true);
|
topLevelMapFields.insert("allow_escaping");
|
||||||
topLevelMapFields.insert("allow_running", true);
|
topLevelMapFields.insert("allow_running");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectConfig.getFloorNumberEnabled()) {
|
if (projectConfig.getFloorNumberEnabled()) {
|
||||||
topLevelMapFields.insert("floor_number", true);
|
topLevelMapFields.insert("floor_number");
|
||||||
}
|
}
|
||||||
return topLevelMapFields;
|
return topLevelMapFields;
|
||||||
}
|
}
|
||||||
|
@ -190,24 +191,25 @@ bool Project::loadMapData(Map* map) {
|
||||||
|
|
||||||
QJsonObject mapObj = mapDoc.object();
|
QJsonObject mapObj = mapDoc.object();
|
||||||
|
|
||||||
map->song = mapObj["music"].toString();
|
map->song = ParseUtil::jsonToQString(mapObj["music"]);
|
||||||
map->layoutId = mapObj["layout"].toString();
|
map->layoutId = ParseUtil::jsonToQString(mapObj["layout"]);
|
||||||
map->location = mapObj["region_map_section"].toString();
|
map->location = ParseUtil::jsonToQString(mapObj["region_map_section"]);
|
||||||
map->requiresFlash = mapObj["requires_flash"].toBool();
|
map->requiresFlash = ParseUtil::jsonToBool(mapObj["requires_flash"]);
|
||||||
map->weather = mapObj["weather"].toString();
|
map->weather = ParseUtil::jsonToQString(mapObj["weather"]);
|
||||||
map->type = mapObj["map_type"].toString();
|
map->type = ParseUtil::jsonToQString(mapObj["map_type"]);
|
||||||
map->show_location = mapObj["show_map_name"].toBool();
|
map->show_location = ParseUtil::jsonToBool(mapObj["show_map_name"]);
|
||||||
map->battle_scene = mapObj["battle_scene"].toString();
|
map->battle_scene = ParseUtil::jsonToQString(mapObj["battle_scene"]);
|
||||||
|
|
||||||
if (projectConfig.getBaseGameVersion() != BaseGameVersion::pokeruby) {
|
if (projectConfig.getBaseGameVersion() != BaseGameVersion::pokeruby) {
|
||||||
map->allowBiking = mapObj["allow_cycling"].toBool();
|
map->allowBiking = ParseUtil::jsonToBool(mapObj["allow_cycling"]);
|
||||||
map->allowEscaping = mapObj["allow_escaping"].toBool();
|
map->allowEscaping = ParseUtil::jsonToBool(mapObj["allow_escaping"]);
|
||||||
map->allowRunning = mapObj["allow_running"].toBool();
|
map->allowRunning = ParseUtil::jsonToBool(mapObj["allow_running"]);
|
||||||
}
|
}
|
||||||
if (projectConfig.getFloorNumberEnabled()) {
|
if (projectConfig.getFloorNumberEnabled()) {
|
||||||
map->floorNumber = mapObj["floor_number"].toInt();
|
map->floorNumber = ParseUtil::jsonToInt(mapObj["floor_number"]);
|
||||||
}
|
}
|
||||||
map->sharedEventsMap = mapObj["shared_events_map"].toString();
|
map->sharedEventsMap = ParseUtil::jsonToQString(mapObj["shared_events_map"]);
|
||||||
map->sharedScriptsMap = mapObj["shared_scripts_map"].toString();
|
map->sharedScriptsMap = ParseUtil::jsonToQString(mapObj["shared_scripts_map"]);
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
map->events[EventGroup::Object].clear();
|
map->events[EventGroup::Object].clear();
|
||||||
|
@ -394,9 +396,9 @@ bool Project::loadMapData(Map* map) {
|
||||||
for (int i = 0; i < connectionsArr.size(); i++) {
|
for (int i = 0; i < connectionsArr.size(); i++) {
|
||||||
QJsonObject connectionObj = connectionsArr[i].toObject();
|
QJsonObject connectionObj = connectionsArr[i].toObject();
|
||||||
MapConnection *connection = new MapConnection;
|
MapConnection *connection = new MapConnection;
|
||||||
connection->direction = connectionObj["direction"].toString();
|
connection->direction = ParseUtil::jsonToQString(connectionObj["direction"]);
|
||||||
connection->offset = QString::number(connectionObj["offset"].toInt());
|
connection->offset = ParseUtil::jsonToInt(connectionObj["offset"]);
|
||||||
QString mapConstant = connectionObj["map"].toString();
|
QString mapConstant = ParseUtil::jsonToQString(connectionObj["map"]);
|
||||||
if (mapConstantsToMapNames.contains(mapConstant)) {
|
if (mapConstantsToMapNames.contains(mapConstant)) {
|
||||||
connection->map_name = mapConstantsToMapNames.value(mapConstant);
|
connection->map_name = mapConstantsToMapNames.value(mapConstant);
|
||||||
map->connections.append(connection);
|
map->connections.append(connection);
|
||||||
|
@ -407,10 +409,10 @@ bool Project::loadMapData(Map* map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for custom fields
|
// Check for custom fields
|
||||||
QMap<QString, bool> baseFields = this->getTopLevelMapFields();
|
QSet<QString> baseFields = this->getTopLevelMapFields();
|
||||||
for (QString key : mapObj.keys()) {
|
for (QString key : mapObj.keys()) {
|
||||||
if (!baseFields.contains(key)) {
|
if (!baseFields.contains(key)) {
|
||||||
map->customHeaders.insert(key, mapObj[key].toString());
|
map->customHeaders.insert(key, ParseUtil::jsonToQString(mapObj[key]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +432,7 @@ QString Project::readMapLayoutId(QString map_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject mapObj = mapDoc.object();
|
QJsonObject mapObj = mapDoc.object();
|
||||||
return mapObj["layout"].toString();
|
return ParseUtil::jsonToQString(mapObj["layout"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::readMapLocation(QString map_name) {
|
QString Project::readMapLocation(QString map_name) {
|
||||||
|
@ -446,7 +448,7 @@ QString Project::readMapLocation(QString map_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject mapObj = mapDoc.object();
|
QJsonObject mapObj = mapDoc.object();
|
||||||
return mapObj["region_map_section"].toString();
|
return ParseUtil::jsonToQString(mapObj["region_map_section"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::setNewMapHeader(Map* map, int mapIndex) {
|
void Project::setNewMapHeader(Map* map, int mapIndex) {
|
||||||
|
@ -518,7 +520,7 @@ bool Project::readMapLayouts() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutsLabel = layoutsObj["layouts_table_label"].toString();
|
layoutsLabel = ParseUtil::jsonToQString(layoutsObj["layouts_table_label"]);
|
||||||
if (layoutsLabel.isNull()) {
|
if (layoutsLabel.isNull()) {
|
||||||
layoutsLabel = "gMapLayouts";
|
layoutsLabel = "gMapLayouts";
|
||||||
logWarn(QString("'layouts_table_label' value is missing from %1. Defaulting to %2")
|
logWarn(QString("'layouts_table_label' value is missing from %1. Defaulting to %2")
|
||||||
|
@ -550,36 +552,36 @@ bool Project::readMapLayouts() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MapLayout *layout = new MapLayout();
|
MapLayout *layout = new MapLayout();
|
||||||
layout->id = layoutObj["id"].toString();
|
layout->id = ParseUtil::jsonToQString(layoutObj["id"]);
|
||||||
if (layout->id.isEmpty()) {
|
if (layout->id.isEmpty()) {
|
||||||
logError(QString("Missing 'id' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
logError(QString("Missing 'id' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->name = layoutObj["name"].toString();
|
layout->name = ParseUtil::jsonToQString(layoutObj["name"]);
|
||||||
if (layout->name.isEmpty()) {
|
if (layout->name.isEmpty()) {
|
||||||
logError(QString("Missing 'name' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
logError(QString("Missing 'name' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int lwidth = layoutObj["width"].toInt();
|
int lwidth = ParseUtil::jsonToInt(layoutObj["width"]);
|
||||||
if (lwidth <= 0) {
|
if (lwidth <= 0) {
|
||||||
logError(QString("Invalid layout 'width' value '%1' on layout %2 in %3. Must be greater than 0.").arg(lwidth).arg(i).arg(layoutsFilepath));
|
logError(QString("Invalid layout 'width' value '%1' on layout %2 in %3. Must be greater than 0.").arg(lwidth).arg(i).arg(layoutsFilepath));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->width = QString::number(lwidth);
|
layout->width = QString::number(lwidth);
|
||||||
int lheight = layoutObj["height"].toInt();
|
int lheight = ParseUtil::jsonToInt(layoutObj["height"]);
|
||||||
if (lheight <= 0) {
|
if (lheight <= 0) {
|
||||||
logError(QString("Invalid layout 'height' value '%1' on layout %2 in %3. Must be greater than 0.").arg(lheight).arg(i).arg(layoutsFilepath));
|
logError(QString("Invalid layout 'height' value '%1' on layout %2 in %3. Must be greater than 0.").arg(lheight).arg(i).arg(layoutsFilepath));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->height = QString::number(lheight);
|
layout->height = QString::number(lheight);
|
||||||
if (useCustomBorderSize) {
|
if (useCustomBorderSize) {
|
||||||
int bwidth = layoutObj["border_width"].toInt();
|
int bwidth = ParseUtil::jsonToInt(layoutObj["border_width"]);
|
||||||
if (bwidth <= 0) { // 0 is an expected border width/height that should be handled, GF used it for the RS layouts in FRLG
|
if (bwidth <= 0) { // 0 is an expected border width/height that should be handled, GF used it for the RS layouts in FRLG
|
||||||
logWarn(QString("Invalid layout 'border_width' value '%1' on layout %2 in %3. Must be greater than 0. Using default (%4) instead.").arg(bwidth).arg(i).arg(layoutsFilepath).arg(DEFAULT_BORDER_WIDTH));
|
logWarn(QString("Invalid layout 'border_width' value '%1' on layout %2 in %3. Must be greater than 0. Using default (%4) instead.").arg(bwidth).arg(i).arg(layoutsFilepath).arg(DEFAULT_BORDER_WIDTH));
|
||||||
bwidth = DEFAULT_BORDER_WIDTH;
|
bwidth = DEFAULT_BORDER_WIDTH;
|
||||||
}
|
}
|
||||||
layout->border_width = QString::number(bwidth);
|
layout->border_width = QString::number(bwidth);
|
||||||
int bheight = layoutObj["border_height"].toInt();
|
int bheight = ParseUtil::jsonToInt(layoutObj["border_height"]);
|
||||||
if (bheight <= 0) {
|
if (bheight <= 0) {
|
||||||
logWarn(QString("Invalid layout 'border_height' value '%1' on layout %2 in %3. Must be greater than 0. Using default (%4) instead.").arg(bheight).arg(i).arg(layoutsFilepath).arg(DEFAULT_BORDER_HEIGHT));
|
logWarn(QString("Invalid layout 'border_height' value '%1' on layout %2 in %3. Must be greater than 0. Using default (%4) instead.").arg(bheight).arg(i).arg(layoutsFilepath).arg(DEFAULT_BORDER_HEIGHT));
|
||||||
bheight = DEFAULT_BORDER_HEIGHT;
|
bheight = DEFAULT_BORDER_HEIGHT;
|
||||||
|
@ -589,22 +591,22 @@ bool Project::readMapLayouts() {
|
||||||
layout->border_width = QString::number(DEFAULT_BORDER_WIDTH);
|
layout->border_width = QString::number(DEFAULT_BORDER_WIDTH);
|
||||||
layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT);
|
layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT);
|
||||||
}
|
}
|
||||||
layout->tileset_primary_label = layoutObj["primary_tileset"].toString();
|
layout->tileset_primary_label = ParseUtil::jsonToQString(layoutObj["primary_tileset"]);
|
||||||
if (layout->tileset_primary_label.isEmpty()) {
|
if (layout->tileset_primary_label.isEmpty()) {
|
||||||
logError(QString("Missing 'primary_tileset' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
logError(QString("Missing 'primary_tileset' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->tileset_secondary_label = layoutObj["secondary_tileset"].toString();
|
layout->tileset_secondary_label = ParseUtil::jsonToQString(layoutObj["secondary_tileset"]);
|
||||||
if (layout->tileset_secondary_label.isEmpty()) {
|
if (layout->tileset_secondary_label.isEmpty()) {
|
||||||
logError(QString("Missing 'secondary_tileset' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
logError(QString("Missing 'secondary_tileset' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->border_path = layoutObj["border_filepath"].toString();
|
layout->border_path = ParseUtil::jsonToQString(layoutObj["border_filepath"]);
|
||||||
if (layout->border_path.isEmpty()) {
|
if (layout->border_path.isEmpty()) {
|
||||||
logError(QString("Missing 'border_filepath' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
logError(QString("Missing 'border_filepath' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->blockdata_path = layoutObj["blockdata_filepath"].toString();
|
layout->blockdata_path = ParseUtil::jsonToQString(layoutObj["blockdata_filepath"]);
|
||||||
if (layout->blockdata_path.isEmpty()) {
|
if (layout->blockdata_path.isEmpty()) {
|
||||||
logError(QString("Missing 'blockdata_filepath' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
logError(QString("Missing 'blockdata_filepath' value on layout %1 in %2").arg(i).arg(layoutsFilepath));
|
||||||
return false;
|
return false;
|
||||||
|
@ -1840,12 +1842,12 @@ bool Project::readMapGroups() {
|
||||||
QStringList maps;
|
QStringList maps;
|
||||||
QStringList groups;
|
QStringList groups;
|
||||||
for (int groupIndex = 0; groupIndex < mapGroupOrder.size(); groupIndex++) {
|
for (int groupIndex = 0; groupIndex < mapGroupOrder.size(); groupIndex++) {
|
||||||
QString groupName = mapGroupOrder.at(groupIndex).toString();
|
QString groupName = ParseUtil::jsonToQString(mapGroupOrder.at(groupIndex));
|
||||||
QJsonArray mapNames = mapGroupsObj.value(groupName).toArray();
|
QJsonArray mapNames = mapGroupsObj.value(groupName).toArray();
|
||||||
groupedMaps.append(QStringList());
|
groupedMaps.append(QStringList());
|
||||||
groups.append(groupName);
|
groups.append(groupName);
|
||||||
for (int j = 0; j < mapNames.size(); j++) {
|
for (int j = 0; j < mapNames.size(); j++) {
|
||||||
QString mapName = mapNames.at(j).toString();
|
QString mapName = ParseUtil::jsonToQString(mapNames.at(j));
|
||||||
mapGroups.insert(mapName, groupIndex);
|
mapGroups.insert(mapName, groupIndex);
|
||||||
groupedMaps[groupIndex].append(mapName);
|
groupedMaps[groupIndex].append(mapName);
|
||||||
maps.append(mapName);
|
maps.append(mapName);
|
||||||
|
|
|
@ -46,14 +46,14 @@ void Prefab::loadPrefabs() {
|
||||||
if (prefabObj.isEmpty())
|
if (prefabObj.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int width = prefabObj["width"].toInt();
|
int width = ParseUtil::jsonToInt(prefabObj["width"]);
|
||||||
int height = prefabObj["height"].toInt();
|
int height = ParseUtil::jsonToInt(prefabObj["height"]);
|
||||||
if (width <= 0 || height <= 0)
|
if (width <= 0 || height <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QString name = prefabObj["name"].toString();
|
QString name = ParseUtil::jsonToQString(prefabObj["name"]);
|
||||||
QString primaryTileset = prefabObj["primary_tileset"].toString();
|
QString primaryTileset = ParseUtil::jsonToQString(prefabObj["primary_tileset"]);
|
||||||
QString secondaryTileset = prefabObj["secondary_tileset"].toString();
|
QString secondaryTileset = ParseUtil::jsonToQString(prefabObj["secondary_tileset"]);
|
||||||
|
|
||||||
MetatileSelection selection;
|
MetatileSelection selection;
|
||||||
selection.dimensions = QPoint(width, height);
|
selection.dimensions = QPoint(width, height);
|
||||||
|
@ -65,17 +65,17 @@ void Prefab::loadPrefabs() {
|
||||||
QJsonArray metatiles = prefabObj["metatiles"].toArray();
|
QJsonArray metatiles = prefabObj["metatiles"].toArray();
|
||||||
for (int j = 0; j < metatiles.size(); j++) {
|
for (int j = 0; j < metatiles.size(); j++) {
|
||||||
QJsonObject metatileObj = metatiles[j].toObject();
|
QJsonObject metatileObj = metatiles[j].toObject();
|
||||||
int x = metatileObj["x"].toInt();
|
int x = ParseUtil::jsonToInt(metatileObj["x"]);
|
||||||
int y = metatileObj["y"].toInt();
|
int y = ParseUtil::jsonToInt(metatileObj["y"]);
|
||||||
if (x < 0 || x >= width || y < 0 || y >= height)
|
if (x < 0 || x >= width || y < 0 || y >= height)
|
||||||
continue;
|
continue;
|
||||||
int index = y * width + x;
|
int index = y * width + x;
|
||||||
int metatileId = metatileObj["metatile_id"].toInt();
|
int metatileId = ParseUtil::jsonToInt(metatileObj["metatile_id"]);
|
||||||
if (metatileId < 0 || metatileId >= Project::getNumMetatilesTotal())
|
if (metatileId < 0 || metatileId >= Project::getNumMetatilesTotal())
|
||||||
continue;
|
continue;
|
||||||
selection.metatileItems[index].metatileId = metatileObj["metatile_id"].toInt();
|
selection.metatileItems[index].metatileId = ParseUtil::jsonToInt(metatileObj["metatile_id"]);
|
||||||
selection.collisionItems[index].collision = metatileObj["collision"].toInt();
|
selection.collisionItems[index].collision = ParseUtil::jsonToInt(metatileObj["collision"]);
|
||||||
selection.collisionItems[index].elevation = metatileObj["elevation"].toInt();
|
selection.collisionItems[index].elevation = ParseUtil::jsonToInt(metatileObj["elevation"]);
|
||||||
selection.metatileItems[index].enabled = true;
|
selection.metatileItems[index].enabled = true;
|
||||||
selection.collisionItems[index].enabled = true;
|
selection.collisionItems[index].enabled = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,13 +125,13 @@ bool RegionMapEditor::loadRegionMapEntries() {
|
||||||
|
|
||||||
for (auto entryRef : object["map_sections"].toArray()) {
|
for (auto entryRef : object["map_sections"].toArray()) {
|
||||||
QJsonObject entryObject = entryRef.toObject();
|
QJsonObject entryObject = entryRef.toObject();
|
||||||
QString entryMapSection = entryObject["map_section"].toString();
|
QString entryMapSection = ParseUtil::jsonToQString(entryObject["map_section"]);
|
||||||
MapSectionEntry entry;
|
MapSectionEntry entry;
|
||||||
entry.name = entryObject["name"].toString();
|
entry.name = ParseUtil::jsonToQString(entryObject["name"]);
|
||||||
entry.x = entryObject["x"].toInt();
|
entry.x = ParseUtil::jsonToInt(entryObject["x"]);
|
||||||
entry.y = entryObject["y"].toInt();
|
entry.y = ParseUtil::jsonToInt(entryObject["y"]);
|
||||||
entry.width = entryObject["width"].toInt();
|
entry.width = ParseUtil::jsonToInt(entryObject["width"]);
|
||||||
entry.height = entryObject["height"].toInt();
|
entry.height = ParseUtil::jsonToInt(entryObject["height"]);
|
||||||
entry.valid = true;
|
entry.valid = true;
|
||||||
this->region_map_entries[entryMapSection] = entry;
|
this->region_map_entries[entryMapSection] = entry;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue