diff options
| author | dam <dam@gudinoff> | 2022-03-05 02:02:31 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-03-05 02:02:31 +0000 |
| commit | 9aff9cbc19c44b1b97cacf02dcdd8a54a0f02a76 (patch) | |
| tree | b341a13caba4cfc83630bb9d0517aef62f47e8fe /menu/menu.gd | |
| parent | 61210d74e50d3e10b9a9c069e837d46ae5b133bb (diff) | |
| download | surgery-log-9aff9cbc19c44b1b97cacf02dcdd8a54a0f02a76.tar.zst surgery-log-9aff9cbc19c44b1b97cacf02dcdd8a54a0f02a76.zip | |
Store database and option sets as JSON. Allow to parse options from CSV database or import from JSON file.
Diffstat (limited to 'menu/menu.gd')
| -rw-r--r-- | menu/menu.gd | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/menu/menu.gd b/menu/menu.gd index 5847d5b..9a5bdbb 100644 --- a/menu/menu.gd +++ b/menu/menu.gd @@ -1,13 +1,13 @@ extends MenuButton const menu_items: Array = [ - { label = "IMPORT OPTION SETS", action = "_menu_import_option_sets_action" }, - { label = "EXPORT OPTION SETS", action = "_menu_export_option_sets_action" }, - { label = "CLEAR OPTION SETS", action = "_menu_clear_option_sets_action" }, - { label = "EXPORT DATA", action = "_menu_export_data_action" }, - { label = "CLEAR DATA", action = "_menu_clear_data_action" }, - { label = "ABOUT", action = "_menu_about_action" }, - { label = "FAKE_DB", action = "_menu_fake_db_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 = "EXPORT DATA", action = "export_data_action" }, + { label = "CLEAR DATA", action = "clear_data_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" @@ -29,64 +29,82 @@ func id_pressed(id: int): self.call_deferred(menu_items[id].action) -func _menu_import_option_sets_action(): +func import_option_sets_action(): file_picker.window_title = "IMPORT OPTION SETS" file_picker.mode = FileDialog.MODE_OPEN_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) - file_picker.filters[0] = "*.json" + file_picker.filters = ["*.json", "*.csv"] file_picker.current_file = "" - file_picker.connect("file_selected", stage, "import_option_sets", [true], CONNECT_ONESHOT) + file_picker.connect("file_selected", self, "import_option_sets_action_confirmed", [], CONNECT_ONESHOT) file_picker.show_modal(true) file_picker.invalidate() -func _menu_export_option_sets_action(): +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.window_title = "EXPORT OPTION SETS" file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) - file_picker.filters[0] = "*.json" + file_picker.filters = ["*.json"] file_picker.current_file = "" - file_picker.connect("file_selected", stage, "store_option_sets", [], CONNECT_ONESHOT) + file_picker.connect("file_selected", stage, "save_option_sets", [], CONNECT_ONESHOT) file_picker.show_modal(true) file_picker.invalidate() -func _menu_clear_option_sets_action(): +func clear_option_sets_action(): confirm_action.window_title = "CLEAR OPTION SETS" confirm_action.dialog_text = "Do you want to delete all option sets?" - confirm_action.connect("confirmed", stage, "clear_option_sets", [true], CONNECT_ONESHOT) + confirm_action.connect("confirmed", stage, "clear_option_sets", [], CONNECT_ONESHOT) confirm_action.show_modal(true) -func _menu_export_data_action(): +func export_data_action(): file_picker.window_title = "EXPORT DATA" file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) - file_picker.filters[0] = "*.csv" + file_picker.filters = ["*.csv"] file_picker.current_file = "" - file_picker.connect("file_selected", database, "store_database", [], CONNECT_ONESHOT) + file_picker.connect("file_selected", database, "save_database", [], CONNECT_ONESHOT) file_picker.show_modal(true) file_picker.invalidate() -func _menu_clear_data_action(): +func clear_data_action(): confirm_action.window_title = "CLEAR DATA" confirm_action.dialog_text = "Do you want to delete all entries from the database?" - confirm_action.connect("confirmed", database, "clear_database", [true], CONNECT_ONESHOT) + confirm_action.connect("confirmed", database, "clear_database", [], CONNECT_ONESHOT) confirm_action.show_modal(true) -func _menu_about_action(): +func about_action(): confirm_action.window_title = "ABOUT" confirm_action.dialog_text = "About text here!" confirm_action.show_modal(true) # @DAM Hide this debug method before release. -func _menu_fake_db_action(): - confirm_action.window_title = "FAKE DB" +func test_fake_db_action(): + confirm_action.window_title = "TEST FAKE DB" confirm_action.dialog_text = "Do you want to delete all entries from the database and replace by fake entries?" - confirm_action.connect("confirmed", database, "fake_database", [true], CONNECT_ONESHOT) + confirm_action.connect("confirmed", database, "fake_database", [], CONNECT_ONESHOT) confirm_action.show_modal(true) |
