From e32cef1fee6eabd6db71af71356664d259c5eb2b Mon Sep 17 00:00:00 2001 From: dam Date: Sun, 10 Apr 2022 06:53:01 +0000 Subject: Removed auto-save logic from load_database and load_option_sets; Changed menu logic to save database and optionsets after making changes. --- logic/database.gd | 35 ++++++++++++++++------------------- logic/stage.gd | 3 --- menu/menu.gd | 36 ++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/logic/database.gd b/logic/database.gd index 19216f6..92b707b 100644 --- a/logic/database.gd +++ b/logic/database.gd @@ -183,9 +183,6 @@ func load_database(file_path: String = DATABASE_FILE_PATH): it["date_day"] = int(it["date_day"]) self.add_item(get_entry_view(it)) - - if file_path != DATABASE_FILE_PATH: - save_database() static func sanitize_database(database: Array): @@ -261,21 +258,21 @@ func clear_database(): db.resize(0) -func fake_database(): - clear_database() - for idx in range(500): - var today := OS.get_date(true) - var date_year = today.year + int(float(idx) / 30.0 / 12) - var date_month = 1 + int(float(idx) / 30.0) % 12 - var date_day = 1 + (idx % 30) - var fake_entry = DatabaseEntry.instance_entry({ - "process_id": "%06d" % idx, - "surgery_id": "s%05d" % idx, - "date_year": date_year, - "date_month": date_month, - "date_day": date_day, - }) - db.append(fake_entry) - self.add_item(get_entry_view(fake_entry)) +#func DEBUG_create_fake_database(): +# clear_database() +# for idx in range(500): +# var today := OS.get_date(true) +# var date_year = today.year + int(float(idx) / 30.0 / 12) +# var date_month = 1 + int(float(idx) / 30.0) % 12 +# var date_day = 1 + (idx % 30) +# var fake_entry = DatabaseEntry.instance_entry({ +# "process_id": "%06d" % idx, +# "surgery_id": "s%05d" % idx, +# "date_year": date_year, +# "date_month": date_month, +# "date_day": date_day, +# }) +# db.append(fake_entry) +# self.add_item(get_entry_view(fake_entry)) diff --git a/logic/stage.gd b/logic/stage.gd index a09f611..764ee52 100644 --- a/logic/stage.gd +++ b/logic/stage.gd @@ -247,9 +247,6 @@ func load_option_sets(file_path: String = OPTION_SETS_FILE_PATH): _: printerr("Invalid option sets file extension: '%s'." % file_path.get_file()) return - - if file_path != OPTION_SETS_FILE_PATH: - save_option_sets() static func import_json(file_path: String) -> Dictionary: diff --git a/menu/menu.gd b/menu/menu.gd index c3e3185..d6e1501 100644 --- a/menu/menu.gd +++ b/menu/menu.gd @@ -8,7 +8,6 @@ const menu_items: Array = [ { label = "Export Database", action = "export_database_action" }, { label = "Clear Database", action = "clear_database_action" }, { label = "About", action = "about_action" }, -# { label = "TEST_FAKE_DB", action = "test_fake_db_action" }, ] const license_font_b612: String = "res://licenses/font_b612.txt" const license_godot: String = "res://licenses/godot.txt" @@ -42,11 +41,16 @@ func import_option_sets_action_accepted(): file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters = ["*.json", "*.csv"] file_picker.current_file = "" - file_picker.connect("file_selected", stage, "load_option_sets") + file_picker.connect("file_selected", self, "import_option_sets") file_picker.show_modal(true) file_picker.invalidate() +func import_option_sets(file_path: String): + stage.load_option_sets(file_path) + stage.save_option_sets() + + func export_option_sets_action(): file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) @@ -59,10 +63,15 @@ func export_option_sets_action(): func clear_option_sets_action(): dialog.setup("All option sets from the dropdown menus will be deleted.", "Delete all", "No") - dialog.connect("accepted", stage, "clear_option_sets") + dialog.connect("accepted", self, "clear_option_sets") popup.open_popup("Clear option sets?", dialog) +func clear_option_sets(): + stage.clear_option_sets() + stage.save_option_sets() + + func import_database_action(): dialog.setup("All entries from the database will be replaced.", "Continue", "No") dialog.connect("accepted", self, "import_database_action_accepted") @@ -74,11 +83,16 @@ func import_database_action_accepted(): file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters = ["*.json", "*.csv"] file_picker.current_file = "" - file_picker.connect("file_selected", database, "load_database") + file_picker.connect("file_selected", self, "import_database") file_picker.show_modal(true) file_picker.invalidate() +func import_database(file_path: String): + database.load_database(file_path) + database.save_database() + + func export_database_action(): file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) @@ -91,19 +105,17 @@ func export_database_action(): func clear_database_action(): dialog.setup("All entries from the database will be deleted.", "Delete all", "No") - dialog.connect("accepted", database, "clear_database") + dialog.connect("accepted", self, "clear_database") popup.open_popup("Clear database?", dialog) +func clear_database(): + database.clear_database() + database.save_database() + + func about_action(): dialog.setup("Surgery Log\nversion 0.1", "", "") popup.open_popup("About", dialog) -# @DAM Hide this debug method before release. -func test_fake_db_action(): - dialog.setup("All entries from the database will be deleted and new fake entries inserted.", "Yes", "No") - dialog.connect("accepted", database, "fake_database") - popup.open_popup("Fake DB?", dialog) - - -- cgit v1.2.3