@ -1,4 +1,5 @@
from PyQt6 . QtCore import QObject , pyqtSignal , QRunnable
import json
from cache import cache
from db import db
@ -35,8 +36,9 @@ class CalculateOriginMarkWorker(QRunnable):
#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.
print ( " Checking Rule 1 " )
chain = db . get_full_evolution_paths ( pfic )
if chain :
if chain and ( len ( chain [ " predecessors " ] ) > 0 or len ( chain [ " successors " ] ) > 0 ) :
base_form_in_generation = None
last_pfic = pfic
current_pfic = pfic
@ -46,7 +48,6 @@ class CalculateOriginMarkWorker(QRunnable):
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 :
@ -58,44 +59,81 @@ class CalculateOriginMarkWorker(QRunnable):
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 ;
continue
#Rule 2
# If a pokemon form has no previous evolution from within the same generation,
# look at the encounters of the pokemon form from this generation and use the mark of the earliest
# game you can encounter that form in from that generation
print ( " Checking Rule 2 " )
mark_id = self . determine_origin_mark ( pfic , target_generation )
if mark_id != None :
self . marks [ pfic ] = mark_id
continue
#Rule 3
# If there are no encounters for the pokemon form from this generation,
# look to see if a previous evolution has an encounter from this generation, and use the mark of the earliest
# game from this generation that the previous evolution is encounterable in.
print ( " Checking Rule 3 " )
mark_id = self . test_evolve_encounters ( pfic , target_generation )
if mark_id != None :
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 )
mark_id = self . determine_origin_mark ( shiftable_form [ " to_pfic " ] , 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 :
encounter [ " game " ] = game_info
if encounter [ " game " ] [ " generation " ] == target_generation :
generation_encounters . append ( encounter )
if len ( generation_encounters ) > 0 :
generation_encounters = sorted ( generation_encounters , key = lambda x : x [ 12 ] )
generation_encounters = sorted ( generation_encounters , key = lambda x : x [ " game " ] [ " generation " ] )
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 ] )
game_info = generation_encounters [ 0 ] [ " game " ]
mark_id = game_info [ " mark " ]
if mark_id == None :
self . logger . info ( f " No mark found for { form_info [ 0 ] } { form_info [ 1 ] } " )
#self.logger.info(f"No mark found for {form_info[0]} {form_info[1]}")
print ( f " No mark found for { get_display_name ( form_info ) } " )
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 ] } " )
#self.logger.info(f"Mark for {form_info[0]} {form_info[1]} is {mark_id}")
print ( f " Mark for { get_display_name ( form_info ) } is { mark_id } " )
return mark_id
return None
def test_evolve_encounters ( self , pfic , target_generation ) :
evolve_encounters = db . get_encounters ( pfic , " evolve " )
if evolve_encounters :
available_encounters = [ ]
for encounter in evolve_encounters :
game_info = db . get_game_by_id ( encounter [ " game_id " ] )
if game_info [ " generation " ] == target_generation :
available_encounters . append ( encounter )
if len ( available_encounters ) > 0 :
available_encounters = sorted ( available_encounters , key = lambda x : x . game_id )
data = json . loads ( available_encounters [ 0 ] [ " data " ] )
mark_id = self . determine_origin_mark ( data [ " from_pfic " ] , target_generation )
if mark_id != None :
return mark_id
mark_id = self . test_evolve_encounters ( data [ " from_pfic " ] , target_generation )
if mark_id != None :
return mark_id
return None