From cd64268a9d548f68eeb1bcf3a9ad1ccbe87567d2 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Wed, 3 Jan 2024 00:15:12 -0500 Subject: [PATCH 1/4] Adding saving functions --- Icon.gd | 6 ++++++ PackDialog.gd | 1 + Route.gd | 6 ++++++ Spatial.gd | 58 ++++++++++++++++++++++++++++++++++++++++++--------- Spatial.tscn | 16 ++++++++++++-- project.godot | 2 +- 6 files changed, 76 insertions(+), 13 deletions(-) diff --git a/Icon.gd b/Icon.gd index cc171b55..2aa7829e 100644 --- a/Icon.gd +++ b/Icon.gd @@ -6,6 +6,12 @@ var texture_path var waypoint: Waypoint.Icon var category: TreeItem +func update_waypoint_icon(): + var position = self.waypoint.position() + position.set_x(translation[0]) + position.set_y(translation[1]) + position.set_z(-translation[2]) + func set_icon_image(texture_path: String): self.texture_path = texture_path diff --git a/PackDialog.gd b/PackDialog.gd index 10b86f2e..42b9ad97 100644 --- a/PackDialog.gd +++ b/PackDialog.gd @@ -42,3 +42,4 @@ func _on_FileDialog_dir_selected(dir_path): print("Failed to execute the command. Error code:", result) else: print("Command executed successfully.") + get_node("../../..").load_waypoint_markers() diff --git a/Route.gd b/Route.gd index 24717e1e..dabbbc56 100644 --- a/Route.gd +++ b/Route.gd @@ -9,6 +9,12 @@ var category: TreeItem var point_list := PoolVector3Array() +func update_waypoint_trail(index): + var trail_data = waypoint.get_trail_data() + trail_data.get_points_x()[index] = self.point_list[index][0] + trail_data.get_points_y()[index] = self.point_list[index][1] + trail_data.get_points_z()[index] = -self.point_list[index][2] + func create_mesh(point_list: PoolVector3Array): self.point_list = point_list refresh_mesh() diff --git a/Spatial.gd b/Spatial.gd index 63d186b3..6d068262 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -59,7 +59,7 @@ const PackDialog = preload("res://PackDialog.gd") onready var markers_ui := $Control/Dialogs/CategoriesDialog/MarkersUI as Tree onready var markers_3d := $Markers3D as Spatial onready var markers_2d := $Control/Markers2D as Node2D - +onready var unsaved_data_icon := $Control/GlobalMenuButton/UnsavedDataIcon as TextureRect # Called when the node enters the scene tree for the first time. func _ready(): @@ -336,10 +336,12 @@ func decode_context_packet(spb: StreamPeerBuffer): # this to just be a radian to degree conversion. if self.map_id != old_map_id: + if unsaved_data_icon.visible: + save_current_map_data() print("New Map") print("Saving Old Map") print("Loading New Map") - load_waypoint_markers(self.map_id) + load_waypoint_markers() reset_minimap_masks() @@ -387,11 +389,12 @@ func reset_3D_minimap_masks(category: Spatial): var waypoint_data = Waypoint.Waypoint.new() -var marker_file_dir = "user://protobins/" +var split_marker_file_dir = "user://protobins/" +var marker_pack_dir = "user://packs/" var marker_file_path = "" -func load_waypoint_markers(map_id): - self.marker_file_path = self.marker_file_dir + String(map_id) + ".data" +func load_waypoint_markers(): + self.marker_file_path = self.split_marker_file_dir + String(self.map_id) + ".data" self.waypoint_data.clear_category() clear_map_markers() init_category_tree() @@ -533,6 +536,9 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category: Wayp for path in waypoint_category.get_trail(): var path_points := PoolVector3Array() var trail_data = path.get_trail_data() + if trail_data == null: + print("Warning: Trail ", category_name, " has no trail data") + continue if trail_data.get_points_x().size() != trail_data.get_points_y().size() or trail_data.get_points_x().size() != trail_data.get_points_z().size(): print("Warning: Trail ", category_name, " does not have equal number of X, Y, and Z coordinates.") for index in range(0, trail_data.get_points_z().size()): @@ -632,6 +638,33 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego var category_data = category_item.get_metadata(0) category_data.category3d.add_icon(new_icon) +################################################################################ +# Section of functions for saving changes to markers +################################################################################ +func on_change_made(): + self.unsaved_data_icon.visible = true + +func save_current_map_data(): + var packed_bytes = self.waypoint_data.to_bytes() + if packed_bytes.size() > 0: + var file = File.new() + file.open(self.marker_file_path, file.WRITE) + file.store_buffer(packed_bytes) + +func save_from_split_files(): + save_current_map_data() + for waypoint_category in self.waypoint_data.get_category(): + var output: Array = [] + var args: PoolStringArray = [ + "--input-waypoint-path", self.split_marker_file_dir, + "--output-waypoint-path", waypoint_category.get_name() + ] + var result: int = OS.execute(self.executable_path, args, true, output, true) + print(output) + if result != OK: + print("Failed to execute the command. Error code:", result) + self.unsaved_data_icon.visible = true + # This function take all of the currently rendered objects and converts it into # the data format that is saved/loaded from. func data_from_renderview(): @@ -822,16 +855,13 @@ func _on_NewPathPoint_pressed(): # ################################################################################ func _on_SavePath_pressed(): - $Control/Dialogs/SaveDialog.show() + save_from_split_files() ################################################################################ # TODO: This function will be used when exporting packs ################################################################################ func _on_SaveDialog_file_selected(path): - self.markerdata[str(self.map_id)] = data_from_renderview() - var save_game = File.new() - save_game.open(path, File.WRITE) - save_game.store_string(JSON.print(self.markerdata)) + pass func _on_NodeEditorDialog_hide(): self.currently_selected_node = null @@ -905,6 +935,8 @@ func _on_ReversePathDirection_pressed(): func _on_ExitButton_pressed(): + if unsaved_data_icon.visible: + save_current_map_data() exit_burrito() @@ -927,3 +959,9 @@ func _on_MarkersUI_item_edited(): func _on_ImportPath_pressed(): $Control/Dialogs/ImportPackDialog.show() + +func _on_UnsavedDataIcon_visibility_changed(): + if $Control/GlobalMenuButton/UnsavedDataIcon.visible: + $Control/GlobalMenuButton/main_menu_toggle.hint_tooltip = "Unsaved Data" + else: + $Control/GlobalMenuButton/main_menu_toggle.hint_tooltip = "" diff --git a/Spatial.tscn b/Spatial.tscn index a220578a..3f1202d0 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -94,6 +94,17 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="UnsavedDataIcon" type="TextureRect" parent="Control/GlobalMenuButton"] +visible = false +modulate = Color( 0.92549, 0, 0, 0.439216 ) +margin_top = 4.0 +margin_right = 25.0 +margin_bottom = 29.0 +texture = ExtResource( 3 ) +__meta__ = { +"_edit_use_anchors_": false +} + [node name="main_menu_toggle" type="Button" parent="Control/GlobalMenuButton"] modulate = Color( 1, 1, 1, 0 ) margin_left = -2.0 @@ -191,8 +202,8 @@ margin_bottom = 534.0 window_title = "Open a Directory" mode = 2 access = 2 -current_dir = "" -current_path = "" +current_dir = "/home/steph/Code/Projects/Burrito" +current_path = "/home/steph/Code/Projects/Burrito/" script = ExtResource( 14 ) __meta__ = { "_edit_use_anchors_": false @@ -879,6 +890,7 @@ color = Color( 0, 0, 0, 1 ) mesh = SubResource( 3 ) material/0 = SubResource( 4 ) +[connection signal="visibility_changed" from="Control/GlobalMenuButton/UnsavedDataIcon" to="." method="_on_UnsavedDataIcon_visibility_changed"] [connection signal="pressed" from="Control/GlobalMenuButton/main_menu_toggle" to="." method="_on_main_menu_toggle_pressed"] [connection signal="pressed" from="Control/GlobalMenuButton/EditorQuckPanel/HBoxContainer/CloseEditorQuickPanel" to="." method="_on_CloseEditorQuickPanel_pressed"] [connection signal="pressed" from="Control/GlobalMenuButton/EditorQuckPanel/HBoxContainer/ChangeTexture" to="." method="_on_ChangeTexture_pressed"] diff --git a/project.godot b/project.godot index fb41ab1c..9b68d549 100644 --- a/project.godot +++ b/project.godot @@ -9,7 +9,7 @@ config_version=4 _global_script_classes=[ { -"base": "Node", +"base": "", "class": "TacoParser", "language": "NativeScript", "path": "res://tacoparser.gdns" From be8931c03991305df0ded0616ce903e158af75ec Mon Sep 17 00:00:00 2001 From: klingbolt Date: Fri, 5 Jan 2024 00:18:59 -0500 Subject: [PATCH 2/4] Added spliting function --- PackDialog.gd | 32 +++++++++++++++++++++++++++++++- Spatial.gd | 6 +++--- Spatial.tscn | 10 ++++++---- project.godot | 2 +- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/PackDialog.gd b/PackDialog.gd index 42b9ad97..7b745826 100644 --- a/PackDialog.gd +++ b/PackDialog.gd @@ -33,7 +33,7 @@ func _on_FileDialog_dir_selected(dir_path): var args: PoolStringArray = [ "--input-taco-path", dir_path, "--output-waypoint-path", new_path, - "--output-split-waypoint-path", self.split_protobin_data_folder + "--copy-images" ] print(args) var result: int = OS.execute(self.executable_path, args, true, output, true) @@ -42,4 +42,34 @@ func _on_FileDialog_dir_selected(dir_path): print("Failed to execute the command. Error code:", result) else: print("Command executed successfully.") + split_waypoint_markers() get_node("../../..").load_waypoint_markers() + +func split_waypoint_markers(): + var input_waypoint_paths: Array = [] + var output: Array = [] + var dir = Directory.new() + if dir.open(self.protobin_data_folder) == OK: + dir.list_dir_begin(true) + var file_name = dir.get_next() + while file_name != "": + if dir.current_is_dir(): + input_waypoint_paths.append(self.protobin_data_folder.plus_file(file_name.plus_file("markers.bin"))) + file_name = dir.get_next() + print(file_name) + else: + print("An error occurred when trying to access ", self.protobin_data_folder) + return + var args: PoolStringArray = ["--input-waypoint-path"] + args.append_array(input_waypoint_paths) + args.append_array([ + "--output-split-waypoint-path", self.split_protobin_data_folder, + "--copy-images" + ]) + print(args) + var result: int = OS.execute(self.executable_path, args, true, output, true) + print(output) + if result != OK: + print("Failed to execute the command. Error code:", result) + else: + print("Command executed successfully.") diff --git a/Spatial.gd b/Spatial.gd index 6d068262..3c71496e 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -395,7 +395,7 @@ var marker_file_path = "" func load_waypoint_markers(): self.marker_file_path = self.split_marker_file_dir + String(self.map_id) + ".data" - self.waypoint_data.clear_category() + self.waypoint_data = Waypoint.Waypoint.new() clear_map_markers() init_category_tree() var file = File.new() @@ -547,7 +547,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.marker_file_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() + var full_texture_path = self.split_marker_file_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() gen_new_path(path_points, full_texture_path, path, category_item) @@ -561,7 +561,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.marker_file_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() + var full_texture_path = self.split_marker_file_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() gen_new_icon(position_vector, full_texture_path, icon, category_item) for category_child in waypoint_category.get_children(): diff --git a/Spatial.tscn b/Spatial.tscn index 3f1202d0..43324dee 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -195,10 +195,11 @@ __meta__ = { } [node name="ImportPackDialog" type="FileDialog" parent="Control/Dialogs"] -margin_left = 289.0 -margin_top = 36.0 -margin_right = 960.0 -margin_bottom = 534.0 +visible = true +margin_left = 777.0 +margin_top = 89.0 +margin_right = 1448.0 +margin_bottom = 587.0 window_title = "Open a Directory" mode = 2 access = 2 @@ -795,6 +796,7 @@ margin_bottom = 304.0 text = "Load Lutris Profile" [node name="CategoriesDialog" type="WindowDialog" parent="Control/Dialogs"] +visible = true margin_left = 280.0 margin_top = 105.0 margin_right = 751.0 diff --git a/project.godot b/project.godot index 9b68d549..fb41ab1c 100644 --- a/project.godot +++ b/project.godot @@ -9,7 +9,7 @@ config_version=4 _global_script_classes=[ { -"base": "", +"base": "Node", "class": "TacoParser", "language": "NativeScript", "path": "res://tacoparser.gdns" From 081784cf8f67e543779d12936f2a3a72c5d71d61 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Fri, 19 Jan 2024 00:08:14 -0500 Subject: [PATCH 3/4] removing unneeded code --- PackDialog.gd | 2 -- Spatial.gd | 26 -------------------------- project.godot | 2 +- 3 files changed, 1 insertion(+), 29 deletions(-) diff --git a/PackDialog.gd b/PackDialog.gd index 7b745826..e9e01425 100644 --- a/PackDialog.gd +++ b/PackDialog.gd @@ -33,7 +33,6 @@ func _on_FileDialog_dir_selected(dir_path): var args: PoolStringArray = [ "--input-taco-path", dir_path, "--output-waypoint-path", new_path, - "--copy-images" ] print(args) var result: int = OS.execute(self.executable_path, args, true, output, true) @@ -64,7 +63,6 @@ func split_waypoint_markers(): args.append_array(input_waypoint_paths) args.append_array([ "--output-split-waypoint-path", self.split_protobin_data_folder, - "--copy-images" ]) print(args) var result: int = OS.execute(self.executable_path, args, true, output, true) diff --git a/Spatial.gd b/Spatial.gd index 3c71496e..51911401 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -665,32 +665,6 @@ func save_from_split_files(): print("Failed to execute the command. Error code:", result) self.unsaved_data_icon.visible = true -# This function take all of the currently rendered objects and converts it into -# the data format that is saved/loaded from. -func data_from_renderview(): - var icons_data = [] - var paths_data = [] - - for icon in $Icons.get_children(): - icons_data.append({ - "position": [icon.translation.x, icon.translation.y, -icon.translation.z], - "texture": icon.texture_path - }) - - for path in $Paths.get_children(): - #print(path) - var points = [] - for point in range(path.get_point_count()): - var point_position:Vector3 = path.get_point_position(point) - points.append([point_position.x, point_position.y, -point_position.z]) - paths_data.append({ - "points": points, - "texture": path.texture_path - }) - - var data_out = {"icons": icons_data, "paths": paths_data} - return data_out - ################################################################################ # Adjustment and gizmo functions ################################################################################ diff --git a/project.godot b/project.godot index fb41ab1c..9b68d549 100644 --- a/project.godot +++ b/project.godot @@ -9,7 +9,7 @@ config_version=4 _global_script_classes=[ { -"base": "Node", +"base": "", "class": "TacoParser", "language": "NativeScript", "path": "res://tacoparser.gdns" From 3ffbd4d886883e8135373df2f35668765f224ae1 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Fri, 19 Jan 2024 00:11:13 -0500 Subject: [PATCH 4/4] removing filepath --- Spatial.tscn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Spatial.tscn b/Spatial.tscn index 43324dee..855bddee 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -203,8 +203,8 @@ margin_bottom = 587.0 window_title = "Open a Directory" mode = 2 access = 2 -current_dir = "/home/steph/Code/Projects/Burrito" -current_path = "/home/steph/Code/Projects/Burrito/" +current_dir = "." +current_path = "." script = ExtResource( 14 ) __meta__ = { "_edit_use_anchors_": false