diff --git a/ui/main_window_controller.py b/ui/main_window_controller.py index afd23fa..d60307c 100644 --- a/ui/main_window_controller.py +++ b/ui/main_window_controller.py @@ -1,3 +1,4 @@ +import json from PyQt6.QtCore import Qt, QTimer, QThreadPool from PyQt6.QtWidgets import QMenu from PyQt6.QtGui import QAction @@ -11,7 +12,7 @@ from ui.workers.gather_pokemon_forms_worker import GatherPokemonFormsWorker from ui.workers.gather_evolutions_worker import GatherEvolutions from ui.workers.generate_plan_worker import GeneratePlanWorker -from utility.functions import get_display_name +from utility.functions import get_display_name, sanitize_filename from db import db class MainWindowController: @@ -219,3 +220,39 @@ class MainWindowController: def on_plan_generated(self, data): print("Plans Done!") + full_plan = [] + family_map = {} + for game_plan in data: + obj = {} + obj["game_name"] = game_plan["game_name"] + family_map = {} + for key in game_plan["pokemon_to_catch"]: + pokemon_to_catch = game_plan["pokemon_to_catch"][key] + family_key = key[:-2] + if family_key not in family_map: + family_map[family_key] = {} + family_map[family_key]["representative"] = key + family_map[family_key]["catch_count"] = 0 + family_map[family_key]["evolve_to"] = [] + family_map[family_key]["breed_for"] = [] + + catch_count = family_map[family_key]["catch_count"] + + for catch_key in pokemon_to_catch: + family_map[family_key][catch_key] = pokemon_to_catch[catch_key] + catch_count += pokemon_to_catch[catch_key] + + family_map[family_key]["catch_count"] = catch_count + catch_details = game_plan["other_map"][key] + + family_map[family_key]["evolve_to"].extend(catch_details["EvolveTo"]) + family_map[family_key]["breed_for"].extend(catch_details["BreedFor"]) + + pass + obj["pokemon"] = family_map + full_plan.append(obj) + + output_file = "./temp/plan.json" + with open(output_file, 'w', encoding='utf-8') as f: + json.dump(full_plan, f, indent=4, ensure_ascii=False) + diff --git a/ui/workers/generate_plan_worker.py b/ui/workers/generate_plan_worker.py index 0476304..50e0618 100644 --- a/ui/workers/generate_plan_worker.py +++ b/ui/workers/generate_plan_worker.py @@ -8,7 +8,7 @@ from utility.data import exclusive_choice_pokemon from utility.functions import get_shiftable_forms, get_shiftable_forms_bidirectional, parse_pfic, sanitize_filename class GeneratePlanWorkerSignals(QObject): - finished = pyqtSignal(dict) + finished = pyqtSignal(list) class GeneratePlanWorker(QRunnable): def __init__(self): @@ -54,7 +54,7 @@ class GeneratePlanWorker(QRunnable): if not found: print(home_pokemon) - return {} + return self.game_plan def plan_for_group(self, group): group_plan = [] @@ -287,6 +287,7 @@ class GeneratePlanWorker(QRunnable): pokemon_to_catch = {} pokemon_to_breed = {} pokemon_map = {} + other_map = {} def record_catch(pfic, gender, to_get): if pfic not in encounters_in_game: @@ -305,6 +306,11 @@ class GeneratePlanWorker(QRunnable): pokemon_map[to_get] = {} pokemon_map[to_get]["ByEvolving"] = pfic + if pfic not in other_map: + other_map[pfic] = {} + other_map[pfic]["EvolveTo"] = [] + other_map[pfic]["BreedFor"] = [] + other_map[pfic]["EvolveTo"].append(to_get) def record_breed(pfic, gender, to_get): if pfic not in pokemon_to_breed: @@ -320,6 +326,11 @@ class GeneratePlanWorker(QRunnable): pokemon_map[to_get] = {} pokemon_map[to_get]["ByBreeding"] = pfic + if pfic not in other_map: + other_map[pfic] = {} + other_map[pfic]["EvolveTo"] = [] + other_map[pfic]["BreedFor"] = [] + other_map[pfic]["BreedFor"].append(to_get) # TODO: Move this to a last pass #if pfic not in pokemon_to_catch: @@ -402,6 +413,7 @@ class GeneratePlanWorker(QRunnable): game_plan["pokemon_to_catch"] = pokemon_to_catch game_plan["pokemon_to_breed"] = pokemon_to_breed game_plan["pokemon_map"] = pokemon_map + game_plan["other_map"] = other_map for required in required_pokemon: if required not in pokemon_map: