From c16a6d5d232e35cb8c7b4c4c0ff5452e96887c2e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 28 Oct 2022 12:40:36 -0400 Subject: [PATCH] Better support for parsing hex values --- src/config.cpp | 2 +- src/core/parseutil.cpp | 2 +- src/project.cpp | 14 +++++++------- src/ui/tileseteditor.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 1c5663fd..69445c88 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -136,7 +136,7 @@ void KeyValueConfigBase::save() { bool KeyValueConfigBase::getConfigBool(QString key, QString value) { bool ok; - int result = value.toInt(&ok); + int result = value.toInt(&ok, 0); if (!ok || (result != 0 && result != 1)) { logWarn(QString("Invalid config value for %1: '%2'. Must be 0 or 1.").arg(key).arg(value)); } diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index 1f933e7c..83954f8e 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -410,7 +410,7 @@ int ParseUtil::gameStringToInt(QString gameString, bool * ok) { return 1; if (QString::compare(gameString, "FALSE", Qt::CaseInsensitive) == 0) return 0; - return gameString.toInt(ok); + return gameString.toInt(ok, 0); } bool ParseUtil::gameStringToBool(QString gameString, bool * ok) { diff --git a/src/project.cpp b/src/project.cpp index dbf04f41..764340ab 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -2070,8 +2070,8 @@ bool Project::readHealLocations() { HealLocation healLocation; if (match.hasMatch()) { QString mapName = match.captured("map"); - int x = match.captured("x").toInt(); - int y = match.captured("y").toInt(); + int x = match.captured("x").toInt(nullptr, 0); + int y = match.captured("y").toInt(nullptr, 0); healLocation = HealLocation(idName, mapName, this->healLocations.size() + 1, x, y); } else { // This heal location has data, but is missing from the location table and won't be displayed by Porymap. @@ -2091,7 +2091,7 @@ bool Project::readHealLocations() { QRegularExpression respawnNPCRegex(QString("%1(?[0-9]+)").arg(initializerPattern)); match = respawnNPCRegex.match(text); if (match.hasMatch()) - healLocation.respawnNPC = match.captured("npc").toInt(); + healLocation.respawnNPC = match.captured("npc").toInt(nullptr, 0); } this->healLocations.append(healLocation); @@ -2474,11 +2474,11 @@ bool Project::readEventGraphics() { QRegularExpressionMatch dimensionMatch = re.match(dimensions_label); QRegularExpressionMatch oamTablesMatch = re.match(subsprites_label); if (oamTablesMatch.hasMatch()) { - eventGraphics->spriteWidth = oamTablesMatch.captured(1).toInt(); - eventGraphics->spriteHeight = oamTablesMatch.captured(2).toInt(); + eventGraphics->spriteWidth = oamTablesMatch.captured(1).toInt(nullptr, 0); + eventGraphics->spriteHeight = oamTablesMatch.captured(2).toInt(nullptr, 0); } else if (dimensionMatch.hasMatch()) { - eventGraphics->spriteWidth = dimensionMatch.captured(1).toInt(); - eventGraphics->spriteHeight = dimensionMatch.captured(2).toInt(); + eventGraphics->spriteWidth = dimensionMatch.captured(1).toInt(nullptr, 0); + eventGraphics->spriteHeight = dimensionMatch.captured(2).toInt(nullptr, 0); } else { eventGraphics->spriteWidth = eventGraphics->spritesheet.width(); eventGraphics->spriteHeight = eventGraphics->spritesheet.height(); diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index d45c65c7..6dcdea0e 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -512,7 +512,7 @@ void TilesetEditor::on_comboBox_metatileBehaviors_currentTextChanged(const QStri } else { // Check if user has entered a number value instead bool ok; - behavior = metatileBehavior.toInt(&ok); + behavior = metatileBehavior.toInt(&ok, 0); if (!ok) return; }