diff --git a/DBEditor/DBEditor.py b/DBEditor/DBEditor.py index f298a84..b093397 100644 --- a/DBEditor/DBEditor.py +++ b/DBEditor/DBEditor.py @@ -609,6 +609,24 @@ class DBEditor(QMainWindow): event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) continue; + event_encounters = event_system.call_sync('get_event_encounters', pfic) + if event_encounters: + earliest_game = 100 + for encounter in event_encounters: + game_id = encounter[2] + if game_id <= earliest_game: + earliest_game = game_id + if earliest_game < 100: + form_info = event_system.call_sync('get_pokemon_data', pfic) + mark_id = event_system.call_sync('get_mark_for_game', earliest_game) + 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]}") + event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) + continue; + def load_shiftable_forms(self, data): try: with open('shiftable_forms.json', 'r') as f: diff --git a/DBEditor/db_controller.py b/DBEditor/db_controller.py index 25fa313..86ac89c 100644 --- a/DBEditor/db_controller.py +++ b/DBEditor/db_controller.py @@ -58,6 +58,7 @@ class DBController: event_system.add_listener('find_default_form', self.find_default_form) event_system.add_listener('get_shiftable_forms', self.get_shiftable_forms) event_system.add_listener('assign_shiftable_form', self.assign_shiftable_form) + event_system.add_listener('get_event_encounters', self.get_event_encounters) def init_database(self): disk_conn = sqlite3.connect('pokemon_forms.db') @@ -74,6 +75,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_event_encounter_table(disk_cursor) self.create_shiftable_forms_table(disk_cursor) # Commit changes to the file-based database @@ -349,6 +351,19 @@ class DBController: ) ''') + def create_event_encounter_table(self, cursor): + cursor.execute(''' + CREATE TABLE IF NOT EXISTS event_encounters ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + pfic TEXT, + game_id INTEGER, + day TEXT, + time TEXT, + FOREIGN KEY (pfic) REFERENCES pokemon_forms (PFIC), + FOREIGN KEY (game_id) REFERENCES games (id) + ) + ''') + def create_shiftable_forms_table(self, cursor): cursor.execute(''' CREATE TABLE IF NOT EXISTS shiftable_forms ( @@ -617,6 +632,11 @@ class DBController: ''', (from_pfic, to_pfic)) self.conn.commit() + def get_event_encounters(self, data): + pfic = data + self.cursor.execute('SELECT * FROM event_encounters WHERE pfic = ?', (pfic,)) + return self.cursor.fetchall() + def get_connection(self): return self.connection_pool.get() diff --git a/DataGatherers/DetermineOriginGame.py b/DataGatherers/DetermineOriginGame.py index 80f6ad2..8912dcb 100644 --- a/DataGatherers/DetermineOriginGame.py +++ b/DataGatherers/DetermineOriginGame.py @@ -681,9 +681,9 @@ def get_locations_from_bulbapedia(pokemon_name, form, cache: CacheManager, defau def process_event_tables(events_section): event_tables = {} if events_section: - next_element = events_section.find_next_sibling() + next_element = events_section.parent.find_next_sibling() while next_element and next_element.name != 'h3': - if next_element.name == 'h4': + if next_element.name == 'h5': variant = next_element.text.strip() table = next_element.find_next_sibling('table', class_='roundy') if table: @@ -691,7 +691,7 @@ def process_event_tables(events_section): next_element = next_element.find_next_sibling() return event_tables -def process_event_table(table, game_locations): +def _process_event_table(table, game_locations): for row in table.find_all('tr')[1:]: # Skip header row cells = row.find_all('td') if len(cells) >= 3: @@ -702,6 +702,48 @@ def process_event_table(table, game_locations): game_locations[game] = [] game_locations[game].append({"location": f"Event: {location}", "tag": str(cells[2])}) +def process_event_table(table, game_locations): + for row in table.find_all('tr')[1:]: # Skip header row + cells = row.find_all('td') + if len(cells) >= 6: # Ensure all required columns are present + # Extract game names as a list + game_links = cells[0].find_all('a') + individual_games = [] + + for link in game_links: + # Replace specific known prefixes + game_name = link['title'].replace("Pokémon ", "").replace("Versions", "").replace(" Version", "").replace(" (Japanese)", "") + + # Split on " and ", which is used for combined games + parsed_names = game_name.split(" and ") + + # Add the parsed names to the list + individual_games.extend(parsed_names) + + # Print extracted game names for debugging + print(f"Extracted game names from row: {individual_games}") + + # Filter games to include only those in all_games + matching_games = [] + + for game in individual_games: + if any(game.strip().lower() == g.lower() for g in all_games): + matching_games.append(game) + + # Print matching games for debugging + print(f"Matching games after filtering: {matching_games}") + + if matching_games: + location = cells[2].text.strip() + distribution_period = cells[5].text.strip() + for game in matching_games: + if game not in game_locations: + game_locations[game] = [] + game_locations[game].append({ + "location": f"Event: {location}", + "tag": str(cells[2]) + }) + def process_game_locations(raw_game, raw_locations, form, default_forms): locations = [] diff --git a/DataGatherers/update_location_information.py b/DataGatherers/update_location_information.py index b1d7df6..0441139 100644 --- a/DataGatherers/update_location_information.py +++ b/DataGatherers/update_location_information.py @@ -361,6 +361,32 @@ def save_evolve_encounter(db_controller, pfic, game, days, times, from_pfic): else: logger.info(f"Identical evolve encounter already exists for {pfic} in {game}") +def save_event_encounter(db_controller, pfic, game): + game_id = event_system.call_sync('get_game_id_for_name', game) + + insert_query = ''' + INSERT INTO event_encounters + (pfic, game_id, day, time) + VALUES (?, ?, ?, ?) + ''' + + criteria = { + "pfic": pfic, + "game_id": game_id, + "day": None, + "time": None + } + + query, values = build_query_string("event_encounters", criteria) + # Check if an identical record already exists + result = db_controller.execute_query(query, values) + + if not result: + db_controller.execute_query_with_commit(insert_query, (pfic, game_id, None, None)) + logger.info(f"New evolve encounter added for {pfic} in {game}") + else: + logger.info(f"Identical event encounter already exists for {pfic} in {game}") + def compare_forms(a, b): if a == b: return True @@ -426,8 +452,7 @@ def process_pokemon_for_location_data(pfic, name, form, national_dex, default_fo "transfer from dream radar", "global link event", "pokémon channel", - "pokémon colosseum bonus disc", - "event" + "pokémon colosseum bonus disc" ] encounter_data = get_locations_from_bulbapedia(name, search_form, cache, default_forms) @@ -458,6 +483,9 @@ def process_pokemon_for_location_data(pfic, name, form, national_dex, default_fo if evolve_info: logger.info(f"Evolve Info: {evolve_info}") save_evolve_encounter(db_controller, pfic, encounter, details["days"], details["times"], evolve_info["evolve_from"]) + elif "event" in test_location_text: + logger.info(f"Event: {location['location']}") + save_event_encounter(db_controller, pfic, encounter) else: remaining, details = extract_additional_information(location["tag"]) routes, remaining = extract_routes(remaining) diff --git a/pokemon_forms.db b/pokemon_forms.db index 74c68a6..72236f1 100644 Binary files a/pokemon_forms.db and b/pokemon_forms.db differ