configuring encounter JSON applies changes to all mon data
This commit is contained in:
parent
911b30089c
commit
91b498ee62
5 changed files with 64 additions and 14 deletions
|
@ -4,9 +4,9 @@
|
|||
#include <QtWidgets>
|
||||
|
||||
struct WildPokemon {
|
||||
int minLevel;
|
||||
int maxLevel;
|
||||
QString species;
|
||||
int minLevel = 5;
|
||||
int maxLevel = 5;
|
||||
QString species = "SPECIES_NONE";
|
||||
};
|
||||
|
||||
struct WildMonInfo {
|
||||
|
|
|
@ -146,6 +146,7 @@ private:
|
|||
void updateMirroredConnectionDirection(MapConnection*, QString);
|
||||
void updateMirroredConnectionMap(MapConnection*, QString);
|
||||
void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false);
|
||||
void updateEncounterFields(Fields newFields);
|
||||
Event* createNewObjectEvent();
|
||||
Event* createNewWarpEvent();
|
||||
Event* createNewHealLocationEvent();
|
||||
|
|
|
@ -10,7 +10,7 @@ WildMonInfo getDefaultMonInfo(Field field) {
|
|||
newInfo.encounterRate = 0;
|
||||
|
||||
for (int row : field.second)
|
||||
newInfo.wildPokemon.append({5, 5, "SPECIES_NONE"});
|
||||
newInfo.wildPokemon.append(WildPokemon());
|
||||
|
||||
return newInfo;
|
||||
}
|
||||
|
|
|
@ -419,6 +419,14 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
|||
fieldChoices->setCurrentIndex(fieldChoices->count() - 1);
|
||||
}
|
||||
});
|
||||
QPushButton *deleteFieldButton = new QPushButton("Delete Field");
|
||||
connect(deleteFieldButton, &QPushButton::clicked, [drawSlotWidgets, fieldChoices, &tempFields]() {
|
||||
if (tempFields.size() < 2) return;// don't delete last
|
||||
int index = fieldChoices->currentIndex();
|
||||
fieldChoices->removeItem(index);
|
||||
tempFields.remove(index);
|
||||
drawSlotWidgets(index);
|
||||
});
|
||||
|
||||
QPushButton *addSlotButton = new QPushButton(QIcon(":/icons/add.ico"), "");
|
||||
addSlotButton->setFlat(true);
|
||||
|
@ -440,6 +448,7 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
|||
QHBoxLayout firstRowLayout;
|
||||
firstRowLayout.addWidget(fieldChoiceLabel);
|
||||
firstRowLayout.addWidget(fieldChoices);
|
||||
firstRowLayout.addWidget(deleteFieldButton);
|
||||
firstRowLayout.addWidget(addFieldButton);
|
||||
firstRowLayout.addWidget(removeSlotButton);
|
||||
firstRowLayout.addWidget(addSlotButton);
|
||||
|
@ -460,14 +469,10 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
|||
layout.addWidget(frameBottom);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
// Copy the temporary modified field info to project.
|
||||
Fields &newFields = project->wildMonFields;
|
||||
newFields = tempFields;
|
||||
updateEncounterFields(tempFields);
|
||||
|
||||
// Re-draw the tab accordingly.
|
||||
displayWildMonTables();
|
||||
|
||||
// TODO: Update values for every single wild encounter entry?
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -497,6 +502,50 @@ void Editor::saveEncounterTabData() {
|
|||
}
|
||||
}
|
||||
|
||||
// Update encounters for every map based on the new encounter JSON field data.
|
||||
void Editor::updateEncounterFields(Fields newFields) {
|
||||
Fields oldFields = project->wildMonFields;
|
||||
// Go through fields and determine whether we need to update a field.
|
||||
// If the field is new, do nothing.
|
||||
// If the field is deleted, remove from all maps.
|
||||
// If the field is changed, change all maps accordingly.
|
||||
for (Field oldField : oldFields) {
|
||||
QString oldFieldName = oldField.first;
|
||||
bool fieldDeleted = true;
|
||||
for (Field newField : newFields) {
|
||||
QString newFieldName = newField.first;
|
||||
if (oldFieldName == newFieldName) {
|
||||
fieldDeleted = false;
|
||||
if (oldField.second.size() != newField.second.size()) {
|
||||
for (QString map : project->wildMonData.keys()) {
|
||||
for (QString groupName : project->wildMonData.value(map).keys()) {
|
||||
WildPokemonHeader &monHeader = project->wildMonData[map][groupName];
|
||||
for (QString fieldName : monHeader.wildMons.keys()) {
|
||||
if (fieldName == oldFieldName) {
|
||||
monHeader.wildMons[fieldName].wildPokemon.resize(newField.second.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fieldDeleted) {
|
||||
for (QString map : project->wildMonData.keys()) {
|
||||
for (QString groupName : project->wildMonData.value(map).keys()) {
|
||||
WildPokemonHeader &monHeader = project->wildMonData[map][groupName];
|
||||
for (QString fieldName : monHeader.wildMons.keys()) {
|
||||
if (fieldName == oldFieldName) {
|
||||
monHeader.wildMons.remove(fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
project->wildMonFields = newFields;
|
||||
}
|
||||
|
||||
void Editor::setDiveEmergeControls() {
|
||||
ui->comboBox_DiveMap->blockSignals(true);
|
||||
ui->comboBox_EmergeMap->blockSignals(true);
|
||||
|
|
|
@ -1418,11 +1418,11 @@ void Project::readWildMonData() {
|
|||
header.wildMons[field].active = true;
|
||||
header.wildMons[field].encounterRate = encounter.toObject().value(field).toObject().value("encounter_rate").toInt();
|
||||
for (QJsonValue mon : encounter.toObject().value(field).toObject().value("mons").toArray()) {
|
||||
header.wildMons[field].wildPokemon.append({
|
||||
mon.toObject().value("min_level").toInt(),
|
||||
mon.toObject().value("max_level").toInt(),
|
||||
mon.toObject().value("species").toString()
|
||||
});
|
||||
WildPokemon newMon;
|
||||
newMon.minLevel = mon.toObject().value("min_level").toInt();
|
||||
newMon.maxLevel = mon.toObject().value("max_level").toInt();
|
||||
newMon.species = mon.toObject().value("species").toString();
|
||||
header.wildMons[field].wildPokemon.append(newMon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue