Move error logging out of gameStringToBool
This commit is contained in:
parent
d7894f8399
commit
c953a15523
5 changed files with 27 additions and 23 deletions
|
@ -71,7 +71,7 @@ public:
|
|||
static QString removeLineComments(QString text, const QStringList &commentSymbols);
|
||||
|
||||
static QStringList splitShellCommand(QStringView command);
|
||||
static bool gameStringToBool(QString gameString);
|
||||
static bool gameStringToBool(QString gameString, bool * ok = nullptr);
|
||||
|
||||
private:
|
||||
QString root;
|
||||
|
|
|
@ -167,6 +167,8 @@ public:
|
|||
|
||||
QString defaultSong;
|
||||
QStringList getVisibilities();
|
||||
void insertTilesetLabel(QString label, bool isSecondary);
|
||||
void insertTilesetLabel(QString label, QString isSecondaryStr);
|
||||
bool readTilesetLabels();
|
||||
bool readTilesetProperties();
|
||||
bool readMaxMapDataSize();
|
||||
|
|
|
@ -402,15 +402,13 @@ QMap<QString, QString> ParseUtil::readNamedIndexCArray(const QString &filename,
|
|||
return map;
|
||||
}
|
||||
|
||||
bool ParseUtil::gameStringToBool(QString gameString) {
|
||||
bool ParseUtil::gameStringToBool(QString gameString, bool * ok) {
|
||||
if (ok) *ok = true;
|
||||
if (QString::compare(gameString, "TRUE", Qt::CaseInsensitive) == 0)
|
||||
return true;
|
||||
if (QString::compare(gameString, "FALSE", Qt::CaseInsensitive) == 0)
|
||||
return false;
|
||||
bool ok;
|
||||
int num = gameString.toInt(&ok);
|
||||
if (!ok) logWarn(QString("Unable to convert string '%1' to bool, will be interpreted as 'FALSE'").arg(gameString));
|
||||
return num != 0;
|
||||
return gameString.toInt(ok) != 0;
|
||||
}
|
||||
|
||||
QMap<QString, QHash<QString, QString>> ParseUtil::readCStructs(const QString &filename, const QString &label, const QHash<int, QString> memberMap) {
|
||||
|
|
|
@ -1342,13 +1342,10 @@ void MainWindow::on_actionNew_Tileset_triggered() {
|
|||
|
||||
if(!createTilesetDialog->isSecondary) {
|
||||
this->ui->comboBox_PrimaryTileset->addItem(createTilesetDialog->fullSymbolName);
|
||||
editor->project->tilesetLabels["primary"].append(createTilesetDialog->fullSymbolName);
|
||||
|
||||
} else {
|
||||
this->ui->comboBox_SecondaryTileset->addItem(createTilesetDialog->fullSymbolName);
|
||||
editor->project->tilesetLabels["secondary"].append(createTilesetDialog->fullSymbolName);
|
||||
}
|
||||
editor->project->tilesetLabelsOrdered.append(createTilesetDialog->fullSymbolName);
|
||||
editor->project->insertTilesetLabel(createTilesetDialog->fullSymbolName, createTilesetDialog->isSecondary);
|
||||
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setText("Successfully created tileset.");
|
||||
|
|
|
@ -1930,6 +1930,22 @@ Project::DataQualifiers Project::getDataQualifiers(QString text, QString label)
|
|||
return qualifiers;
|
||||
}
|
||||
|
||||
void Project::insertTilesetLabel(QString label, bool isSecondary) {
|
||||
QString category = isSecondary ? "secondary" : "primary";
|
||||
this->tilesetLabels[category].append(label);
|
||||
this->tilesetLabelsOrdered.append(label);
|
||||
}
|
||||
|
||||
void Project::insertTilesetLabel(QString label, QString isSecondaryStr) {
|
||||
bool ok;
|
||||
bool isSecondary = ParseUtil::gameStringToBool(isSecondaryStr, &ok);
|
||||
if (!ok) {
|
||||
logError(QString("Unable to convert value '%1' of isSecondary to bool for tileset %2.").arg(isSecondaryStr).arg(label));
|
||||
return;
|
||||
}
|
||||
insertTilesetLabel(label, isSecondary);
|
||||
}
|
||||
|
||||
bool Project::readTilesetLabels() {
|
||||
QStringList primaryTilesets;
|
||||
QStringList secondaryTilesets;
|
||||
|
@ -1953,25 +1969,16 @@ bool Project::readTilesetLabels() {
|
|||
QRegularExpressionMatchIterator iter = re.globalMatch(text);
|
||||
while (iter.hasNext()) {
|
||||
QRegularExpressionMatch match = iter.next();
|
||||
QString tilesetLabel = match.captured("label");
|
||||
if (ParseUtil::gameStringToBool(match.captured("isSecondary")))
|
||||
this->tilesetLabels["secondary"].append(tilesetLabel);
|
||||
else
|
||||
this->tilesetLabels["primary"].append(tilesetLabel);
|
||||
this->tilesetLabelsOrdered.append(tilesetLabel);
|
||||
insertTilesetLabel(match.captured("label"), match.captured("isSecondary"));
|
||||
}
|
||||
filename = asm_filename; // For error reporting further down
|
||||
} else {
|
||||
this->usingAsmTilesets = false;
|
||||
const auto structs = parser.readCStructs(filename, "", Tileset::getHeaderMemberMap(this->usingAsmTilesets));
|
||||
QStringList labels = structs.keys();
|
||||
// TODO: This is alphabetical, AdvanceMap import wants the vanilla order in tilesetLabelsOrdered
|
||||
for (const auto tilesetLabel : labels){
|
||||
if (tilesetLabel.isEmpty()) continue;
|
||||
if (ParseUtil::gameStringToBool(structs[tilesetLabel].value("isSecondary")))
|
||||
this->tilesetLabels["secondary"].append(tilesetLabel);
|
||||
else
|
||||
this->tilesetLabels["primary"].append(tilesetLabel);
|
||||
this->tilesetLabelsOrdered.append(tilesetLabel); // TODO: This is alphabetical, AdvanceMap import wants the vanilla order
|
||||
insertTilesetLabel(tilesetLabel, structs[tilesetLabel].value("isSecondary"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue