Remove more internal type conversions

This commit is contained in:
GriffinR 2022-10-16 02:49:42 -04:00
parent 67945cb297
commit a0eff32f36
11 changed files with 65 additions and 65 deletions

View file

@ -8,7 +8,7 @@
class MapConnection {
public:
QString direction;
QString offset;
int offset;
QString map_name;
};

View file

@ -14,10 +14,10 @@ public:
static QString layoutConstantFromName(QString mapName);
QString id;
QString name;
QString width;
QString height;
QString border_width;
QString border_height;
int width;
int height;
int border_width;
int border_height;
QString border_path;
QString blockdata_path;
QString tileset_primary_label;

View file

@ -15,7 +15,7 @@ public:
setFlag(ItemSendsGeometryChanges);
this->initialX = x;
this->initialY = y;
this->initialOffset = connection->offset.toInt();
this->initialOffset = connection->offset;
this->baseMapWidth = baseMapWidth;
this->baseMapHeight = baseMapHeight;
}

View file

@ -310,10 +310,10 @@ void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata, bool
setNewDimensionsBlockdata(newWidth, newHeight);
}
int oldWidth = layout->width.toInt();
int oldHeight = layout->height.toInt();
layout->width = QString::number(newWidth);
layout->height = QString::number(newHeight);
int oldWidth = layout->width;
int oldHeight = layout->height;
layout->width = newWidth;
layout->height = newHeight;
if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) {
Scripting::cb_MapResized(oldWidth, oldHeight, newWidth, newHeight);
@ -328,10 +328,10 @@ void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata,
setNewBorderDimensionsBlockdata(newWidth, newHeight);
}
int oldWidth = layout->border_width.toInt();
int oldHeight = layout->border_height.toInt();
layout->border_width = QString::number(newWidth);
layout->border_height = QString::number(newHeight);
int oldWidth = layout->border_width;
int oldHeight = layout->border_height;
layout->border_width = newWidth;
layout->border_height = newHeight;
if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) {
Scripting::cb_BorderResized(oldWidth, oldHeight, newWidth, newHeight);

View file

@ -16,17 +16,17 @@ QString MapLayout::layoutConstantFromName(QString mapName) {
}
int MapLayout::getWidth() {
return width.toInt(nullptr, 0);
return width;
}
int MapLayout::getHeight() {
return height.toInt(nullptr, 0);
return height;
}
int MapLayout::getBorderWidth() {
return border_width.toInt(nullptr, 0);
return border_width;
}
int MapLayout::getBorderHeight() {
return border_height.toInt(nullptr, 0);
return border_height;
}

View file

@ -70,10 +70,10 @@ MapLayout *MapParser::parse(QString filepath, bool *error, Project *project)
}
MapLayout *mapLayout = new MapLayout();
mapLayout->width = QString::number(mapWidth);
mapLayout->height = QString::number(mapHeight);
mapLayout->border_width = (borderWidth == 0) ? QString::number(2) : QString::number(borderWidth);
mapLayout->border_height = (borderHeight == 0) ? QString::number(2) : QString::number(borderHeight);
mapLayout->width = mapWidth;
mapLayout->height = mapHeight;
mapLayout->border_width = (borderWidth == 0) ? DEFAULT_BORDER_WIDTH : borderWidth;
mapLayout->border_height = (borderHeight == 0) ? DEFAULT_BORDER_HEIGHT : borderHeight;
QList<QString> tilesets = project->tilesetLabelsOrdered;

View file

@ -177,7 +177,7 @@ void Editor::setEditingConnections() {
bool controlsEnabled = selected_connection_item != nullptr;
setConnectionEditControlsEnabled(controlsEnabled);
if (selected_connection_item) {
onConnectionOffsetChanged(selected_connection_item->connection->offset.toInt());
onConnectionOffsetChanged(selected_connection_item->connection->offset);
setConnectionMap(selected_connection_item->connection->map_name);
setCurrentConnectionDirection(selected_connection_item->connection->direction);
}
@ -775,7 +775,7 @@ void Editor::setCurrentConnectionDirection(QString curDirection) {
selected_connection_item->connection->direction = curDirection;
QPixmap pixmap = connected_map->renderConnection(*selected_connection_item->connection, map->layout);
int offset = selected_connection_item->connection->offset.toInt(nullptr, 0);
int offset = selected_connection_item->connection->offset;
selected_connection_item->initialOffset = offset;
int x = 0, y = 0;
if (selected_connection_item->connection->direction == "up") {
@ -821,7 +821,7 @@ void Editor::updateCurrentConnectionDirection(QString curDirection) {
void Editor::onConnectionMoved(MapConnection* connection) {
updateMirroredConnectionOffset(connection);
onConnectionOffsetChanged(connection->offset.toInt());
onConnectionOffsetChanged(connection->offset);
maskNonVisibleConnectionTiles();
}
@ -835,7 +835,7 @@ void Editor::onConnectionOffsetChanged(int newOffset) {
void Editor::setConnectionEditControlValues(MapConnection* connection) {
QString mapName = connection ? connection->map_name : "";
QString direction = connection ? connection->direction : "";
int offset = connection ? connection->offset.toInt() : 0;
int offset = connection ? connection->offset : 0;
ui->comboBox_ConnectedMap->blockSignals(true);
ui->comboBox_ConnectionDirection->blockSignals(true);
@ -884,7 +884,7 @@ void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
setConnectionEditControlValues(selected_connection_item->connection);
ui->spinBox_ConnectionOffset->setMaximum(selected_connection_item->getMaxOffset());
ui->spinBox_ConnectionOffset->setMinimum(selected_connection_item->getMinOffset());
onConnectionOffsetChanged(selected_connection_item->connection->offset.toInt());
onConnectionOffsetChanged(selected_connection_item->connection->offset);
}
void Editor::setSelectedConnectionFromMap(QString mapName) {
@ -1561,7 +1561,7 @@ void Editor::createConnectionItem(MapConnection* connection, bool hide) {
}
QPixmap pixmap = connected_map->renderConnection(*connection, map->layout);
int offset = connection->offset.toInt(nullptr, 0);
int offset = connection->offset;
int x = 0, y = 0;
if (connection->direction == "up") {
x = offset * 16;
@ -1724,7 +1724,7 @@ void Editor::updateConnectionOffset(int offset) {
selected_connection_item->blockSignals(true);
offset = qMin(offset, selected_connection_item->getMaxOffset());
offset = qMax(offset, selected_connection_item->getMinOffset());
selected_connection_item->connection->offset = QString::number(offset);
selected_connection_item->connection->offset = offset;
if (selected_connection_item->connection->direction == "up" || selected_connection_item->connection->direction == "down") {
selected_connection_item->setX(selected_connection_item->initialX + (offset - selected_connection_item->initialOffset) * 16);
} else if (selected_connection_item->connection->direction == "left" || selected_connection_item->connection->direction == "right") {
@ -1779,7 +1779,7 @@ void Editor::addNewConnection() {
MapConnection* newConnection = new MapConnection;
newConnection->direction = minDirection;
newConnection->offset = "0";
newConnection->offset = 0;
newConnection->map_name = defaultMapName;
map->connections.append(newConnection);
createConnectionItem(newConnection, true);
@ -1847,7 +1847,7 @@ void Editor::updateMirroredConnection(MapConnection* connection, QString origina
otherMap->connections.append(mirrorConnection);
}
mirrorConnection->offset = QString::number(-connection->offset.toInt());
mirrorConnection->offset = -connection->offset;
}
void Editor::removeCurrentConnection() {
@ -1905,7 +1905,7 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
if (!connection) {
connection = new MapConnection;
connection->direction = direction;
connection->offset = "0";
connection->offset = 0;
connection->map_name = mapName;
map->connections.append(connection);
updateMirroredConnection(connection, connection->direction, connection->map_name);

View file

@ -567,29 +567,29 @@ bool Project::readMapLayouts() {
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;
}
layout->width = QString::number(lwidth);
layout->width = lwidth;
int lheight = ParseUtil::jsonToInt(layoutObj["height"]);
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));
return false;
}
layout->height = QString::number(lheight);
layout->height = lheight;
if (useCustomBorderSize) {
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
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;
}
layout->border_width = QString::number(bwidth);
layout->border_width = bwidth;
int bheight = ParseUtil::jsonToInt(layoutObj["border_height"]);
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));
bheight = DEFAULT_BORDER_HEIGHT;
}
layout->border_height = QString::number(bheight);
layout->border_height = bheight;
} else {
layout->border_width = QString::number(DEFAULT_BORDER_WIDTH);
layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT);
layout->border_width = DEFAULT_BORDER_WIDTH;
layout->border_height = DEFAULT_BORDER_HEIGHT;
}
layout->tileset_primary_label = ParseUtil::jsonToQString(layoutObj["primary_tileset"]);
if (layout->tileset_primary_label.isEmpty()) {
@ -641,11 +641,11 @@ void Project::saveMapLayouts() {
OrderedJson::object layoutObj;
layoutObj["id"] = layout->id;
layoutObj["name"] = layout->name;
layoutObj["width"] = layout->width.toInt(nullptr, 0);
layoutObj["height"] = layout->height.toInt(nullptr, 0);
layoutObj["width"] = layout->width;
layoutObj["height"] = layout->height;
if (useCustomBorderSize) {
layoutObj["border_width"] = layout->border_width.toInt(nullptr, 0);
layoutObj["border_height"] = layout->border_height.toInt(nullptr, 0);
layoutObj["border_width"] = layout->border_width;
layoutObj["border_height"] = layout->border_height;
}
layoutObj["primary_tileset"] = layout->tileset_primary_label;
layoutObj["secondary_tileset"] = layout->tileset_secondary_label;
@ -672,10 +672,10 @@ void Project::setNewMapLayout(Map* map) {
MapLayout *layout = new MapLayout();
layout->id = MapLayout::layoutConstantFromName(map->name);
layout->name = QString("%1_Layout").arg(map->name);
layout->width = QString::number(getDefaultMapSize());
layout->height = QString::number(getDefaultMapSize());
layout->border_width = QString::number(DEFAULT_BORDER_WIDTH);
layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT);
layout->width = getDefaultMapSize();
layout->height = getDefaultMapSize();
layout->border_width = DEFAULT_BORDER_WIDTH;
layout->border_height = DEFAULT_BORDER_HEIGHT;
layout->border_path = QString("%2%1/border.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders));
layout->blockdata_path = QString("%2%1/map.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders));
layout->tileset_primary_label = tilesetLabels["primary"].value(0, "gTileset_General");
@ -1311,11 +1311,11 @@ void Project::saveMap(Map *map) {
QJsonObject newLayoutObj;
newLayoutObj["id"] = map->layout->id;
newLayoutObj["name"] = map->layout->name;
newLayoutObj["width"] = map->layout->width.toInt();
newLayoutObj["height"] = map->layout->height.toInt();
newLayoutObj["width"] = map->layout->width;
newLayoutObj["height"] = map->layout->height;
if (projectConfig.getUseCustomBorderSize()) {
newLayoutObj["border_width"] = map->layout->border_width.toInt();
newLayoutObj["border_height"] = map->layout->border_height.toInt();
newLayoutObj["border_width"] = map->layout->border_width;
newLayoutObj["border_height"] = map->layout->border_height;
}
newLayoutObj["primary_tileset"] = map->layout->tileset_primary_label;
newLayoutObj["secondary_tileset"] = map->layout->tileset_secondary_label;
@ -1361,7 +1361,7 @@ void Project::saveMap(Map *map) {
if (mapNamesToMapConstants.contains(connection->map_name)) {
OrderedJson::object connectionObj;
connectionObj["direction"] = connection->direction;
connectionObj["offset"] = connection->offset.toInt();
connectionObj["offset"] = connection->offset;
connectionObj["map"] = this->mapNamesToMapConstants.value(connection->map_name);
connectionsArr.append(connectionObj);
} else {

View file

@ -56,7 +56,7 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
y = this->initialY;
}
this->connection->offset = QString::number(newOffset);
this->connection->offset = newOffset;
emit connectionMoved(this->connection);
return QPointF(x, y);
}

View file

@ -241,7 +241,7 @@ QPixmap MapImageExporter::getStitchedImage(QProgressDialog *progress, bool inclu
continue;
int x = cur.x;
int y = cur.y;
int offset = connection->offset.toInt(nullptr, 0);
int offset = connection->offset;
Map *connectionMap = this->editor->project->loadMap(connection->map_name);
if (connection->direction == "up") {
x += offset;

View file

@ -118,8 +118,8 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
ui->comboBox_Song->addItems(project->songNames);
if (existingLayout) {
ui->spinBox_NewMap_Width->setValue(project->mapLayouts.value(layoutId)->width.toInt(nullptr, 0));
ui->spinBox_NewMap_Height->setValue(project->mapLayouts.value(layoutId)->height.toInt(nullptr, 0));
ui->spinBox_NewMap_Width->setValue(project->mapLayouts.value(layoutId)->width);
ui->spinBox_NewMap_Height->setValue(project->mapLayouts.value(layoutId)->height);
ui->comboBox_NewMap_Primary_Tileset->setCurrentText(project->mapLayouts.value(layoutId)->tileset_primary_label);
ui->comboBox_NewMap_Secondary_Tileset->setCurrentText(project->mapLayouts.value(layoutId)->tileset_secondary_label);
ui->spinBox_NewMap_Width->setDisabled(true);
@ -156,8 +156,8 @@ void NewMapPopup::setDefaultValuesImportMap(MapLayout *mapLayout) {
ui->comboBox_Song->addItems(project->songNames);
ui->spinBox_NewMap_Width->setValue(mapLayout->width.toInt(nullptr, 0));
ui->spinBox_NewMap_Height->setValue(mapLayout->height.toInt(nullptr, 0));
ui->spinBox_NewMap_Width->setValue(mapLayout->width);
ui->spinBox_NewMap_Height->setValue(mapLayout->height);
ui->comboBox_NewMap_Primary_Tileset->setCurrentText(mapLayout->tileset_primary_label);
ui->comboBox_NewMap_Secondary_Tileset->setCurrentText(mapLayout->tileset_secondary_label);
@ -208,8 +208,8 @@ void NewMapPopup::setDefaultValuesProjectConfig(bool importedMap, MapLayout *map
}
if (projectConfig.getUseCustomBorderSize()) {
if (importedMap) {
ui->spinBox_NewMap_BorderWidth->setValue(mapLayout->border_width.toInt(nullptr, 0));
ui->spinBox_NewMap_BorderHeight->setValue(mapLayout->border_height.toInt(nullptr, 0));
ui->spinBox_NewMap_BorderWidth->setValue(mapLayout->border_width);
ui->spinBox_NewMap_BorderHeight->setValue(mapLayout->border_height);
}
ui->spinBox_NewMap_BorderWidth->setVisible(true);
ui->spinBox_NewMap_BorderHeight->setVisible(true);
@ -278,14 +278,14 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
layout = new MapLayout;
layout->id = MapLayout::layoutConstantFromName(newMapName);
layout->name = QString("%1_Layout").arg(newMap->name);
layout->width = QString::number(this->ui->spinBox_NewMap_Width->value());
layout->height = QString::number(this->ui->spinBox_NewMap_Height->value());
layout->width = this->ui->spinBox_NewMap_Width->value();
layout->height = this->ui->spinBox_NewMap_Height->value();
if (projectConfig.getUseCustomBorderSize()) {
layout->border_width = QString::number(this->ui->spinBox_NewMap_BorderWidth->value());
layout->border_height = QString::number(this->ui->spinBox_NewMap_BorderHeight->value());
layout->border_width = this->ui->spinBox_NewMap_BorderWidth->value();
layout->border_height = this->ui->spinBox_NewMap_BorderHeight->value();
} else {
layout->border_width = QString::number(DEFAULT_BORDER_WIDTH);
layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT);
layout->border_width = DEFAULT_BORDER_WIDTH;
layout->border_height = DEFAULT_BORDER_HEIGHT;
}
layout->tileset_primary_label = this->ui->comboBox_NewMap_Primary_Tileset->currentText();
layout->tileset_secondary_label = this->ui->comboBox_NewMap_Secondary_Tileset->currentText();