5 changed files with 151 additions and 5 deletions
@ -0,0 +1,101 @@ |
|||||
|
from PyQt6.QtCore import QObject, pyqtSignal, QRunnable |
||||
|
|
||||
|
from cache import cache |
||||
|
from db import db |
||||
|
|
||||
|
from utility.functions import get_display_name, get_shiftable_forms |
||||
|
|
||||
|
class CalculateOriginMarkWorkerSignals(QObject): |
||||
|
finished = pyqtSignal(list) |
||||
|
|
||||
|
class CalculateOriginMarkWorker(QRunnable): |
||||
|
def __init__(self): |
||||
|
super().__init__() |
||||
|
self.signals = CalculateOriginMarkWorkerSignals() |
||||
|
self.marks = {} |
||||
|
|
||||
|
def run(self): |
||||
|
try: |
||||
|
gathered_data = self.calculate_marks() |
||||
|
self.signals.finished.emit(gathered_data) |
||||
|
except Exception as e: |
||||
|
print(f"Error gathering Pokémon home storage status: {e}") |
||||
|
|
||||
|
def calculate_marks(self): |
||||
|
all_pokemon_forms = db.get_list_of_pokemon_forms() |
||||
|
for form_entry in all_pokemon_forms: |
||||
|
if form_entry["storable_in_home"] == False: |
||||
|
continue |
||||
|
|
||||
|
print(f"Determining mark for {get_display_name(form_entry)}") |
||||
|
|
||||
|
target_generation = form_entry["generation"] |
||||
|
pfic = form_entry["pfic"] |
||||
|
|
||||
|
#Rule 1 |
||||
|
# 1. If a pokemon form has a previous evolution from within the same generation, |
||||
|
# use the mark of the previous evolution. This should be recursive within the same generation. |
||||
|
chain = db.get_full_evolution_paths(pfic) |
||||
|
if chain: |
||||
|
base_form_in_generation = None |
||||
|
last_pfic = pfic |
||||
|
current_pfic = pfic |
||||
|
while True: |
||||
|
current_pfic, _ = db.get_previous_evolution(current_pfic) |
||||
|
if current_pfic == None: |
||||
|
base_form_in_generation = last_pfic |
||||
|
break |
||||
|
chain_pokemon_data = db.get_pokemon_details(current_pfic) |
||||
|
#chain_pokemon_data = event_system.call_sync('get_pokemon_form_by_pfic', current_pfic[0]) |
||||
|
if chain_pokemon_data["generation"] == target_generation: |
||||
|
base_form_in_generation = current_pfic |
||||
|
else: |
||||
|
base_form_in_generation = last_pfic |
||||
|
break |
||||
|
last_pfic = current_pfic |
||||
|
|
||||
|
if base_form_in_generation and base_form_in_generation != pfic: |
||||
|
print(f"Base form in generation for {get_display_name(form_entry)} is {base_form_in_generation}") |
||||
|
mark_id = self.determine_origin_mark(base_form_in_generation, target_generation) |
||||
|
if mark_id != None: |
||||
|
#event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) |
||||
|
self.marks[pfic] = mark_id |
||||
|
continue |
||||
|
elif base_form_in_generation == pfic: |
||||
|
mark_id = self.determine_origin_mark(pfic, target_generation) |
||||
|
if mark_id != None: |
||||
|
#event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) |
||||
|
self.marks[pfic] = mark_id |
||||
|
continue; |
||||
|
|
||||
|
pass |
||||
|
|
||||
|
def determine_origin_mark(self, pfic, target_generation): |
||||
|
shiftable_forms = get_shiftable_forms(pfic) |
||||
|
if len(shiftable_forms) > 0: |
||||
|
for shiftable_form in shiftable_forms: |
||||
|
mark_id = self.determine_origin_mark(shiftable_form[2], target_generation) |
||||
|
return mark_id |
||||
|
encounters = db.get_encounters(pfic) |
||||
|
if encounters: |
||||
|
generation_encounters = [] |
||||
|
for encounter in encounters: |
||||
|
game_info = db.get_game_by_id(encounter["game_id"]) |
||||
|
game_generation = game_info["generation"] |
||||
|
game_id = game_info["id"] |
||||
|
encounter = encounter + (game_generation, game_id) |
||||
|
if game_generation == target_generation: |
||||
|
generation_encounters.append(encounter) |
||||
|
if len(generation_encounters) > 0: |
||||
|
generation_encounters = sorted(generation_encounters, key=lambda x: x[12]) |
||||
|
form_info = db.get_pokemon_details(pfic) |
||||
|
game_info = db.get_game_by_id(encounter["game_id"]) |
||||
|
mark_id = 1 # TODO: Work this bit out. |
||||
|
mark_id = event_system.call_sync('get_mark_for_game_name', generation_encounters[0][0]) |
||||
|
if mark_id == None: |
||||
|
self.logger.info(f"No mark found for {form_info[0]} {form_info[1]}") |
||||
|
else: |
||||
|
mark_details = event_system.call_sync('get_mark_details', mark_id) |
||||
|
self.logger.info(f"Mark for {form_info[0]} {form_info[1]} is {mark_details[0]} - {mark_details[1]}") |
||||
|
return mark_id |
||||
|
return None |
||||
Loading…
Reference in new issue