Browse Source

- Write the plan out to disk

plan_generation
Dan 1 year ago
parent
commit
5ebbad4ba7
  1. 39
      ui/main_window_controller.py
  2. 16
      ui/workers/generate_plan_worker.py

39
ui/main_window_controller.py

@ -1,3 +1,4 @@
import json
from PyQt6.QtCore import Qt, QTimer, QThreadPool from PyQt6.QtCore import Qt, QTimer, QThreadPool
from PyQt6.QtWidgets import QMenu from PyQt6.QtWidgets import QMenu
from PyQt6.QtGui import QAction 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.gather_evolutions_worker import GatherEvolutions
from ui.workers.generate_plan_worker import GeneratePlanWorker 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 from db import db
class MainWindowController: class MainWindowController:
@ -219,3 +220,39 @@ class MainWindowController:
def on_plan_generated(self, data): def on_plan_generated(self, data):
print("Plans Done!") 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)

16
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 from utility.functions import get_shiftable_forms, get_shiftable_forms_bidirectional, parse_pfic, sanitize_filename
class GeneratePlanWorkerSignals(QObject): class GeneratePlanWorkerSignals(QObject):
finished = pyqtSignal(dict) finished = pyqtSignal(list)
class GeneratePlanWorker(QRunnable): class GeneratePlanWorker(QRunnable):
def __init__(self): def __init__(self):
@ -54,7 +54,7 @@ class GeneratePlanWorker(QRunnable):
if not found: if not found:
print(home_pokemon) print(home_pokemon)
return {} return self.game_plan
def plan_for_group(self, group): def plan_for_group(self, group):
group_plan = [] group_plan = []
@ -287,6 +287,7 @@ class GeneratePlanWorker(QRunnable):
pokemon_to_catch = {} pokemon_to_catch = {}
pokemon_to_breed = {} pokemon_to_breed = {}
pokemon_map = {} pokemon_map = {}
other_map = {}
def record_catch(pfic, gender, to_get): def record_catch(pfic, gender, to_get):
if pfic not in encounters_in_game: if pfic not in encounters_in_game:
@ -305,6 +306,11 @@ class GeneratePlanWorker(QRunnable):
pokemon_map[to_get] = {} pokemon_map[to_get] = {}
pokemon_map[to_get]["ByEvolving"] = pfic 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): def record_breed(pfic, gender, to_get):
if pfic not in pokemon_to_breed: if pfic not in pokemon_to_breed:
@ -320,6 +326,11 @@ class GeneratePlanWorker(QRunnable):
pokemon_map[to_get] = {} pokemon_map[to_get] = {}
pokemon_map[to_get]["ByBreeding"] = pfic 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 # TODO: Move this to a last pass
#if pfic not in pokemon_to_catch: #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_catch"] = pokemon_to_catch
game_plan["pokemon_to_breed"] = pokemon_to_breed game_plan["pokemon_to_breed"] = pokemon_to_breed
game_plan["pokemon_map"] = pokemon_map game_plan["pokemon_map"] = pokemon_map
game_plan["other_map"] = other_map
for required in required_pokemon: for required in required_pokemon:
if required not in pokemon_map: if required not in pokemon_map:

Loading…
Cancel
Save