diff --git a/database/db_controller.py b/database/db_controller.py index e2c0e0c..71835a5 100644 --- a/database/db_controller.py +++ b/database/db_controller.py @@ -418,13 +418,25 @@ class DBController: return [row['PFIC'] for row in results] def get_game_id_by_name(self, name): + # First try: exact match against the `name` column self.cursor.execute(''' SELECT id, name, generation FROM games - WHERE name LIKE ? OR alt_names LIKE ? - ''', (f"%{name}%", f"%{name}%")) - - # Fetch and print the results + WHERE name = ? + ''', (name,)) + + # Fetch the result result = self.cursor.fetchone() + + # If no exact match found, try matching using `LIKE` with both `name` and `alt_names` + if not result: + self.cursor.execute(''' + SELECT id, name, generation FROM games + WHERE name LIKE ? OR alt_names LIKE ? + ''', (f"%{name}%", f"%{name}%")) + + # Fetch the result from the second query + result = self.cursor.fetchone() + print(f"ID: {result[0]}, Name: {result[1]}, Generation: {result[2]}") return dict(result) diff --git a/ui/main_window_controller.py b/ui/main_window_controller.py index f2a20af..19be816 100644 --- a/ui/main_window_controller.py +++ b/ui/main_window_controller.py @@ -195,9 +195,13 @@ class MainWindowController: self.view.image_label.setText("Image not found") self.load_evolution_chain(pfic) - #self.load_encounter_locations(pfic) + self.load_encounter_locations(pfic) self.current_pfic = pfic def load_evolution_chain(self, pfic): chain = db.get_full_evolution_paths(pfic) self.view.update_evolution_tree(chain, pfic) + + def load_encounter_locations(self, pfic): + encounters = db.get_encounters(pfic) + self.view.update_encounter_list(encounters, pfic) diff --git a/ui/main_window_view.py b/ui/main_window_view.py index c2968a2..3454aa0 100644 --- a/ui/main_window_view.py +++ b/ui/main_window_view.py @@ -8,6 +8,7 @@ from .main_window_controller import MainWindowController from utility.functions import get_display_name from db import db +import json class PokemonUI(QWidget): def __init__(self, parent=None): @@ -293,4 +294,65 @@ class PokemonUI(QWidget): if selected_pfic in tree_items: current_item = tree_items[selected_pfic] self.evolution_tree.scrollToItem(current_item) - self.evolution_tree.setCurrentItem(current_item) \ No newline at end of file + self.evolution_tree.setCurrentItem(current_item) + + def update_encounter_list(self, encounters, pfic): + self.locations_tree.clear() + game_items = {} + + for encounter in encounters: + pfic = encounter["PFIC"] + game_id = encounter["game_id"] + type = encounter["type"] + + if type == "event": + continue + + if type == "evolve": + continue + + data = json.loads(encounter["data"]) + game = db.get_game_by_id(game_id) + game_name = game["name"] + location = data["location"] + + if game_name not in game_items: + #print(f'finding generation for {game}') + game_item = QTreeWidgetItem([game_name]) + game_items[game_name] = game_item + # Use generation for sorting, default to 0 if not found + game_item.setData(0, Qt.ItemDataRole.UserRole, game["generation"]) + #print(f'generation for {game} is {generation}') + + location_item = QTreeWidgetItem([location]) + details = [] + if "day" in data: + details.append(f"Day: {data["day"]}") + if "time" in data: + details.append(f"Time: {data["time"]}") + if "dual_slot" in data: + details.append(f"Dual Slot: {data["dual_slot"]}") + if "static_encounter" in data: + details.append(f"Static Encounter (Count: {data["static_encounter_count"]})") + if "extra_text" in data: + details.append(f"Extra: {data["extra_text"]}") + if "stars" in data: + details.append(f"Stars: {data["stars"]}") + if "fishing" in data: + details.append(f"Fishing") + if "rods" in data: + details.append(f"Rods: {data["rods"]}") + + location_item.setText(1, ", ".join(details)) + game_items[game_name].addChild(location_item) + + # Sort game items by generation and add them to the tree + sorted_game_items = sorted(game_items.values(), key=lambda x: x.data(0, Qt.ItemDataRole.UserRole)) + self.locations_tree.addTopLevelItems(sorted_game_items) + self.locations_tree.expandAll() + + # Update the cache for this Pokémon + #self.encounter_cache[pfic] = len(encounters) > 0 + + # After updating the locations tree + #self.update_pokemon_list_highlights() \ No newline at end of file diff --git a/utility/data.py b/utility/data.py index db09dd9..df4a40c 100644 --- a/utility/data.py +++ b/utility/data.py @@ -15,261 +15,298 @@ regional_descriptors = ["Kantonian", "Johtonian", "Hoennian", "Sinnohan", "Unova yellow = { "Name": "Yellow", - "AltNames": ["Pokemon Yellow", "Pokémon Yellow", "Y"], + "AltNames": ["Pokemon Yellow", "Pokémon Yellow"], "Generation": 1, - "Mark": "Game Boy" + "Mark": "Game Boy", + "Abvr": "Y" } red = { "Name": "Red", - "AltNames": ["Pokemon Red", "Pokémon Red", "R"], + "AltNames": ["Pokemon Red", "Pokémon Red"], "Generation": 1, - "Mark": "Game Boy" + "Mark": "Game Boy", + "Abvr": "R" } blue = { "Name": "Blue", - "AltNames": ["Pokemon Blue", "Pokémon Blue", "B"], + "AltNames": ["Pokemon Blue", "Pokémon Blue"], "Generation": 1, - "Mark": "Game Boy" + "Mark": "Game Boy", + "Abvr": "B" } crystal = { "Name": "Crystal", - "AltNames": ["Pokemon Crystal", "Pokémon Crystal", "C"], + "AltNames": ["Pokemon Crystal", "Pokémon Crystal"], "Generation": 2, - "Mark": "Game Boy" + "Mark": "Game Boy", + "Abvr": "C" } gold = { "Name": "Gold", - "AltNames": ["Pokemon Gold", "Pokémon Gold", "G"], + "AltNames": ["Pokemon Gold", "Pokémon Gold"], "Generation": 2, - "Mark": "Game Boy" + "Mark": "Game Boy", + "Abvr": "G" } silver = { "Name": "Silver", - "AltNames": ["Pokemon Silver", "Pokémon Silver", "S"], + "AltNames": ["Pokemon Silver", "Pokémon Silver"], "Generation": 2, - "Mark": "Game Boy" + "Mark": "Game Boy", + "Abvr": "S" } emerald = { "Name": "Emerald", - "AltNames": ["Pokemon Emerald", "Pokémon Emerald", "E"], + "AltNames": ["Pokemon Emerald", "Pokémon Emerald"], "Generation": 3, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "E" } fire_red = { "Name": "FireRed", - "AltNames": ["Pokemon FireRed", "Pokémon FireRed", "FR"], + "AltNames": ["Pokemon FireRed", "Pokémon FireRed"], "Generation": 3, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "FR" } leaf_green = { "Name": "LeafGreen", - "AltNames": ["Pokemon LeafGreen", "Pokémon LeafGreen", "LG"], + "AltNames": ["Pokemon LeafGreen", "Pokémon LeafGreen"], "Generation": 3, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "LG" } ruby = { "Name": "Ruby", - "AltNames": ["Pokemon Ruby", "Pokémon Ruby", "R"], + "AltNames": ["Pokemon Ruby", "Pokémon Ruby"], "Generation": 3, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "R" } sapphire = { "Name": "Sapphire", - "AltNames": ["Pokemon Sapphire", "Pokémon Sapphire", "S"], + "AltNames": ["Pokemon Sapphire", "Pokémon Sapphire"], "Generation": 3, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "S" } platinum = { "Name": "Platinum", - "AltNames": ["Pokemon Platinum", "Pokémon Platinum", "Pt"], + "AltNames": ["Pokemon Platinum", "Pokémon Platinum"], "Generation": 4, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "Pt" } heart_gold = { "Name": "HeartGold", - "AltNames": ["Pokemon HeartGold", "Pokémon HeartGold", "HG"], + "AltNames": ["Pokemon HeartGold", "Pokémon HeartGold"], "Generation": 4, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "HG" } soul_silver = { "Name": "SoulSilver", - "AltNames": ["Pokemon SoulSilver", "Pokémon SoulSilver", "SS"], + "AltNames": ["Pokemon SoulSilver", "Pokémon SoulSilver"], "Generation": 4, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "SS" } diamond = { "Name": "Diamond", - "AltNames": ["Pokemon Diamond", "Pokémon Diamond", "D"], + "AltNames": ["Pokemon Diamond", "Pokémon Diamond"], "Generation": 4, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "D" } pearl = { "Name": "Pearl", - "AltNames": ["Pokemon Pearl", "Pokémon Pearl", "P"], + "AltNames": ["Pokemon Pearl", "Pokémon Pearl"], "Generation": 4, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "P" } black = { "Name": "Black", - "AltNames": ["Pokemon Black", "Pokémon Black", "B"], + "AltNames": ["Pokemon Black", "Pokémon Black"], "Generation": 5, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "B" } white = { "Name": "White", - "AltNames": ["Pokemon White", "Pokémon White", "W"], + "AltNames": ["Pokemon White", "Pokémon White"], "Generation": 5, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "W" } black_2 = { "Name": "Black 2", - "AltNames": ["Pokemon Black 2", "Pokémon Black 2", "B2"], + "AltNames": ["Pokemon Black 2", "Pokémon Black 2"], "Generation": 5, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "B2" } white_2 = { "Name": "White 2", - "AltNames": ["Pokemon White 2", "Pokémon White 2", "W2"], + "AltNames": ["Pokemon White 2", "Pokémon White 2"], "Generation": 5, - "Mark": "Markless" + "Mark": "Markless", + "Abvr": "W2" } x = { "Name": "X", "AltNames": ["Pokemon X", "Pokémon X"], "Generation": 6, - "Mark": "Kalos" + "Mark": "Kalos", + "Abvr": "X" } y = { "Name": "Y", "AltNames": ["Pokemon Y", "Pokémon Y"], "Generation": 6, - "Mark": "Kalos" + "Mark": "Kalos", + "Abvr": "Y" } omega_ruby = { "Name": "Omega Ruby", - "AltNames": ["Pokemon Omega Ruby", "Pokémon Omega Ruby", "OR"], + "AltNames": ["Pokemon Omega Ruby", "Pokémon Omega Ruby"], "Generation": 6, - "Mark": "Kalos" + "Mark": "Kalos", + "Abvr": "OR" } alpha_sapphire = { "Name": "Alpha Sapphire", - "AltNames": ["Pokemon Alpha Sapphire", "Pokémon Alpha Sapphire", "AS"], + "AltNames": ["Pokemon Alpha Sapphire", "Pokémon Alpha Sapphire"], "Generation": 6, - "Mark": "Kalos" + "Mark": "Kalos", + "Abvr": "AS" } sun = { "Name": "Sun", "AltNames": ["Pokemon Sun", "Pokémon Sun"], "Generation": 7, - "Mark": "Alola" + "Mark": "Alola", + "Abvr": "" } moon = { "Name": "Moon", "AltNames": ["Pokemon Moon", "Pokémon Moon"], "Generation": 7, - "Mark": "Alola" + "Mark": "Alola", + "Abvr": "" } ultra_sun = { "Name": "Ultra Sun", - "AltNames": ["Pokemon Ultra Sun", "Pokémon Ultra Sun", "US"], + "AltNames": ["Pokemon Ultra Sun", "Pokémon Ultra Sun"], "Generation": 7, - "Mark": "Alola" + "Mark": "Alola", + "Abvr": "US" } ultra_moon = { "Name": "Ultra Moon", - "AltNames": ["Pokemon Ultra Moon", "Pokémon Ultra Moon", "UM"], + "AltNames": ["Pokemon Ultra Moon", "Pokémon Ultra Moon"], "Generation": 7, - "Mark": "Alola" + "Mark": "Alola", + "Abvr": "UM" } sword = { "Name": "Sword", "AltNames": ["Pokemon Sword", "Pokémon Sword", "Expansion Pass", "Expansion Pass (Sword)"], "Generation": 8, - "Mark": "Galar" + "Mark": "Galar", + "Abvr": "" } shield = { "Name": "Shield", "AltNames": ["Pokemon Shield", "Pokémon Shield", "Expansion Pass", "Expansion Pass (Shield)"], "Generation": 8, - "Mark": "Galar" + "Mark": "Galar", + "Abvr": "" } brilliant_diamond = { "Name": "Brilliant Diamond", - "AltNames": ["Pokemon Brilliant Diamond", "Pokémon Brilliant Diamond", "BD"], + "AltNames": ["Pokemon Brilliant Diamond", "Pokémon Brilliant Diamond"], "Generation": 8, - "Mark": "Sinnoh" + "Mark": "Sinnoh", + "Abvr": "BD" } shining_pearl = { "Name": "Shining Pearl", - "AltNames": ["Pokemon Shining Pearl", "Pokémon Shining Pearl", "SP"], + "AltNames": ["Pokemon Shining Pearl", "Pokémon Shining Pearl"], "Generation": 8, - "Mark": "Sinnoh" + "Mark": "Sinnoh", + "Abvr": "SP" } legends_arceus = { "Name": "Legends: Arceus", - "AltNames": ["Pokemon Legends: Arceus", "Pokémon Legends: Arceus", "LA", "Legends Arceus", "Arceus"], + "AltNames": ["Pokemon Legends: Arceus", "Pokémon Legends: Arceus", "Legends Arceus", "Arceus"], "Generation": 8, - "Mark": "Hisui" + "Mark": "Hisui", + "Abvr": "LA" } scarlet = { "Name": "Scarlet", "AltNames": ["Pokemon Scarlet", "Pokémon Scarlet", "The Hidden Treasure of Area Zero", "The Hidden Treasure of Area Zero (Scarlet)", "The Teal Mask", "The Teal Mask (Scarlet)"], "Generation": 9, - "Mark": "Paldea" + "Mark": "Paldea", + "Abvr": "" } violet = { "Name": "Violet", "AltNames": ["Pokemon Violet", "Pokémon Violet", "The Hidden Treasure of Area Zero", "The Hidden Treasure of Area Zero (Violet)", "The Teal Mask", "The Teal Mask (Violet)"], "Generation": 9, - "Mark": "Paldea" + "Mark": "Paldea", + "Abvr": "" } lets_go_pikachu = { "Name": "Lets Go Pikachu", "AltNames": [], "Generation": 8, - "Mark": "Let's Go" + "Mark": "Let's Go", + "Abvr": "" } lets_go_eevee = { "Name": "Lets Go Eevee", "AltNames": [], "Generation": 8, - "Mark": "Let's Go" + "Mark": "Let's Go", + "Abvr": "" } main_line_games = [ @@ -351,7 +388,15 @@ POKEMON_PROPER_NOUNS = { "Augurite", "Electirizer", "Magmarizer", - "Gigantamax" + "Gigantamax", + "Hangry", + "Amped", + "Eternamax", + "Terastal", + "Pa'u", + "Sensu", + "Debutante", + "Douse" } POKEMON_PROPER_NOUNS = POKEMON_PROPER_NOUNS | set(regions) diff --git a/utility/pokemon_word_ninja.py b/utility/pokemon_word_ninja.py index 2ff87f4..55b16df 100644 --- a/utility/pokemon_word_ninja.py +++ b/utility/pokemon_word_ninja.py @@ -31,12 +31,15 @@ class PokemonWordNinja: def split(self, text: str) -> str: working_text = text + working_text = working_text.replace("-", " ") # First handle exact custom words to preserve capitalization for word in self.custom_words: - placeholder = self.word_to_placeholder_map[word] - pattern = re.compile(re.escape(word), re.IGNORECASE) - working_text = pattern.sub(placeholder, working_text) + # Use word boundaries to make sure we only match full words + pattern = re.compile(r'\b' + re.escape(word) + r'\b', re.IGNORECASE) + if pattern.search(working_text): + placeholder = self.word_to_placeholder_map[word] + working_text = pattern.sub(placeholder, working_text) # Clean up spaces working_text = ' '.join(working_text.split())