diff --git a/DBEditor/DBEditor.py b/DBEditor/DBEditor.py index dbf3fd9..23dd903 100644 --- a/DBEditor/DBEditor.py +++ b/DBEditor/DBEditor.py @@ -99,8 +99,6 @@ class DBEditor(QMainWindow): self.conn = sqlite3.connect(':memory:', check_same_thread=False) # Use in-memory database for runtime self.cursor = self.conn.cursor() self.init_database() - #self.patches = self.load_and_apply_patches() - self.patches = {} self.init_ui() @@ -169,10 +167,6 @@ class DBEditor(QMainWindow): self.conn.commit() return patches - def save_patches(self): - with open('patches.json', 'w') as f: - json.dump(self.patches, f) - def save_changes(self, data): # Your existing code to save changes pass diff --git a/DBEditor/db_controller.py b/DBEditor/db_controller.py index e5c9ea1..8f84cc2 100644 --- a/DBEditor/db_controller.py +++ b/DBEditor/db_controller.py @@ -32,6 +32,7 @@ class DBController: event_system.add_listener('add_encounter_to_set', self.add_encounter_to_set) event_system.add_listener('get_games_list', self.get_games_list) event_system.add_listener('add_new_exclusive_set', self.add_new_exclusive_set) + event_system.add_listener('save_changes', self.save_changes) def init_database(self): disk_conn = sqlite3.connect('pokemon_forms.db') @@ -436,3 +437,8 @@ class DBController: WHERE g.id = ? ''', (game_id,)) return self.cursor.fetchall() + + def save_changes(self, data): + disk_conn = sqlite3.connect('pokemon_forms.db') + self.conn.backup(disk_conn) + disk_conn.close() diff --git a/DBEditor/pokemon_db_ui.py b/DBEditor/pokemon_db_ui.py index 2651516..24a19f1 100644 --- a/DBEditor/pokemon_db_ui.py +++ b/DBEditor/pokemon_db_ui.py @@ -748,18 +748,20 @@ class PokemonUI(QWidget): # Change from QMainWindow to QWidget new_fishing = fishing_check.isChecked() new_rods = rods_edit.text() or None new_exclusive_group_id = exclusive_group_combo.currentData() + + game_id = event_system.call_sync('get_game_id_for_name', new_game) # Update the database self.cursor.execute(''' - UPDATE encounters - SET game = ?, location = ?, day = ?, time = ?, dual_slot = ?, + UPDATE encounters + SET game_id = ?, location = ?, day = ?, time = ?, dual_slot = ?, static_encounter = ?, static_encounter_count = ?, extra_text = ?, stars = ?, fishing = ?, rods = ? - WHERE pfic = ? AND game = ? AND location = ? - ''', (new_game, new_location, new_day, new_time, new_dual_slot, - new_static_encounter, new_static_encounter_count, new_extra_text, - new_stars, new_fishing, new_rods, - self.current_pfic, game, location)) + WHERE pfic = ? AND game_id = ? AND location = ? + ''', (game_id, new_location, new_day, new_time, new_dual_slot, + new_static_encounter, new_static_encounter_count, new_extra_text, + new_stars, new_fishing, new_rods, + self.current_pfic, game_id, location)) self.conn.commit() # Update the cache if all encounters for this Pokémon were deleted @@ -828,7 +830,7 @@ class PokemonUI(QWidget): # Change from QMainWindow to QWidget game_id = event_system.call_sync('get_game_id_for_name', game) - # Insert new encounter into the database + # Insert new encounter into the in-memory database self.cursor.execute(''' INSERT INTO encounters (pfic, game_id, location, day, time, dual_slot, static_encounter, static_encounter_count, extra_text, stars, fishing, rods) @@ -845,10 +847,31 @@ class PokemonUI(QWidget): # Change from QMainWindow to QWidget def save_changes(self): if hasattr(self, 'current_pfic'): storable_in_home = self.home_checkbox.isChecked() - self.patches[self.current_pfic] = {'storable_in_home': storable_in_home} + is_baby_form = self.is_baby_form_checkbox.isChecked() + + # Update the in-memory database + #self.cursor.execute(''' + # UPDATE pokemon_storage + # SET storable_in_home = ? + # WHERE PFIC = ? + #''', (storable_in_home, self.current_pfic)) + + #self.cursor.execute(''' + # UPDATE pokemon_forms + # SET is_baby_form = ? + # WHERE PFIC = ? + #''', (is_baby_form, self.current_pfic)) - with open('patches.json', 'w') as f: - json.dump(self.patches, f) + #self.conn.commit() + + # Write the in-memory database to disk + #disk_conn = sqlite3.connect('pokemon_forms.db') + #self.conn.backup(disk_conn) + #disk_conn.close() + + event_system.emit_sync('save_changes') + + QMessageBox.information(self, "Save Complete", "Changes have been saved to the database.") def export_database(self): export_conn = sqlite3.connect('pokemon_forms_production.db') @@ -873,16 +896,6 @@ class PokemonUI(QWidget): # Change from QMainWindow to QWidget VALUES (?, ?, ?) ''', (new_from_pfic, new_to_pfic, new_method)) - # Create a new patch - patch_key = f"evolution_{new_from_pfic}_{new_to_pfic}" - self.patches[patch_key] = { - 'action': 'add', - 'from_pfic': new_from_pfic, - 'to_pfic': new_to_pfic, - 'method': new_method - } - self.save_patches() - # Refresh the evolution chain display self.load_evolution_chain(self.current_pfic) diff --git a/pokemon_forms.db b/pokemon_forms.db index 1377776..3777079 100644 Binary files a/pokemon_forms.db and b/pokemon_forms.db differ