From e5122ef94ffc35453955d2bd584637df49597934 Mon Sep 17 00:00:00 2001 From: garakmon Date: Mon, 20 Apr 2020 10:18:03 -0400 Subject: [PATCH] use ordered map for wild encounter json --- include/project.h | 3 ++- src/editor.cpp | 29 ++++++++++++++++++----------- src/project.cpp | 10 ++++++---- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/include/project.h b/include/project.h index e3e3b21c..bd4a69e0 100644 --- a/include/project.h +++ b/include/project.h @@ -91,7 +91,8 @@ public: QString readMapLocation(QString map_name); bool readWildMonData(); - QMap> wildMonData; + tsl::ordered_map> wildMonData; + QVector wildMonFields; QVector encounterGroupLabels; QVector extraEncounterGroups; diff --git a/src/editor.cpp b/src/editor.cpp index b52f81b7..96f47db8 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -175,17 +175,20 @@ void Editor::displayWildMonTables() { return; } - labelCombo->addItems(project->wildMonData[map->constantName].keys()); - labelCombo->setCurrentText(project->wildMonData[map->constantName].firstKey()); + for (auto groupPair : project->wildMonData[map->constantName]) + labelCombo->addItem(groupPair.first); - for (int labelIndex = 0; labelIndex < project->wildMonData[map->constantName].keys().size(); labelIndex++) { + labelCombo->setCurrentText(labelCombo->itemText(0)); - QString label = project->wildMonData.value(map->constantName).keys().at(labelIndex); + int labelIndex = 0; + for (auto labelPair : project->wildMonData[map->constantName]) { - WildPokemonHeader header = project->wildMonData.value(map->constantName).value(label); + QString label = labelPair.first; + + WildPokemonHeader header = project->wildMonData[map->constantName][label]; MonTabWidget *tabWidget = new MonTabWidget(this); - stack->insertWidget(labelIndex, tabWidget); + stack->insertWidget(labelIndex++, tabWidget); int tabIndex = 0; for (EncounterField monField : project->wildMonFields) { @@ -555,7 +558,7 @@ void Editor::saveEncounterTabData() { if (!stack->count()) return; - QMap &encounterMap = project->wildMonData[map->constantName]; + tsl::ordered_map &encounterMap = project->wildMonData[map->constantName]; for (int groupIndex = 0; groupIndex < stack->count(); groupIndex++) { MonTabWidget *tabWidget = static_cast(stack->widget(groupIndex)); @@ -590,8 +593,10 @@ void Editor::updateEncounterFields(EncounterFields newFields) { if (oldFieldName == newFieldName) { fieldDeleted = false; if (oldField.encounterRates.size() != newField.encounterRates.size()) { - for (QString map : project->wildMonData.keys()) { - for (QString groupName : project->wildMonData.value(map).keys()) { + for (auto mapPair : project->wildMonData) { + QString map = mapPair.first; + for (auto groupNamePair : project->wildMonData[map]) { + QString groupName = groupNamePair.first; WildPokemonHeader &monHeader = project->wildMonData[map][groupName]; for (QString fieldName : monHeader.wildMons.keys()) { if (fieldName == oldFieldName) { @@ -604,8 +609,10 @@ void Editor::updateEncounterFields(EncounterFields newFields) { } } if (fieldDeleted) { - for (QString map : project->wildMonData.keys()) { - for (QString groupName : project->wildMonData.value(map).keys()) { + for (auto mapPair : project->wildMonData) { + QString map = mapPair.first; + for (auto groupNamePair : project->wildMonData[map]) { + QString groupName = groupNamePair.first; WildPokemonHeader &monHeader = project->wildMonData[map][groupName]; for (QString fieldName : monHeader.wildMons.keys()) { if (fieldName == oldFieldName) { diff --git a/src/project.cpp b/src/project.cpp index 4033faf0..6781b84c 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -640,13 +640,15 @@ void Project::saveWildMonData() { monHeadersObject["fields"] = fieldsInfoArray; OrderedJson::array encountersArray; - for (QString key : wildMonData.keys()) { - for (QString groupLabel : wildMonData.value(key).keys()) { + for (auto keyPair : wildMonData) { + QString key = keyPair.first; + for (auto grouplLabelPair : wildMonData[key]) { + QString groupLabel = grouplLabelPair.first; OrderedJson::object encounterObject; encounterObject["map"] = key; encounterObject["base_label"] = groupLabel; - WildPokemonHeader encounterHeader = wildMonData.value(key).value(groupLabel); + WildPokemonHeader encounterHeader = wildMonData[key][groupLabel]; for (QString fieldName : encounterHeader.wildMons.keys()) { OrderedJson::object fieldObject; WildMonInfo monInfo = encounterHeader.wildMons.value(fieldName); @@ -1556,7 +1558,7 @@ bool Project::readWildMonData() { } } } - wildMonData[mapConstant].insert(encounter.toObject().value("base_label").toString(), header); + wildMonData[mapConstant].insert({encounter.toObject().value("base_label").toString(), header}); encounterGroupLabels.append(encounter.toObject().value("base_label").toString()); } }