Merge pull request #205 from garakmon/encord

use ordered map for wild encounter json
This commit is contained in:
garak 2020-04-20 14:27:47 -04:00 committed by GitHub
commit 4a23c90695
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 16 deletions

View file

@ -92,7 +92,8 @@ public:
QString readMapLocation(QString map_name);
bool readWildMonData();
QMap<QString, QMap<QString, WildPokemonHeader>> wildMonData;
tsl::ordered_map<QString, tsl::ordered_map<QString, WildPokemonHeader>> wildMonData;
QVector<EncounterField> wildMonFields;
QVector<QString> encounterGroupLabels;
QVector<poryjson::Json::object> extraEncounterGroups;

View file

@ -179,17 +179,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) {
@ -559,7 +562,7 @@ void Editor::saveEncounterTabData() {
if (!stack->count()) return;
QMap<QString, WildPokemonHeader> &encounterMap = project->wildMonData[map->constantName];
tsl::ordered_map<QString, WildPokemonHeader> &encounterMap = project->wildMonData[map->constantName];
for (int groupIndex = 0; groupIndex < stack->count(); groupIndex++) {
MonTabWidget *tabWidget = static_cast<MonTabWidget *>(stack->widget(groupIndex));
@ -594,8 +597,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) {
@ -608,8 +613,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) {

View file

@ -726,13 +726,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);
@ -1752,7 +1754,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());
}
}