From 49cb69f2b8e7615e63811aa29ac5b113f580d967 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 7 Nov 2023 13:03:32 -0500 Subject: [PATCH] Fix issues when user supplies incorrect number of encounters --- CHANGELOG.md | 1 + src/project.cpp | 5 +++++ src/ui/encountertablemodel.cpp | 3 +-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d067e60d..b1b0c4ce5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Fix the selection outline sticking in single-tile mode on the Prefab tab. - Fix heal location data being cleared if certain spaces aren't used in the table. - Fix bad URL color contrast on dark themes. +- Fix some issues when too few/many pokémon are specified for a wild encounter group. ## [5.1.1] - 2023-02-20 ### Added diff --git a/src/project.cpp b/src/project.cpp index 422c09c5e..fd7d7dcc3 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1670,6 +1670,11 @@ bool Project::readWildMonData() { newMon.species = monObj["species"].string_value(); header.wildMons[field].wildPokemon.append(newMon); } + // If the user supplied too few pokémon for this group then we fill in the rest. + for (int i = header.wildMons[field].wildPokemon.length(); i < monField.encounterRates.length(); i++) { + WildPokemon newMon; // Keep default values + header.wildMons[field].wildPokemon.append(newMon); + } } } wildMonData[mapConstant].insert({encounterObj["base_label"].string_value(), header}); diff --git a/src/ui/encountertablemodel.cpp b/src/ui/encountertablemodel.cpp index b38529af2..fd870e40a 100644 --- a/src/ui/encountertablemodel.cpp +++ b/src/ui/encountertablemodel.cpp @@ -10,11 +10,10 @@ EncounterTableModel::EncounterTableModel(WildMonInfo info, EncounterFields field this->resize(this->monInfo.wildPokemon.size(), ColumnType::Count); - this->slotRatios = fields[fieldIndex].encounterRates; - for (int r = 0; r < this->numRows; r++) { this->groupNames.append(QString()); this->slotPercentages.append(0.0); + this->slotRatios.append(fields[fieldIndex].encounterRates.value(r, 0)); } if (!this->encounterFields[this->fieldIndex].groups.empty()) {