From 350a4fab9e297083c05894c953700d4d5795ade9 Mon Sep 17 00:00:00 2001 From: Quildra Date: Wed, 23 Oct 2024 22:07:58 +0100 Subject: [PATCH] - Add in saves for the new exclusive encounters --- DBEditor/DBEditor.py | 6 ----- DBEditor/db_controller.py | 6 +++++ DBEditor/pokemon_db_ui.py | 55 +++++++++++++++++++++++--------------- pokemon_forms.db | Bin 3100672 -> 3108864 bytes 4 files changed, 40 insertions(+), 27 deletions(-) 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 13777762085012c9625f5687617769269637aa49..37770799ba4a1edb706bced247ed7a4e57f4aac0 100644 GIT binary patch delta 3533 zcmZ{nd2AF_9LMK)bG(_^PTK`)TME;1wYC&czylSQvb124wOgtPQit84U3PZ2?g6c! z^jb~zv693Vl!I&UM|1cU&iAOXs5&tn_6o`pRltlf#DZ4X!u*tWbH}5y^ znEm8^+5@kgVGsOxhCSX~w~t}CD~$V5Pjua^?PI$4JmJ#^nR<5riFhkw_j6bBt>=E5 zJUCt_H3S0O;fbud)3&T+B$Z2Mt@N-p9%Wz1T1k;POkfhFjg@^1Tl)yM7;c<!t@{e*sIj?-9e5!n)ysf;dJgXd4_9+SF zL1nYjqbyhED}F`7SMf!B9)F9cCh-UOBz_q`jSu4t-i~|mD%_15F)Lq`zmq?c&&Vg` zgK|>dE{Ekld6m3GZk6k0QTj{zS^7@;M0!tpQ+i%HCXGvRX@|5~S|i;ebxX4)QM@W% z7Jm>w7vB+I5>JSS#Dq8~t`Z|M+Agl{9)&k$Q43Vivi#`cesN=K>PSztFPKB%5j9;HYH` zTBdDmGBa_kl6w%-$PUF)ww1*i*@T#8HXJe2wCN}Pi0NSatr063%@~1n#L8vldU7`% zCp;QU#*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