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 QString removeLineComments(QString text, const QStringList &commentSymbols);
|
||||||
|
|
||||||
static QStringList splitShellCommand(QStringView command);
|
static QStringList splitShellCommand(QStringView command);
|
||||||
static bool gameStringToBool(QString gameString);
|
static bool gameStringToBool(QString gameString, bool * ok = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString root;
|
QString root;
|
||||||
|
|
|
@ -167,6 +167,8 @@ public:
|
||||||
|
|
||||||
QString defaultSong;
|
QString defaultSong;
|
||||||
QStringList getVisibilities();
|
QStringList getVisibilities();
|
||||||
|
void insertTilesetLabel(QString label, bool isSecondary);
|
||||||
|
void insertTilesetLabel(QString label, QString isSecondaryStr);
|
||||||
bool readTilesetLabels();
|
bool readTilesetLabels();
|
||||||
bool readTilesetProperties();
|
bool readTilesetProperties();
|
||||||
bool readMaxMapDataSize();
|
bool readMaxMapDataSize();
|
||||||
|
|
|
@ -402,15 +402,13 @@ QMap<QString, QString> ParseUtil::readNamedIndexCArray(const QString &filename,
|
||||||
return map;
|
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)
|
if (QString::compare(gameString, "TRUE", Qt::CaseInsensitive) == 0)
|
||||||
return true;
|
return true;
|
||||||
if (QString::compare(gameString, "FALSE", Qt::CaseInsensitive) == 0)
|
if (QString::compare(gameString, "FALSE", Qt::CaseInsensitive) == 0)
|
||||||
return false;
|
return false;
|
||||||
bool ok;
|
return gameString.toInt(ok) != 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
@ -1342,13 +1342,10 @@ void MainWindow::on_actionNew_Tileset_triggered() {
|
||||||
|
|
||||||
if(!createTilesetDialog->isSecondary) {
|
if(!createTilesetDialog->isSecondary) {
|
||||||
this->ui->comboBox_PrimaryTileset->addItem(createTilesetDialog->fullSymbolName);
|
this->ui->comboBox_PrimaryTileset->addItem(createTilesetDialog->fullSymbolName);
|
||||||
editor->project->tilesetLabels["primary"].append(createTilesetDialog->fullSymbolName);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this->ui->comboBox_SecondaryTileset->addItem(createTilesetDialog->fullSymbolName);
|
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);
|
QMessageBox msgBox(this);
|
||||||
msgBox.setText("Successfully created tileset.");
|
msgBox.setText("Successfully created tileset.");
|
||||||
|
|
|
@ -1930,6 +1930,22 @@ Project::DataQualifiers Project::getDataQualifiers(QString text, QString label)
|
||||||
return qualifiers;
|
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() {
|
bool Project::readTilesetLabels() {
|
||||||
QStringList primaryTilesets;
|
QStringList primaryTilesets;
|
||||||
QStringList secondaryTilesets;
|
QStringList secondaryTilesets;
|
||||||
|
@ -1953,25 +1969,16 @@ bool Project::readTilesetLabels() {
|
||||||
QRegularExpressionMatchIterator iter = re.globalMatch(text);
|
QRegularExpressionMatchIterator iter = re.globalMatch(text);
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
QRegularExpressionMatch match = iter.next();
|
QRegularExpressionMatch match = iter.next();
|
||||||
QString tilesetLabel = match.captured("label");
|
insertTilesetLabel(match.captured("label"), match.captured("isSecondary"));
|
||||||
if (ParseUtil::gameStringToBool(match.captured("isSecondary")))
|
|
||||||
this->tilesetLabels["secondary"].append(tilesetLabel);
|
|
||||||
else
|
|
||||||
this->tilesetLabels["primary"].append(tilesetLabel);
|
|
||||||
this->tilesetLabelsOrdered.append(tilesetLabel);
|
|
||||||
}
|
}
|
||||||
filename = asm_filename; // For error reporting further down
|
filename = asm_filename; // For error reporting further down
|
||||||
} else {
|
} else {
|
||||||
this->usingAsmTilesets = false;
|
this->usingAsmTilesets = false;
|
||||||
const auto structs = parser.readCStructs(filename, "", Tileset::getHeaderMemberMap(this->usingAsmTilesets));
|
const auto structs = parser.readCStructs(filename, "", Tileset::getHeaderMemberMap(this->usingAsmTilesets));
|
||||||
QStringList labels = structs.keys();
|
QStringList labels = structs.keys();
|
||||||
for (const auto tilesetLabel : labels) {
|
// TODO: This is alphabetical, AdvanceMap import wants the vanilla order in tilesetLabelsOrdered
|
||||||
if (tilesetLabel.isEmpty()) continue;
|
for (const auto tilesetLabel : labels){
|
||||||
if (ParseUtil::gameStringToBool(structs[tilesetLabel].value("isSecondary")))
|
insertTilesetLabel(tilesetLabel, 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue