diff options
Diffstat (limited to 'menu/menu.gd')
| -rw-r--r-- | menu/menu.gd | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/menu/menu.gd b/menu/menu.gd index 5f13949..735f86a 100644 --- a/menu/menu.gd +++ b/menu/menu.gd @@ -1,12 +1,13 @@ extends MenuButton const menu_items: Array = [ - { label = "IMPORT OPTION SETS", action = "import_option_sets_action" }, - { label = "EXPORT OPTION SETS", action = "export_option_sets_action" }, - { label = "CLEAR OPTION SETS", action = "clear_option_sets_action" }, - { label = "EXPORT DATA", action = "export_data_action" }, - { label = "CLEAR DATA", action = "clear_data_action" }, - { label = "ABOUT", action = "about_action" }, + { label = "Import Option Sets", action = "import_option_sets_action" }, + { label = "Export Option Sets", action = "export_option_sets_action" }, + { label = "Clear Option Sets", action = "clear_option_sets_action" }, + { label = "Import Database", action = "import_database_action" }, + { 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" @@ -31,39 +32,27 @@ func id_pressed(id: int): func import_option_sets_action(): + dialog.setup("All option sets from the dropdown menus will be replaced.", "Continue", "No") + dialog.connect("accepted", self, "import_option_sets_action_accepted") + popup.open_popup("Replace option sets?", dialog) + + +func import_option_sets_action_accepted(): file_picker.mode = FileDialog.MODE_OPEN_FILE 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", self, "import_option_sets_action_confirmed") + file_picker.connect("file_selected", stage, "load_option_sets") file_picker.show_modal(true) file_picker.invalidate() -func import_option_sets_action_confirmed(file_path: String): - match file_path.get_extension(): - "json": - stage.load_option_sets(file_path) - stage.sanitize_option_sets(stage.option_sets) - stage.save_option_sets() - - "csv": - var database := Database.import_database(file_path) - for it in database: - stage.gather_option_sets(it) - stage.save_option_sets() - - _: - push_error("Invalid file extension selected to be parsed for option sets: '%s'." % file_path.get_file()) - return - - func export_option_sets_action(): file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters = ["*.json"] file_picker.current_file = "" - file_picker.connect("file_selected", stage, "save_option_sets", [], CONNECT_ONESHOT) + file_picker.connect("file_selected", stage, "save_option_sets") file_picker.show_modal(true) file_picker.invalidate() @@ -74,17 +63,33 @@ func clear_option_sets_action(): popup.open_popup("Clear option sets?", dialog) -func export_data_action(): +func import_database_action(): + dialog.setup("All entries from the database will be replaced.", "Continue", "No") + dialog.connect("accepted", self, "import_database_action_accepted") + popup.open_popup("Replace database?", dialog) + + +func import_database_action_accepted(): + file_picker.mode = FileDialog.MODE_OPEN_FILE + 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.show_modal(true) + file_picker.invalidate() + + +func export_database_action(): file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters = ["*.csv"] file_picker.current_file = "" - file_picker.connect("file_selected", database, "save_database", [], CONNECT_ONESHOT) + file_picker.connect("file_selected", database, "save_database") file_picker.show_modal(true) file_picker.invalidate() -func clear_data_action(): +func clear_database_action(): dialog.setup("All entries from the database will be deleted.", "Delete all", "No") dialog.connect("accepted", database, "clear_database") popup.open_popup("Clear database?", dialog) |
