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>
|
#include <QtWidgets>
|
||||||
|
|
||||||
struct WildPokemon {
|
struct WildPokemon {
|
||||||
int minLevel;
|
int minLevel = 5;
|
||||||
int maxLevel;
|
int maxLevel = 5;
|
||||||
QString species;
|
QString species = "SPECIES_NONE";
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WildMonInfo {
|
struct WildMonInfo {
|
||||||
|
|
|
@ -146,6 +146,7 @@ private:
|
||||||
void updateMirroredConnectionDirection(MapConnection*, QString);
|
void updateMirroredConnectionDirection(MapConnection*, QString);
|
||||||
void updateMirroredConnectionMap(MapConnection*, QString);
|
void updateMirroredConnectionMap(MapConnection*, QString);
|
||||||
void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false);
|
void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false);
|
||||||
|
void updateEncounterFields(Fields newFields);
|
||||||
Event* createNewObjectEvent();
|
Event* createNewObjectEvent();
|
||||||
Event* createNewWarpEvent();
|
Event* createNewWarpEvent();
|
||||||
Event* createNewHealLocationEvent();
|
Event* createNewHealLocationEvent();
|
||||||
|
|
|
@ -10,7 +10,7 @@ WildMonInfo getDefaultMonInfo(Field field) {
|
||||||
newInfo.encounterRate = 0;
|
newInfo.encounterRate = 0;
|
||||||
|
|
||||||
for (int row : field.second)
|
for (int row : field.second)
|
||||||
newInfo.wildPokemon.append({5, 5, "SPECIES_NONE"});
|
newInfo.wildPokemon.append(WildPokemon());
|
||||||
|
|
||||||
return newInfo;
|
return newInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,6 +419,14 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
||||||
fieldChoices->setCurrentIndex(fieldChoices->count() - 1);
|
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"), "");
|
QPushButton *addSlotButton = new QPushButton(QIcon(":/icons/add.ico"), "");
|
||||||
addSlotButton->setFlat(true);
|
addSlotButton->setFlat(true);
|
||||||
|
@ -440,6 +448,7 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
||||||
QHBoxLayout firstRowLayout;
|
QHBoxLayout firstRowLayout;
|
||||||
firstRowLayout.addWidget(fieldChoiceLabel);
|
firstRowLayout.addWidget(fieldChoiceLabel);
|
||||||
firstRowLayout.addWidget(fieldChoices);
|
firstRowLayout.addWidget(fieldChoices);
|
||||||
|
firstRowLayout.addWidget(deleteFieldButton);
|
||||||
firstRowLayout.addWidget(addFieldButton);
|
firstRowLayout.addWidget(addFieldButton);
|
||||||
firstRowLayout.addWidget(removeSlotButton);
|
firstRowLayout.addWidget(removeSlotButton);
|
||||||
firstRowLayout.addWidget(addSlotButton);
|
firstRowLayout.addWidget(addSlotButton);
|
||||||
|
@ -460,14 +469,10 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
||||||
layout.addWidget(frameBottom);
|
layout.addWidget(frameBottom);
|
||||||
|
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
// Copy the temporary modified field info to project.
|
updateEncounterFields(tempFields);
|
||||||
Fields &newFields = project->wildMonFields;
|
|
||||||
newFields = tempFields;
|
|
||||||
|
|
||||||
// Re-draw the tab accordingly.
|
// Re-draw the tab accordingly.
|
||||||
displayWildMonTables();
|
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() {
|
void Editor::setDiveEmergeControls() {
|
||||||
ui->comboBox_DiveMap->blockSignals(true);
|
ui->comboBox_DiveMap->blockSignals(true);
|
||||||
ui->comboBox_EmergeMap->blockSignals(true);
|
ui->comboBox_EmergeMap->blockSignals(true);
|
||||||
|
|
|
@ -1418,11 +1418,11 @@ void Project::readWildMonData() {
|
||||||
header.wildMons[field].active = true;
|
header.wildMons[field].active = true;
|
||||||
header.wildMons[field].encounterRate = encounter.toObject().value(field).toObject().value("encounter_rate").toInt();
|
header.wildMons[field].encounterRate = encounter.toObject().value(field).toObject().value("encounter_rate").toInt();
|
||||||
for (QJsonValue mon : encounter.toObject().value(field).toObject().value("mons").toArray()) {
|
for (QJsonValue mon : encounter.toObject().value(field).toObject().value("mons").toArray()) {
|
||||||
header.wildMons[field].wildPokemon.append({
|
WildPokemon newMon;
|
||||||
mon.toObject().value("min_level").toInt(),
|
newMon.minLevel = mon.toObject().value("min_level").toInt();
|
||||||
mon.toObject().value("max_level").toInt(),
|
newMon.maxLevel = mon.toObject().value("max_level").toInt();
|
||||||
mon.toObject().value("species").toString()
|
newMon.species = mon.toObject().value("species").toString();
|
||||||
});
|
header.wildMons[field].wildPokemon.append(newMon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue