From 6c0034414d8f19b4b5aa73687ebfe52b576e91b6 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 23 Jul 2024 21:31:24 -0400 Subject: [PATCH] Moved data dir variables to settings file --- ImportPackDialog.gd | 14 +++----------- Settings.gd | 30 ++++++++++++++++++++++++++++-- Spatial.gd | 24 +++++++++++++----------- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/ImportPackDialog.gd b/ImportPackDialog.gd index 3db05f00..cee02eb7 100644 --- a/ImportPackDialog.gd +++ b/ImportPackDialog.gd @@ -1,25 +1,17 @@ extends FileDialog const FileHandler = preload("res://FileHandler.gd") -var downloaded_markers_dir: String -var unsaved_markers_dir: String -var user_data_dir: String func _ready(): - #TODO: Move these to global file Settings so they can be customized - self.user_data_dir = str(OS.get_user_data_dir()) - self.downloaded_markers_dir = self.user_data_dir.plus_file("packs") - self.unsaved_markers_dir = self.user_data_dir.plus_file("protobins") - FileHandler.create_directory_if_missing(self.downloaded_markers_dir) - FileHandler.create_directory_if_missing(self.unsaved_markers_dir) + pass func _on_FileDialog_dir_selected(dir_path: String): print("Selected folder:", dir_path) - var new_path: String = self.downloaded_markers_dir.plus_file(dir_path.get_file()) + var new_path: String = Settings.downloaded_markers_dir.plus_file(dir_path.get_file()) FileHandler.create_directory_if_missing(new_path) var args: PoolStringArray = [ "--input-taco-path", dir_path, "--output-waypoint-path", new_path, - "--output-split-waypoint-path", self.unsaved_markers_dir + "--output-split-waypoint-path", Settings.unsaved_markers_dir ] FileHandler.call_xml_converter(args) diff --git a/Settings.gd b/Settings.gd index 2af0fb9b..1fbad94c 100644 --- a/Settings.gd +++ b/Settings.gd @@ -1,6 +1,7 @@ extends Node const CONFIG_PATH = "user://settings.json" +const FileHandler = preload("res://FileHandler.gd") var _config_data = {} var local_category_data = {} @@ -17,12 +18,24 @@ var burrito_link_wine_path: String = "" var burrito_link_env_args: String = "" +var user_data_dir: String +var downloaded_markers_dir: String +#We save the marker data in this directory when the files are have been split +#by Map ID. All changes made by the editor are automatically saved in these +#files prior to export. +var unsaved_markers_dir: String + +var unsaved_changes: bool = false + func _ready(): var file = File.new() file.open(CONFIG_PATH, file.READ) var text = file.get_as_text() var datum = JSON.parse(text) self._config_data = JSON.parse(text).result + self.user_data_dir = str(OS.get_user_data_dir()) + self.downloaded_markers_dir = self.user_data_dir.plus_file("packs") + self.unsaved_markers_dir = self.user_data_dir.plus_file("protobin_by_map_id") if self._config_data == null: self._config_data = {} @@ -45,7 +58,16 @@ func _ready(): self.burrito_link_wine_path = self._config_data["burrito_link_wine_path"] if "burrito_link_env_args" in self._config_data: self.burrito_link_env_args = self._config_data["burrito_link_env_args"] - + if "user_data_dir" in self._config_data: + self.user_data_dir = self._config_data["user_data_dir"] + if "downloaded_markers_dir" in self._config_data: + self.downloaded_markers_dir = self._config_data["downloaded_markers_dir"] + if "unsaved_markers_dir" in self._config_data: + self.unsaved_markers_dir = self._config_data["unsaved_markers_dir"] + if "unsaved_changes" in self._config_data: + self.unsaved_changes = self._config_data["unsaved_changes"] + FileHandler.create_directory_if_missing(self.downloaded_markers_dir) + FileHandler.create_directory_if_missing(self.unsaved_markers_dir) func save(): _config_data = { @@ -57,7 +79,11 @@ func save(): "burrito_link_auto_launch_enabled": burrito_link_auto_launch_enabled, "burrito_link_wine_path": burrito_link_wine_path, "burrito_link_env_args": burrito_link_env_args, - "local_category_data": local_category_data + "local_category_data": local_category_data, + #"user_data_dir" : user_data_dir, + #"downloaded_markers_dir": downloaded_markers_dir, + #"unsaved_markers_dir": unsaved_markers_dir, + "unsaved_changes": unsaved_changes } var file = File.new() diff --git a/Spatial.gd b/Spatial.gd index a3479d0d..eb206b96 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -82,6 +82,8 @@ func _ready(): # Postion at top left corner OS.set_window_position(Vector2(0,0)) set_minimal_mouse_block() + if Settings.unsaved_changes: + set_unsaved_changes(Settings.unsaved_changes) server.listen(4242) @@ -390,14 +392,11 @@ func reset_3D_minimap_masks(category: Spatial): var waypoint_data = Waypoint.Waypoint.new() -#We save the marker data in this directory when the files are have been split -#by Map ID. All changes made by the editor are automatically saved in these -#files prior to export. -var unsaved_markers_dir = "user://protobins/" +# Filepath for the current map var marker_file_path = "" func load_waypoint_markers(map_id_to_load: int): - self.marker_file_path = self.unsaved_markers_dir + String(map_id_to_load) + ".bin" + self.marker_file_path = Settings.unsaved_markers_dir.plus_file(String(map_id_to_load) + ".bin") self.waypoint_data = Waypoint.Waypoint.new() clear_map_markers() init_category_tree() @@ -541,7 +540,7 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category: Wayp if texture_id == null: print("Warning: No texture found in " , category_name) continue - var full_texture_path = self.unsaved_markers_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() + var full_texture_path = Settings.unsaved_markers_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() gen_new_trail(full_texture_path, trail, category_item) @@ -550,7 +549,7 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category: Wayp if texture_id == null: print("Warning: No texture found in " , category_name) continue - var full_texture_path = self.unsaved_markers_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() + var full_texture_path = Settings.unsaved_markers_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() gen_new_icon(full_texture_path, icon, category_item) for category_child in waypoint_category.get_children(): @@ -631,6 +630,8 @@ func gen_new_icon(texture_path: String, waypoint_icon: Waypoint.Icon, category_i func set_unsaved_changes(value): if self.unsaved_changes != value: unsaved_changes = value + Settings.unsaved_changes = self.unsaved_changes + Settings.save() update_burrito_icon() func update_burrito_icon(): @@ -647,7 +648,7 @@ func save_current_map_data(): var file = File.new() file.open(self.marker_file_path, file.WRITE) file.store_buffer(packed_bytes) - set_unsaved_changes(false) + ################################################################################ @@ -767,7 +768,7 @@ func set_icon_position(new_position: Vector3, waypoint_icon: Waypoint.Icon, icon position.set_y(new_position.y) position.set_z(new_position.z) icon.set_position(new_position) - set_unsaved_changes(true) + Settings.set_unsaved_changes(true) func remove_icon(waypoint_icon: Waypoint.Icon, icon: Sprite3D): if icon.waypoint != waypoint_icon: @@ -853,11 +854,11 @@ func new_trail_point_after(waypoint_trail: Waypoint.Trail, trail3d: Spatial, tra func refresh_trail3d_points(trail3d: Spatial): trail3d.refresh_mesh() - set_unsaved_changes(true) + Settings.set_unsaved_changes(true) func refresh_trail2d_points(trail2d: Line2D): trail2d.refresh_points() - set_unsaved_changes(true) + Settings.set_unsaved_changes(true) ################################################################################ @@ -865,6 +866,7 @@ func refresh_trail2d_points(trail2d: Line2D): ################################################################################ func _on_SaveTrail_pressed(): save_current_map_data() + Settings.set_unsaved_changes(false) func _on_main_menu_toggle_pressed(): $Control/Dialogs/MainMenu.show()