mirror of
https://github.com/huderlem/porymap.git
synced 2026-03-21 17:45:44 -05:00
Remove some unprotected usage of QList::at
This commit is contained in:
parent
a5823f04f1
commit
bc9fbe6e72
|
|
@ -75,6 +75,8 @@ public:
|
|||
bool fromScriptCall = false);
|
||||
void floodFillSmartPath(int initialX, int initialY, bool fromScriptCall = false);
|
||||
|
||||
static bool isSmartPathSize(const QSize &size) { return size.width() == smartPathWidth && size.height() == smartPathHeight; }
|
||||
|
||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||
virtual void select(QGraphicsSceneMouseEvent*);
|
||||
virtual void shift(QGraphicsSceneMouseEvent*);
|
||||
|
|
@ -88,7 +90,11 @@ public:
|
|||
|
||||
private:
|
||||
void paintSmartPath(int x, int y, bool fromScriptCall = false);
|
||||
static bool isValidSmartPathSelection(MetatileSelection selection);
|
||||
static QList<int> smartPathTable;
|
||||
static constexpr int smartPathWidth = 3;
|
||||
static constexpr int smartPathHeight = 3;
|
||||
static constexpr int smartPathMiddleIndex = (smartPathWidth / 2) + ((smartPathHeight / 2) * smartPathWidth);
|
||||
QPoint lastMetatileSelectionPos = QPoint(-1,-1);
|
||||
|
||||
unsigned actionId_ = 0;
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@
|
|||
|
||||
struct MetatileSelectionItem
|
||||
{
|
||||
bool enabled;
|
||||
uint16_t metatileId;
|
||||
bool enabled = false;
|
||||
uint16_t metatileId = 0;
|
||||
};
|
||||
|
||||
struct CollisionSelectionItem
|
||||
{
|
||||
bool enabled;
|
||||
uint16_t collision;
|
||||
uint16_t elevation;
|
||||
bool enabled = false;
|
||||
uint16_t collision = 0;
|
||||
uint16_t elevation = 0;
|
||||
};
|
||||
|
||||
struct MetatileSelection
|
||||
|
|
|
|||
|
|
@ -527,7 +527,7 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
|||
auto createNewSlot = [&fieldSlots, &tempFields, &updateTotal](int index, EncounterField ¤tField) {
|
||||
QLabel *indexLabel = new QLabel(QString("Index: %1").arg(QString::number(index)));
|
||||
QSpinBox *chanceSpinner = new QSpinBox;
|
||||
int chance = currentField.encounterRates.at(index);
|
||||
int chance = currentField.encounterRates.value(index);
|
||||
chanceSpinner->setMinimum(1);
|
||||
chanceSpinner->setMaximum(9999);
|
||||
chanceSpinner->setValue(chance);
|
||||
|
|
|
|||
|
|
@ -1299,7 +1299,7 @@ void Project::setNewLayoutBorder(Layout *layout) {
|
|||
} else {
|
||||
// Fill the border with the default metatiles from the config.
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
layout->border.append(projectConfig.newMapBorderMetatileIds.at(i));
|
||||
layout->border.append(projectConfig.newMapBorderMetatileIds.value(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ Scripting::Scripting(MainWindow *mainWindow) {
|
|||
const QStringList paths = userConfig.getCustomScriptPaths();
|
||||
const QList<bool> enabled = userConfig.getCustomScriptsEnabled();
|
||||
for (int i = 0; i < paths.length(); i++) {
|
||||
if (enabled.at(i))
|
||||
if (enabled.value(i, true))
|
||||
this->filepaths.append(paths.at(i));
|
||||
}
|
||||
this->loadModules(this->filepaths);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
|
||||
for (int i = 0; i < selection.dimensions.width() && (i + pos.x()) < width; i++) {
|
||||
for (int j = 0; j < selection.dimensions.height() && (j + pos.y()) < height; j++) {
|
||||
MetatileSelectionItem item = selection.metatileItems.at(j * selection.dimensions.width() + i);
|
||||
MetatileSelectionItem item = selection.metatileItems.value(j * selection.dimensions.width() + i);
|
||||
layout->setBorderMetatileId(pos.x() + i, pos.y() + j, item.metatileId, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ QPixmap drawMetatileSelection(MetatileSelection selection, Layout *layout) {
|
|||
int y = j * Metatile::pixelHeight();
|
||||
QPoint metatile_origin = QPoint(x, y);
|
||||
int index = j * selection.dimensions.width() + i;
|
||||
MetatileSelectionItem item = selection.metatileItems.at(index);
|
||||
MetatileSelectionItem item = selection.metatileItems.value(index);
|
||||
if (item.enabled) {
|
||||
QImage metatile_image = getMetatileImage(item.metatileId, layout);
|
||||
painter.drawImage(metatile_origin, metatile_image);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "cursortilerect.h"
|
||||
#include "layoutpixmapitem.h"
|
||||
#include "log.h"
|
||||
|
||||
CursorTileRect::CursorTileRect(const QSize &tileSize, const QRgb &color, QGraphicsItem *parent)
|
||||
|
|
@ -46,7 +47,7 @@ void CursorTileRect::updateSelectionSize(const QSize &size) {
|
|||
}
|
||||
|
||||
bool CursorTileRect::smartPathInEffect() const {
|
||||
return !m_rightClickSelectionAnchored && m_smartPathMode && m_selectionSize == QSize(3,3);
|
||||
return !m_rightClickSelectionAnchored && m_smartPathMode && LayoutPixmapItem::isSmartPathSize(m_selectionSize);
|
||||
}
|
||||
|
||||
void CursorTileRect::updateLocation(int coordX, int coordY) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ CustomScriptsEditor::CustomScriptsEditor(QWidget *parent) :
|
|||
const QStringList paths = userConfig.getCustomScriptPaths();
|
||||
const QList<bool> enabled = userConfig.getCustomScriptsEnabled();
|
||||
for (int i = 0; i < paths.length(); i++)
|
||||
this->displayScript(paths.at(i), enabled.at(i));
|
||||
this->displayScript(paths.at(i), enabled.value(i, true));
|
||||
|
||||
connect(ui->button_Help, &QAbstractButton::clicked, this, &CustomScriptsEditor::openManual);
|
||||
connect(ui->button_CreateNewScript, &QAbstractButton::clicked, this, &CustomScriptsEditor::createNewScript);
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@ void LayoutPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
|||
bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
|
||||
QSize selectionDimensions = this->metatileSelector->getSelectionDimensions();
|
||||
if (settings->smartPathsEnabled) {
|
||||
if (!shiftPressed && selectionDimensions == QSize(3,3)) {
|
||||
if (!shiftPressed && isSmartPathSize(selectionDimensions)) {
|
||||
paintSmartPath(pos.x(), pos.y());
|
||||
} else {
|
||||
paintNormal(pos.x(), pos.y());
|
||||
}
|
||||
} else {
|
||||
if (shiftPressed && selectionDimensions == QSize(3,3)) {
|
||||
if (shiftPressed && isSmartPathSize(selectionDimensions)) {
|
||||
paintSmartPath(pos.x(), pos.y());
|
||||
} else {
|
||||
paintNormal(pos.x(), pos.y());
|
||||
|
|
@ -91,7 +91,7 @@ void LayoutPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) {
|
|||
destY %= this->layout->getHeight();
|
||||
|
||||
int blockIndex = j * this->layout->getWidth() + i;
|
||||
Block srcBlock = oldMetatiles.at(blockIndex);
|
||||
Block srcBlock = oldMetatiles.value(blockIndex);
|
||||
this->layout->setBlock(destX, destY, srcBlock);
|
||||
}
|
||||
|
||||
|
|
@ -126,12 +126,12 @@ void LayoutPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
|
|||
Block block;
|
||||
if (this->layout->getBlock(actualX, actualY, &block)) {
|
||||
int index = j * selection.dimensions.width() + i;
|
||||
MetatileSelectionItem item = selection.metatileItems.at(index);
|
||||
MetatileSelectionItem item = selection.metatileItems.value(index);
|
||||
if (!item.enabled)
|
||||
continue;
|
||||
block.setMetatileId(item.metatileId);
|
||||
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
|
||||
CollisionSelectionItem collisionItem = selection.collisionItems.at(index);
|
||||
CollisionSelectionItem collisionItem = selection.collisionItems.value(index);
|
||||
block.setCollision(collisionItem.collision);
|
||||
block.setElevation(collisionItem.elevation);
|
||||
}
|
||||
|
|
@ -177,8 +177,11 @@ bool isSmartPathTile(QList<MetatileSelectionItem> metatileItems, uint16_t metati
|
|||
return false;
|
||||
}
|
||||
|
||||
bool isValidSmartPathSelection(MetatileSelection selection) {
|
||||
if (selection.dimensions != QSize(3,3))
|
||||
bool LayoutPixmapItem::isValidSmartPathSelection(MetatileSelection selection) {
|
||||
if (!isSmartPathSize(selection.dimensions))
|
||||
return false;
|
||||
|
||||
if (selection.metatileItems.length() != (LayoutPixmapItem::smartPathWidth * LayoutPixmapItem::smartPathHeight))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < selection.metatileItems.length(); i++) {
|
||||
|
|
@ -195,13 +198,13 @@ void LayoutPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
|||
return;
|
||||
|
||||
// Shift to the middle tile of the smart path selection.
|
||||
uint16_t openMetatileId = selection.metatileItems.at(4).metatileId;
|
||||
uint16_t openMetatileId = selection.metatileItems.at(smartPathMiddleIndex).metatileId;
|
||||
uint16_t openCollision = 0;
|
||||
uint16_t openElevation = 0;
|
||||
bool setCollisions = false;
|
||||
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
|
||||
openCollision = selection.collisionItems.at(4).collision;
|
||||
openElevation = selection.collisionItems.at(4).elevation;
|
||||
openCollision = selection.collisionItems.at(smartPathMiddleIndex).collision;
|
||||
openElevation = selection.collisionItems.at(smartPathMiddleIndex).elevation;
|
||||
setCollisions = true;
|
||||
}
|
||||
|
||||
|
|
@ -356,7 +359,7 @@ void LayoutPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event)
|
|||
metatiles.append(block.metatileId());
|
||||
}
|
||||
int blockIndex = y * this->layout->getWidth() + x;
|
||||
block = this->layout->blockdata.at(blockIndex);
|
||||
block = this->layout->blockdata.value(blockIndex);
|
||||
auto collision = block.collision();
|
||||
auto elevation = block.elevation();
|
||||
collisions.append(QPair<uint16_t, uint16_t>(collision, elevation));
|
||||
|
|
@ -377,7 +380,7 @@ void LayoutPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
|||
int metatileId = selection.metatileItems.first().metatileId;
|
||||
if (selection.metatileItems.count() > 1 || (this->layout->getBlock(pos.x(), pos.y(), &block) && block.metatileId() != metatileId)) {
|
||||
bool smartPathsEnabled = event->modifiers() & Qt::ShiftModifier;
|
||||
if ((this->settings->smartPathsEnabled || smartPathsEnabled) && selection.dimensions == QSize(3,3))
|
||||
if ((this->settings->smartPathsEnabled || smartPathsEnabled) && isSmartPathSize(selection.dimensions))
|
||||
this->floodFillSmartPath(pos.x(), pos.y());
|
||||
else
|
||||
this->floodFill(pos.x(), pos.y());
|
||||
|
|
@ -435,7 +438,7 @@ void LayoutPixmapItem::magicFill(
|
|||
if (i < 0) i = selectionDimensions.width() + i;
|
||||
if (j < 0) j = selectionDimensions.height() + j;
|
||||
int index = j * selectionDimensions.width() + i;
|
||||
if (selectedMetatiles.at(index).enabled) {
|
||||
if (index < selectedMetatiles.length() && selectedMetatiles.at(index).enabled) {
|
||||
block.setMetatileId(selectedMetatiles.at(index).metatileId);
|
||||
if (setCollisions) {
|
||||
CollisionSelectionItem item = selectedCollisions.at(index);
|
||||
|
|
@ -495,12 +498,12 @@ void LayoutPixmapItem::floodFill(
|
|||
if (i < 0) i = selectionDimensions.width() + i;
|
||||
if (j < 0) j = selectionDimensions.height() + j;
|
||||
int index = j * selectionDimensions.width() + i;
|
||||
uint16_t metatileId = selectedMetatiles.at(index).metatileId;
|
||||
uint16_t metatileId = selectedMetatiles.value(index).metatileId;
|
||||
uint16_t old_metatileId = block.metatileId();
|
||||
if (selectedMetatiles.at(index).enabled && (selectedMetatiles.count() != 1 || old_metatileId != metatileId)) {
|
||||
if (selectedMetatiles.value(index).enabled && (selectedMetatiles.count() != 1 || old_metatileId != metatileId)) {
|
||||
block.setMetatileId(metatileId);
|
||||
if (setCollisions) {
|
||||
CollisionSelectionItem item = selectedCollisions.at(index);
|
||||
CollisionSelectionItem item = selectedCollisions.value(index);
|
||||
block.setCollision(item.collision);
|
||||
block.setElevation(item.elevation);
|
||||
}
|
||||
|
|
@ -535,12 +538,12 @@ void LayoutPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromS
|
|||
return;
|
||||
|
||||
// Shift to the middle tile of the smart path selection.
|
||||
uint16_t openMetatileId = selection.metatileItems.at(4).metatileId;
|
||||
uint16_t openMetatileId = selection.metatileItems.at(smartPathMiddleIndex).metatileId;
|
||||
uint16_t openCollision = 0;
|
||||
uint16_t openElevation = 0;
|
||||
bool setCollisions = false;
|
||||
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
|
||||
CollisionSelectionItem item = selection.collisionItems.at(4);
|
||||
CollisionSelectionItem item = selection.collisionItems.at(smartPathMiddleIndex);
|
||||
openCollision = item.collision;
|
||||
openElevation = item.elevation;
|
||||
setCollisions = true;
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ void Prefab::savePrefabs() {
|
|||
for (int y = 0; y < item.selection.dimensions.height(); y++) {
|
||||
for (int x = 0; x < item.selection.dimensions.width(); x++) {
|
||||
int index = y * item.selection.dimensions.width() + x;
|
||||
auto metatileItem = item.selection.metatileItems.at(index);
|
||||
auto metatileItem = item.selection.metatileItems.value(index);
|
||||
if (metatileItem.enabled) {
|
||||
OrderedJson::object metatileObj;
|
||||
metatileObj["x"] = x;
|
||||
|
|
|
|||
|
|
@ -459,7 +459,7 @@ void TilesetEditor::drawSelectedTiles() {
|
|||
int tileIndex = 0;
|
||||
for (int y = 0; y < dimensions.height(); y++) {
|
||||
for (int x = 0; x < dimensions.width(); x++) {
|
||||
auto tile = tiles.at(tileIndex++);
|
||||
auto tile = tiles.value(tileIndex++);
|
||||
QImage tileImage = getPalettedTileImage(tile.tileId, this->primaryTileset, this->secondaryTileset, tile.palette, true).scaled(imgTileWidth, imgTileHeight);
|
||||
tile.flip(&tileImage);
|
||||
painter.drawImage(x * imgTileWidth, y * imgTileHeight, tileImage);
|
||||
|
|
@ -543,7 +543,7 @@ void TilesetEditor::paintSelectedLayerTiles(const QPoint &pos, bool paletteOnly)
|
|||
int destTileIndex = this->metatileLayersItem->posToTileIndex(pos.x() + x, pos.y() + y);
|
||||
if (destTileIndex < maxTileIndex) {
|
||||
Tile &destTile = this->metatile->tiles[destTileIndex];
|
||||
const Tile srcTile = tiles.at(srcTileIndex++);
|
||||
const Tile srcTile = tiles.value(srcTileIndex++);
|
||||
if (paletteOnly) {
|
||||
if (srcTile.palette == destTile.palette)
|
||||
continue; // Ignore no-ops for edit history
|
||||
|
|
|
|||
|
|
@ -146,7 +146,6 @@ QList<Tile> TilesetEditorTileSelector::buildSelectedTiles(int width, int height,
|
|||
QList<QList<Tile>> tileMatrix;
|
||||
for (int j = 0; j < height; j++) {
|
||||
QList<Tile> row;
|
||||
QList<Tile> layerRow;
|
||||
for (int i = 0; i < width; i++) {
|
||||
int index = i + j * width;
|
||||
Tile tile = selected.value(index);
|
||||
|
|
@ -155,17 +154,9 @@ QList<Tile> TilesetEditorTileSelector::buildSelectedTiles(int width, int height,
|
|||
if (this->paletteChanged)
|
||||
tile.palette = this->paletteId;
|
||||
if (this->xFlip)
|
||||
layerRow.prepend(tile);
|
||||
row.prepend(tile);
|
||||
else
|
||||
layerRow.append(tile);
|
||||
|
||||
// If we've completed a layer row, or its the last tile of an incompletely
|
||||
// selected layer, then append the layer row to the full row
|
||||
// If not an external selection, treat the whole row as 1 "layer"
|
||||
if (i == width - 1) {
|
||||
row.append(layerRow);
|
||||
layerRow.clear();
|
||||
}
|
||||
row.append(tile);
|
||||
}
|
||||
if (this->yFlip)
|
||||
tileMatrix.prepend(row);
|
||||
|
|
|
|||
|
|
@ -392,10 +392,10 @@ void WildMonChart::updateTheme() {
|
|||
saveSpeciesColors(static_cast<QAbstractBarSeries*>(chart->series().at(0))->barSets());
|
||||
|
||||
chart = ui->chartView_LevelDistribution->chart();
|
||||
if (chart) {
|
||||
chart->setTheme(theme);
|
||||
applySpeciesColors(static_cast<QAbstractBarSeries*>(chart->series().at(0))->barSets());
|
||||
}
|
||||
if (!chart || chart->series().isEmpty())
|
||||
return;
|
||||
chart->setTheme(theme);
|
||||
applySpeciesColors(static_cast<QAbstractBarSeries*>(chart->series().at(0))->barSets());
|
||||
}
|
||||
|
||||
void WildMonChart::saveSpeciesColors(const QList<QBarSet*> &barSets) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user