Merge pull request #512 from GriffinRichards/layout-warn
Improve layout parser warnings/errors
This commit is contained in:
commit
9727af5793
1 changed files with 29 additions and 13 deletions
|
@ -410,11 +410,12 @@ bool Project::readMapLayouts() {
|
||||||
mapLayouts.clear();
|
mapLayouts.clear();
|
||||||
mapLayoutsTable.clear();
|
mapLayoutsTable.clear();
|
||||||
|
|
||||||
QString layoutsFilepath = QString("%1/%2").arg(root).arg(projectConfig.getFilePath(ProjectFilePath::json_layouts));
|
QString layoutsFilepath = projectConfig.getFilePath(ProjectFilePath::json_layouts);
|
||||||
fileWatcher.addPath(layoutsFilepath);
|
QString fullFilepath = QString("%1/%2").arg(root).arg(layoutsFilepath);
|
||||||
|
fileWatcher.addPath(fullFilepath);
|
||||||
QJsonDocument layoutsDoc;
|
QJsonDocument layoutsDoc;
|
||||||
if (!parser.tryParseJsonFile(&layoutsDoc, layoutsFilepath)) {
|
if (!parser.tryParseJsonFile(&layoutsDoc, fullFilepath)) {
|
||||||
logError(QString("Failed to read map layouts from %1").arg(layoutsFilepath));
|
logError(QString("Failed to read map layouts from %1").arg(fullFilepath));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,35 +461,46 @@ bool Project::readMapLayouts() {
|
||||||
layout->id = ParseUtil::jsonToQString(layoutObj["id"]);
|
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));
|
||||||
|
delete layout;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (mapLayouts.contains(layout->id)) {
|
||||||
|
logWarn(QString("Duplicate layout entry for %1 in %2 will be ignored.").arg(layout->id).arg(layoutsFilepath));
|
||||||
|
delete layout;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
layout->name = ParseUtil::jsonToQString(layoutObj["name"]);
|
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 for %1 in %2").arg(layout->id).arg(layoutsFilepath));
|
||||||
|
delete layout;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int lwidth = ParseUtil::jsonToInt(layoutObj["width"]);
|
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 'width' value '%1' for %2 in %3. Must be greater than 0.").arg(lwidth).arg(layout->id).arg(layoutsFilepath));
|
||||||
|
delete layout;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->width = lwidth;
|
layout->width = lwidth;
|
||||||
int lheight = ParseUtil::jsonToInt(layoutObj["height"]);
|
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 'height' value '%1' for %2 in %3. Must be greater than 0.").arg(lheight).arg(layout->id).arg(layoutsFilepath));
|
||||||
|
delete layout;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->height = lheight;
|
layout->height = lheight;
|
||||||
if (useCustomBorderSize) {
|
if (useCustomBorderSize) {
|
||||||
int bwidth = ParseUtil::jsonToInt(layoutObj["border_width"]);
|
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 'border_width' value '%1' for %2 in %3. Must be greater than 0. Using default (%4) instead.")
|
||||||
|
.arg(bwidth).arg(layout->id).arg(layoutsFilepath).arg(DEFAULT_BORDER_WIDTH));
|
||||||
bwidth = DEFAULT_BORDER_WIDTH;
|
bwidth = DEFAULT_BORDER_WIDTH;
|
||||||
}
|
}
|
||||||
layout->border_width = bwidth;
|
layout->border_width = bwidth;
|
||||||
int bheight = ParseUtil::jsonToInt(layoutObj["border_height"]);
|
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 'border_height' value '%1' for %2 in %3. Must be greater than 0. Using default (%4) instead.")
|
||||||
|
.arg(bheight).arg(layout->id).arg(layoutsFilepath).arg(DEFAULT_BORDER_HEIGHT));
|
||||||
bheight = DEFAULT_BORDER_HEIGHT;
|
bheight = DEFAULT_BORDER_HEIGHT;
|
||||||
}
|
}
|
||||||
layout->border_height = bheight;
|
layout->border_height = bheight;
|
||||||
|
@ -498,22 +510,26 @@ bool Project::readMapLayouts() {
|
||||||
}
|
}
|
||||||
layout->tileset_primary_label = ParseUtil::jsonToQString(layoutObj["primary_tileset"]);
|
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 for %1 in %2").arg(layout->id).arg(layoutsFilepath));
|
||||||
|
delete layout;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->tileset_secondary_label = ParseUtil::jsonToQString(layoutObj["secondary_tileset"]);
|
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 for %1 in %2").arg(layout->id).arg(layoutsFilepath));
|
||||||
|
delete layout;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->border_path = ParseUtil::jsonToQString(layoutObj["border_filepath"]);
|
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 for %1 in %2").arg(layout->id).arg(layoutsFilepath));
|
||||||
|
delete layout;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layout->blockdata_path = ParseUtil::jsonToQString(layoutObj["blockdata_filepath"]);
|
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 for %1 in %2").arg(layout->id).arg(layoutsFilepath));
|
||||||
|
delete layout;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mapLayouts.insert(layout->id, layout);
|
mapLayouts.insert(layout->id, layout);
|
||||||
|
|
Loading…
Reference in a new issue