diff --git a/DBEditor/DBEditor.py b/DBEditor/DBEditor.py index 615b35d..d9dfe8d 100644 --- a/DBEditor/DBEditor.py +++ b/DBEditor/DBEditor.py @@ -438,6 +438,11 @@ class DBEditor(QMainWindow): QMessageBox.information(self, 'Database Reinitialized', 'The database has been cleared and reinitialized.') def determine_origin_mark(self, pfic, target_generation): + shiftable_forms = event_system.call_sync('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 = event_system.call_sync('get_encounter_locations', pfic) if encounters: generation_encounters = [] @@ -458,7 +463,30 @@ class DBEditor(QMainWindow): self.logger.info(f"Mark for {form_info[0]} {form_info[1]} is {mark_details[0]} - {mark_details[1]}") return mark_id return None - + + def test_evolve_encounters(self, pfic, target_generation): + evolve_encounters = event_system.call_sync('get_evolve_encounters', pfic) + if evolve_encounters: + available_encounters = [] + for encounter in evolve_encounters: + game_id = encounter.game_id + game_info = event_system.call_sync('get_game_by_id', game_id) + if game_info[2] == target_generation: + available_encounters.append(encounter) + + if len(available_encounters) > 0: + available_encounters = sorted(available_encounters, key=lambda x: x.game_id) + mark_id = self.determine_origin_mark(available_encounters[0].from_pfic, target_generation) + if mark_id != None: + return mark_id + + mark_id = self.test_evolve_encounters(available_encounters[0].from_pfic, target_generation) + if mark_id != None: + return mark_id + + return None + + def gather_marks_info(self, data): event_system.emit_sync('clear_log_display') self.logger.info("Starting to gather marks information...") @@ -520,21 +548,10 @@ class DBEditor(QMainWindow): # 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. - evolve_encounters = event_system.call_sync('get_evolve_encounters', pfic) - if evolve_encounters: - available_encounters = [] - for encounter in evolve_encounters: - game_id = encounter.game_id - game_info = event_system.call_sync('get_game_by_id', game_id) - if game_info[2] == target_generation: - available_encounters.append(encounter) - - if len(available_encounters) > 0: - available_encounters = sorted(available_encounters, key=lambda x: x.game_id) - mark_id = self.determine_origin_mark(available_encounters[0].from_pfic, target_generation) - if mark_id != None: - event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) - continue; + mark_id = self.test_evolve_encounters(pfic, target_generation) + if mark_id != None: + event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) + continue; encounters = event_system.call_sync('get_encounter_locations', pfic) count = 0 @@ -547,18 +564,29 @@ class DBEditor(QMainWindow): if count == 0: #Rule 2b # Check to see if this is a sub-form pokemon, and if so, use the mark of the base form. - base = pfic[:-6] - alternate_forms = event_system.call_sync('find_default_form', base) - if alternate_forms: + shiftable_forms = event_system.call_sync('get_shiftable_forms', pfic) + if len(shiftable_forms) > 0: form_found = False - for alternate_form in alternate_forms: - mark_id = self.determine_origin_mark(alternate_form.pfic, target_generation) + for shiftable_form in shiftable_forms: + mark_id = self.determine_origin_mark(shiftable_form[2], target_generation) if mark_id != None: event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) form_found = True break; if form_found: continue; + #base = pfic[:-6] + #alternate_forms = event_system.call_sync('find_default_form', base) + #if alternate_forms: + # form_found = False + # for alternate_form in alternate_forms: + # mark_id = self.determine_origin_mark(alternate_form.pfic, target_generation) + # if mark_id != None: + # event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) + # form_found = True + # break; + # if form_found: + # continue; #Rule 4 # If there are no encounters for the pokemon form or its evolution line from this generation, diff --git a/DBEditor/db_controller.py b/DBEditor/db_controller.py index 746c807..3dd1a37 100644 --- a/DBEditor/db_controller.py +++ b/DBEditor/db_controller.py @@ -56,6 +56,7 @@ class DBController: event_system.add_listener('get_game_by_id', self.get_game_by_id) event_system.add_listener('get_pokemon_form_by_pfic', self.get_pokemon_form_by_pfic) event_system.add_listener('find_default_form', self.find_default_form) + event_system.add_listener('get_shiftable_forms', self.get_shiftable_forms) def init_database(self): disk_conn = sqlite3.connect('pokemon_forms.db') @@ -72,6 +73,7 @@ class DBController: self.create_mark_table(disk_cursor) self.create_form_marks_table(disk_cursor) self.create_evolve_encounter_table(disk_cursor) + self.create_shiftable_forms_table(disk_cursor) # Commit changes to the file-based database disk_conn.commit() @@ -346,6 +348,17 @@ class DBController: ) ''') + def create_shiftable_forms_table(self, cursor): + cursor.execute(''' + CREATE TABLE IF NOT EXISTS shiftable_forms ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + from_pfic TEXT, + to_pfic TEXT, + FOREIGN KEY (from_pfic) REFERENCES pokemon_forms (PFIC), + FOREIGN KEY (to_pfic) REFERENCES pokemon_forms (PFIC) + ) + ''') + def load_pokemon_details(self, pfic): self.cursor.execute(''' SELECT pf.name, pf.form_name, pf.national_dex, pf.generation, ps.storable_in_home, pf.is_baby_form @@ -588,6 +601,11 @@ class DBController: ''', (search_pfic + "%",)) results = self.cursor.fetchall() return [PokemonForm(result[0], result[1], result[2], result[3], result[4], result[6], result[5]) for result in results] + + def get_shiftable_forms(self, data): + pfic = data + self.cursor.execute('SELECT * FROM shiftable_forms WHERE from_pfic = ?', (pfic,)) + return self.cursor.fetchall() def get_connection(self): return self.connection_pool.get() diff --git a/DataGatherers/update_location_information.py b/DataGatherers/update_location_information.py index 141bfed..b1d7df6 100644 --- a/DataGatherers/update_location_information.py +++ b/DataGatherers/update_location_information.py @@ -447,15 +447,6 @@ def process_pokemon_for_location_data(pfic, name, form, national_dex, default_fo test_location_text = BeautifulSoup(test_location, 'html.parser').get_text().lower() - ignore_location = False - for ignore in encounters_to_ignore: - if ignore in test_location_text: - ignore_location = True - break - - if ignore_location: - continue - if print_encounter: logger.info(f"Found in {encounter}:") print_encounter = False @@ -487,6 +478,15 @@ def process_pokemon_for_location_data(pfic, name, form, national_dex, default_fo if remaining_location.strip() == "": continue + ignore_location = False + for ignore in encounters_to_ignore: + if ignore in remaining_location.lower(): + ignore_location = True + break + + if ignore_location: + continue + save_encounter(db_controller, pfic, encounter, remaining_location.strip(), details["days"], details["times"], details["dual_slot"], details["static_encounter"], details["static_encounter_count"], details["extra_text"], details["stars"], details["Rods"], details["Fishing"], details["starter"] ) def extract_evolve_information(s: str, db_controller): diff --git a/pokemon_forms.db b/pokemon_forms.db index a97bbad..bc76ec7 100644 Binary files a/pokemon_forms.db and b/pokemon_forms.db differ