From 2d7da6bbc23fb917dfe931eaeb5566da0a102ac3 Mon Sep 17 00:00:00 2001 From: dam Date: Sun, 10 Apr 2022 08:32:49 +0000 Subject: Code cleanup. --- logic/menu.gd | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 logic/menu.gd (limited to 'logic/menu.gd') diff --git a/logic/menu.gd b/logic/menu.gd new file mode 100644 index 0000000..d6e1501 --- /dev/null +++ b/logic/menu.gd @@ -0,0 +1,121 @@ +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 = "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" }, +] +const license_font_b612: String = "res://licenses/font_b612.txt" +const license_godot: String = "res://licenses/godot.txt" + +onready var menu := get_popup() as PopupMenu +onready var popup := get_node("/root/main/popup") as ModalPopup +onready var dialog := get_node("/root/main/dialog") as Dialog +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()): + menu.add_item(menu_items[idx].label, idx) + menu.connect("id_pressed", self, "id_pressed") + + +func id_pressed(id: int): + self.call_deferred(menu_items[id].action) + + +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") + 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) + file_picker.filters = ["*.json"] + file_picker.current_file = "" + file_picker.connect("file_selected", stage, "save_option_sets") + file_picker.show_modal(true) + file_picker.invalidate() + + +func clear_option_sets_action(): + dialog.setup("All option sets from the dropdown menus will be deleted.", "Delete all", "No") + 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") + 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", 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) + file_picker.filters = ["*.csv"] + file_picker.current_file = "" + file_picker.connect("file_selected", database, "save_database") + file_picker.show_modal(true) + file_picker.invalidate() + + +func clear_database_action(): + dialog.setup("All entries from the database will be deleted.", "Delete all", "No") + 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) + + -- cgit v1.2.3 From 4534e6c5d0981972b3174dd82c0d7ba5aadb5139 Mon Sep 17 00:00:00 2001 From: dam Date: Mon, 11 Apr 2022 15:38:12 +0000 Subject: Bumped to version 1.0. Version stored in project settings global/version. --- logic/menu.gd | 2 +- project.godot | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'logic/menu.gd') diff --git a/logic/menu.gd b/logic/menu.gd index d6e1501..caa39d1 100644 --- a/logic/menu.gd +++ b/logic/menu.gd @@ -115,7 +115,7 @@ func clear_database(): func about_action(): - dialog.setup("Surgery Log\nversion 0.1", "", "") + dialog.setup("Surgery Log\nversion %s" % ProjectSettings.get_setting("global/version"), "", "") popup.open_popup("About", dialog) diff --git a/project.godot b/project.godot index ebb4f56..b71ddf9 100644 --- a/project.godot +++ b/project.godot @@ -104,6 +104,10 @@ window/size/test_height=1024 window/energy_saving/keep_screen_on=false window/handheld/orientation="portrait" +[global] + +version="1.0" + [input_devices] pointing/emulate_touch_from_mouse=true -- cgit v1.2.3 From be7097c8fab45457c703a28aae44509e21e1cf2a Mon Sep 17 00:00:00 2001 From: dam Date: Sat, 16 Apr 2022 23:42:21 +0000 Subject: Allow user to export error log to file. --- logic/menu.gd | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'logic/menu.gd') diff --git a/logic/menu.gd b/logic/menu.gd index caa39d1..42b88d5 100644 --- a/logic/menu.gd +++ b/logic/menu.gd @@ -1,5 +1,6 @@ extends MenuButton +const LOGS_FILE_PATH: String = "user://logs/godot.log" const menu_items: Array = [ { label = "Import Option Sets", action = "import_option_sets_action" }, { label = "Export Option Sets", action = "export_option_sets_action" }, @@ -7,6 +8,7 @@ const menu_items: Array = [ { label = "Import Database", action = "import_database_action" }, { label = "Export Database", action = "export_database_action" }, { label = "Clear Database", action = "clear_database_action" }, + { label = "Export Log", action = "export_log_action" }, { label = "About", action = "about_action" }, ] const license_font_b612: String = "res://licenses/font_b612.txt" @@ -114,6 +116,35 @@ func clear_database(): database.save_database() +func export_log_action(): + file_picker.mode = FileDialog.MODE_SAVE_FILE + file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) + file_picker.filters = ["*.log"] + file_picker.current_file = "" + file_picker.connect("file_selected", self, "export_log") + file_picker.show_modal(true) + file_picker.invalidate() + + +func export_log(file_path: String): + var error : int + var file := File.new() + + error = file.open(LOGS_FILE_PATH, File.READ) + if error != OK: + printerr("Failed to open log file '%s' (error %d)." % [LOGS_FILE_PATH, error]) + return + var file_content = file.get_as_text() + file.close() + + error = file.open(file_path, File.WRITE) + if error != OK: + printerr("Failed to open file '%s' to write log (error %d)." % [file_path, error]) + return + file.store_string(file_content) + file.close() + + func about_action(): dialog.setup("Surgery Log\nversion %s" % ProjectSettings.get_setting("global/version"), "", "") popup.open_popup("About", dialog) -- cgit v1.2.3 From ee31a9a3d387121030a5f4503adeac5816d7726f Mon Sep 17 00:00:00 2001 From: dam Date: Sun, 17 Apr 2022 10:04:21 +0000 Subject: Renamed app log export action. --- logic/menu.gd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'logic/menu.gd') diff --git a/logic/menu.gd b/logic/menu.gd index 42b88d5..4b0b7b3 100644 --- a/logic/menu.gd +++ b/logic/menu.gd @@ -8,7 +8,7 @@ const menu_items: Array = [ { label = "Import Database", action = "import_database_action" }, { label = "Export Database", action = "export_database_action" }, { label = "Clear Database", action = "clear_database_action" }, - { label = "Export Log", action = "export_log_action" }, + { label = "Export App Log", action = "export_app_log_action" }, { label = "About", action = "about_action" }, ] const license_font_b612: String = "res://licenses/font_b612.txt" @@ -116,17 +116,17 @@ func clear_database(): database.save_database() -func export_log_action(): +func export_app_log_action(): file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters = ["*.log"] file_picker.current_file = "" - file_picker.connect("file_selected", self, "export_log") + file_picker.connect("file_selected", self, "export_app_log") file_picker.show_modal(true) file_picker.invalidate() -func export_log(file_path: String): +func export_app_log(file_path: String): var error : int var file := File.new() -- cgit v1.2.3