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 = "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" onready var popup := get_popup() as PopupMenu onready var confirm_action := get_node("/root/main/confirm_action") as ConfirmationDialog onready var file_picker := get_node("/root/main/file_picker") as FileDialog onready var database := get_node("/root/main/database") as Database onready var stage := get_node("/root/main/stage") as Stage func _ready(): for idx in range(menu_items.size()): popup.add_item(menu_items[idx].label, idx) popup.connect("id_pressed", self, "id_pressed") func id_pressed(id: int): self.call_deferred(menu_items[id].action) func import_option_sets_action(): 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", [], CONNECT_ONESHOT) 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.show_modal(true) file_picker.invalidate() func clear_option_sets_action(): confirm_action.dialog_text = "Do you want to delete all option sets?" confirm_action.connect("confirmed", stage, "clear_option_sets", [], CONNECT_ONESHOT) confirm_action.show_modal(true) func export_data_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.show_modal(true) file_picker.invalidate() func clear_data_action(): confirm_action.dialog_text = "Do you want to delete all entries from the database?" confirm_action.connect("confirmed", database, "clear_database", [], CONNECT_ONESHOT) confirm_action.show_modal(true) func about_action(): confirm_action.dialog_text = "Surgery Log\nversion 2022-02-27" confirm_action.show_modal(true) # @DAM Hide this debug method before release. func test_fake_db_action(): 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", [], CONNECT_ONESHOT) confirm_action.show_modal(true)