From cd64268a9d548f68eeb1bcf3a9ad1ccbe87567d2 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Wed, 3 Jan 2024 00:15:12 -0500 Subject: [PATCH 1/6] 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/6] 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 6bf21cbc6114f07545aa8ec99c740ebb7a20df6e Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sat, 20 Jan 2024 09:58:39 -0500 Subject: [PATCH 3/6] Removing code that is not about saving current state --- PackDialog.gd | 33 +-------------------------------- Spatial.gd | 43 ++----------------------------------------- Spatial.tscn | 6 ++---- 3 files changed, 5 insertions(+), 77 deletions(-) diff --git a/PackDialog.gd b/PackDialog.gd index 7b745826..10b86f2e 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, - "--copy-images" + "--output-split-waypoint-path", self.split_protobin_data_folder ] print(args) var result: int = OS.execute(self.executable_path, args, true, output, true) @@ -42,34 +42,3 @@ 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 3c71496e..4c5e4ee9 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -651,46 +651,6 @@ func save_current_map_data(): 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(): - 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 ################################################################################ @@ -855,7 +815,8 @@ func _on_NewPathPoint_pressed(): # ################################################################################ func _on_SavePath_pressed(): - save_from_split_files() + #TODO: Save split files into individual files + pass ################################################################################ # TODO: This function will be used when exporting packs diff --git a/Spatial.tscn b/Spatial.tscn index 43324dee..397ab16b 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -195,7 +195,6 @@ __meta__ = { } [node name="ImportPackDialog" type="FileDialog" parent="Control/Dialogs"] -visible = true margin_left = 777.0 margin_top = 89.0 margin_right = 1448.0 @@ -203,8 +202,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 @@ -796,7 +795,6 @@ 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 From 11e071c0974e80c15800b319a6f9a7e614669f6d Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 23 Jan 2024 23:46:28 -0500 Subject: [PATCH 4/6] Addressing code review --- Gizmo/PointEdit.gd | 5 ++-- Icon.gd | 11 +++++--- PackDialog.gd | 26 +++++++++--------- Route.gd | 33 ++++++++++++++++++---- Spatial.gd | 68 ++++++++++++++++++++++------------------------ Spatial.tscn | 12 -------- 6 files changed, 82 insertions(+), 73 deletions(-) diff --git a/Gizmo/PointEdit.gd b/Gizmo/PointEdit.gd index 93ddfa5c..429c3972 100644 --- a/Gizmo/PointEdit.gd +++ b/Gizmo/PointEdit.gd @@ -3,6 +3,7 @@ extends Spatial var camera: Camera signal selected(selected_object) signal deselected(selected_object) +signal update() var last_translation var selected: bool = false @@ -49,11 +50,11 @@ func update_point(): self.object_link.set_point_position(self.object_index, self.translation) self.object_2d_link.points[self.object_index] = Vector2(self.translation.x, self.translation.z) if point_type == "icon": - self.object_link.translation = self.translation + self.object_link.set_point_position(self.translation) print("update") + emit_signal("update") self.last_translation = self.translation - ################################################################################ # Handle resizing the control nodes so that no matter how far away from the # camera they appear to be the same pixel size on-screen. Without this it will diff --git a/Icon.gd b/Icon.gd index 2aa7829e..8f3bcb6d 100644 --- a/Icon.gd +++ b/Icon.gd @@ -6,11 +6,14 @@ var texture_path var waypoint: Waypoint.Icon var category: TreeItem -func update_waypoint_icon(): +func set_point_position(point_position: Vector3): + self.translation = point_position var position = self.waypoint.position() - position.set_x(translation[0]) - position.set_y(translation[1]) - position.set_z(-translation[2]) + if position == null: + position = Waypoint.Position.new() + position.set_x(point_position[0]) + position.set_y(point_position[1]) + position.set_z(-point_position[2]) func set_icon_image(texture_path: String): self.texture_path = texture_path diff --git a/PackDialog.gd b/PackDialog.gd index 10b86f2e..f6550d44 100644 --- a/PackDialog.gd +++ b/PackDialog.gd @@ -1,39 +1,39 @@ extends Control const executable_path: String = "./xml_converter/build/xml_converter" -var protobin_data_folder: String -var split_protobin_data_folder: String +var user_marker_pack_dir: String +var user_protobin_by_map_id_dir: String var user_data_dir: String func _ready(): var dir = Directory.new() self.user_data_dir = str(OS.get_user_data_dir()) - self.protobin_data_folder = self.user_data_dir.plus_file("packs") - self.split_protobin_data_folder = self.user_data_dir.plus_file("protobins") - if not dir.dir_exists(self.protobin_data_folder): - var success = dir.make_dir(self.protobin_data_folder) + self.user_marker_pack_dir = self.user_data_dir.plus_file("marker_packs") + self.user_protobin_by_map_id_dir = self.user_data_dir.plus_file("protobin_by_map_id") + if not dir.dir_exists(self.user_marker_pack_dir): + var success = dir.make_dir(self.user_marker_pack_dir) if success != OK: - print("Error: Could not create data folder:", self.protobin_data_folder) - if not dir.dir_exists(self.split_protobin_data_folder): - var success = dir.make_dir(self.split_protobin_data_folder) + print("Error: Could not create data folder:", self.user_marker_pack_dir) + if not dir.dir_exists(self.user_protobin_by_map_id_dir): + var success = dir.make_dir(self.user_protobin_by_map_id_dir) if success != OK: - print("Error: Could not create data folder:", self.split_protobin_data_folder) + print("Error: Could not create data folder:", self.user_protobin_by_map_id_dir) func _on_FileDialog_dir_selected(dir_path): var output: Array = [] print("Selected folder:", dir_path) var dir = Directory.new() - var new_path: String = self.protobin_data_folder.plus_file(dir_path.get_file()) + var new_path: String = self.user_marker_pack_dir.plus_file(dir_path.get_file()) if not dir.dir_exists(new_path): var success = dir.make_dir(new_path) if success != OK: - print("Error: Could not create data folder:", self.protobin_data_folder) + print("Error: Could not create data folder:", self.user_marker_pack_dir) #else: # #Pop up here to confirm overwrite? var args: PoolStringArray = [ "--input-taco-path", dir_path, "--output-waypoint-path", new_path, - "--output-split-waypoint-path", self.split_protobin_data_folder + "--output-split-waypoint-path", self.user_protobin_by_map_id_dir ] print(args) var result: int = OS.execute(self.executable_path, args, true, output, true) diff --git a/Route.gd b/Route.gd index dabbbc56..9606d6ad 100644 --- a/Route.gd +++ b/Route.gd @@ -9,12 +9,6 @@ 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() @@ -76,6 +70,14 @@ func update_point_vertical(index, y_value): func reverse(): self.point_list.invert() + var trail_data = waypoint.get_trail_data() + # The default value of the TrailData class for new trails is null. + # The default for the points arrays is [] so no check is needed for those. + if trail_data == null: + trail_data = Waypoint.TrailData.new() + trail_data.get_points_x().invert() + trail_data.get_points_y().invert() + trail_data.get_points_z().invert() refresh_mesh() func get_point_count(): @@ -86,17 +88,36 @@ func get_point_position(index: int): func set_point_position(index: int, position: Vector3): self.point_list[index] = position + 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] refresh_mesh() func add_point(position: Vector3, index: int = -1): + var trail_data = waypoint.get_trail_data() + # The default value of the TrailData class for new trails is null. + # The default for the points arrays is [] so no check is needed for those. + if trail_data == null: + trail_data = Waypoint.TrailData.new() if index == -1: self.point_list.append(position) + trail_data.add_points_x(position[0]) + trail_data.add_points_y(position[1]) + trail_data.add_points_z(-position[2]) else: self.point_list.insert(index, position) + 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] refresh_mesh() func remove_point(index: int): self.point_list.remove(index) + var trail_data = waypoint.get_trail_data() + trail_data.get_points_x().remove(index) + trail_data.get_points_y().remove(index) + trail_data.get_points_z().remove(index) refresh_mesh() diff --git a/Spatial.gd b/Spatial.gd index 4c5e4ee9..e0795171 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -9,6 +9,7 @@ var map_is_open: bool var compass_is_top_right: bool var edit_panel_open: bool = false +var unsaved_changes: bool = false # This is the path to the texture that will be used for the next created 3d-path # object or icon object in the UI @@ -59,7 +60,6 @@ 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,12 +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: + if self.unsaved_changes: save_current_map_data() print("New Map") print("Saving Old Map") print("Loading New Map") - load_waypoint_markers() + load_waypoint_markers(self.map_id) reset_minimap_masks() @@ -388,13 +388,13 @@ func reset_3D_minimap_masks(category: Spatial): reset_3D_minimap_masks(subcategory) -var waypoint_data = Waypoint.Waypoint.new() -var split_marker_file_dir = "user://protobins/" -var marker_pack_dir = "user://packs/" -var marker_file_path = "" +var waypoint_data: Waypoint.Waypoint = Waypoint.Waypoint.new() +const user_protobin_by_map_id_dir: String = "user://protobin_by_map_id/" +const user_marker_pack_dir: String = "user://marker_packs/" +var marker_file_path: String = "" -func load_waypoint_markers(): - self.marker_file_path = self.split_marker_file_dir + String(self.map_id) + ".data" +func load_waypoint_markers(map_id_to_load: int): + self.marker_file_path = self.user_protobin_by_map_id_dir + String(map_id_to_load) + ".data" self.waypoint_data = Waypoint.Waypoint.new() clear_map_markers() init_category_tree() @@ -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.split_marker_file_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() + var full_texture_path = self.user_protobin_by_map_id_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.split_marker_file_dir + self.waypoint_data.get_textures()[texture_id].get_filepath() + var full_texture_path = self.user_protobin_by_map_id_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(): @@ -641,15 +641,21 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego ################################################################################ # Section of functions for saving changes to markers ################################################################################ -func on_change_made(): - self.unsaved_data_icon.visible = true +func update_burrito_icon(): + if self.unsaved_changes: + $Control/GlobalMenuButton/TextureRect.modulate = Color(.78, 0.3, 0.3, 1.0) + $Control/GlobalMenuButton/main_menu_toggle.hint_tooltip = "Unsaved Data" + else: + $Control/GlobalMenuButton/TextureRect.modulate = Color(1.0, 1.0, 1.0, 1.0) + $Control/GlobalMenuButton/main_menu_toggle.hint_tooltip = "" 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) + var file = File.new() + file.open(self.marker_file_path, file.WRITE) + file.store_buffer(packed_bytes) + self.unsaved_changes = false + update_burrito_icon() ################################################################################ # Adjustment and gizmo functions @@ -687,6 +693,7 @@ func gen_adjustment_nodes(): new_gizmo.link_point("path", route, path2d, i) new_gizmo.connect("selected", self, "on_gizmo_selected") new_gizmo.connect("deselected", self, "on_gizmo_deselected") + new_gizmo.connect("update", self, "on_update_made") $Gizmos.add_child(new_gizmo) for icon in category3d.icons: var new_gizmo = gizmo_scene.instance() @@ -694,6 +701,7 @@ func gen_adjustment_nodes(): new_gizmo.link_point("icon", icon) new_gizmo.connect("selected", self, "on_gizmo_selected") new_gizmo.connect("deselected", self, "on_gizmo_deselected") + new_gizmo.connect("update", self, "on_update_made") $Gizmos.add_child(new_gizmo) @@ -721,6 +729,9 @@ func on_gizmo_deselected(object): $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SetActivePath.disabled = true $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/ReversePathDirection.disabled = true +func on_update_made(): + self.unsaved_changes = true + update_burrito_icon() func clear_adjustment_nodes(): for child in $Gizmos.get_children(): @@ -730,6 +741,9 @@ func clear_adjustment_nodes(): ################################################################################ # Signal Functions ################################################################################ +func _on_SavePath_pressed(): + save_current_map_data() + func _on_main_menu_toggle_pressed(): $Control/Dialogs/MainMenu.show() set_maximal_mouse_block() @@ -811,19 +825,6 @@ func _on_NewPathPoint_pressed(): self.currently_active_path_2d.add_point(Vector2(self.player_position.x, -self.player_position.z)) -################################################################################ -# -################################################################################ -func _on_SavePath_pressed(): - #TODO: Save split files into individual files - pass - -################################################################################ -# TODO: This function will be used when exporting packs -################################################################################ -func _on_SaveDialog_file_selected(path): - pass - func _on_NodeEditorDialog_hide(): self.currently_selected_node = null clear_adjustment_nodes() @@ -896,7 +897,7 @@ func _on_ReversePathDirection_pressed(): func _on_ExitButton_pressed(): - if unsaved_data_icon.visible: + if self.unsaved_changes: save_current_map_data() exit_burrito() @@ -921,8 +922,3 @@ 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 397ab16b..ced08072 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -94,17 +94,6 @@ __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 @@ -890,7 +879,6 @@ 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"] From 1e65d69baaeae777771376b137200ebcf2b3a8fe Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 6 Feb 2024 00:06:33 -0500 Subject: [PATCH 5/6] Addressing code review. Moving some functions out of Gizmo. Renaming variables. --- Gizmo/PointEdit.gd | 16 ++------ Icon.gd | 2 +- PackDialog.gd | 26 ++++++------ Route.gd | 2 +- SelectedNode.gd | 7 ++++ Spatial.gd | 100 +++++++++++++++++++++++++++------------------ Spatial.tscn | 10 ++--- 7 files changed, 91 insertions(+), 72 deletions(-) create mode 100644 SelectedNode.gd diff --git a/Gizmo/PointEdit.gd b/Gizmo/PointEdit.gd index 429c3972..b076d91f 100644 --- a/Gizmo/PointEdit.gd +++ b/Gizmo/PointEdit.gd @@ -3,7 +3,7 @@ extends Spatial var camera: Camera signal selected(selected_object) signal deselected(selected_object) -signal update() +signal update(point_position) var last_translation var selected: bool = false @@ -28,11 +28,6 @@ func select(camera, event): $Pillar/CollisionShape.disabled = false emit_signal("selected", self) -var object_link = null -var object_2d_link = null -var object_index:int = 0 -var point_type: String - func link_point(point_type: String, object_link, object_2d_link = null, object_index = 0): self.point_type = point_type @@ -46,14 +41,9 @@ func link_point(point_type: String, object_link, object_2d_link = null, object_i func update_point(): if self.translation != self.last_translation: - if point_type == "path" || point_type == "area": - self.object_link.set_point_position(self.object_index, self.translation) - self.object_2d_link.points[self.object_index] = Vector2(self.translation.x, self.translation.z) - if point_type == "icon": - self.object_link.set_point_position(self.translation) print("update") - emit_signal("update") - self.last_translation = self.translation + emit_signal("update", self.translation) + self.last_translation = self.translation ################################################################################ # Handle resizing the control nodes so that no matter how far away from the diff --git a/Icon.gd b/Icon.gd index 8f3bcb6d..7841967b 100644 --- a/Icon.gd +++ b/Icon.gd @@ -8,7 +8,7 @@ var category: TreeItem func set_point_position(point_position: Vector3): self.translation = point_position - var position = self.waypoint.position() + var position = self.waypoint.get_position() if position == null: position = Waypoint.Position.new() position.set_x(point_position[0]) diff --git a/PackDialog.gd b/PackDialog.gd index f6550d44..0c0193c9 100644 --- a/PackDialog.gd +++ b/PackDialog.gd @@ -1,39 +1,39 @@ extends Control const executable_path: String = "./xml_converter/build/xml_converter" -var user_marker_pack_dir: String -var user_protobin_by_map_id_dir: String +var downloaded_markers_dir: String +var unsaved_markers_dir: String var user_data_dir: String func _ready(): var dir = Directory.new() self.user_data_dir = str(OS.get_user_data_dir()) - self.user_marker_pack_dir = self.user_data_dir.plus_file("marker_packs") - self.user_protobin_by_map_id_dir = self.user_data_dir.plus_file("protobin_by_map_id") - if not dir.dir_exists(self.user_marker_pack_dir): - var success = dir.make_dir(self.user_marker_pack_dir) + self.downloaded_markers_dir = self.user_data_dir.plus_file("marker_packs") + self.unsaved_markers_dir = self.user_data_dir.plus_file("protobin_by_map_id") + if not dir.dir_exists(self.downloaded_markers_dir): + var success = dir.make_dir(self.downloaded_markers_dir) if success != OK: - print("Error: Could not create data folder:", self.user_marker_pack_dir) - if not dir.dir_exists(self.user_protobin_by_map_id_dir): - var success = dir.make_dir(self.user_protobin_by_map_id_dir) + print("Error: Could not create data folder:", self.downloaded_markers_dir) + if not dir.dir_exists(self.unsaved_markers_dir): + var success = dir.make_dir(self.unsaved_markers_dir) if success != OK: - print("Error: Could not create data folder:", self.user_protobin_by_map_id_dir) + print("Error: Could not create data folder:", self.unsaved_markers_dir) func _on_FileDialog_dir_selected(dir_path): var output: Array = [] print("Selected folder:", dir_path) var dir = Directory.new() - var new_path: String = self.user_marker_pack_dir.plus_file(dir_path.get_file()) + var new_path: String = self.downloaded_markers_dir.plus_file(dir_path.get_file()) if not dir.dir_exists(new_path): var success = dir.make_dir(new_path) if success != OK: - print("Error: Could not create data folder:", self.user_marker_pack_dir) + print("Error: Could not create data folder:", self.downloaded_markers_dir) #else: # #Pop up here to confirm overwrite? var args: PoolStringArray = [ "--input-taco-path", dir_path, "--output-waypoint-path", new_path, - "--output-split-waypoint-path", self.user_protobin_by_map_id_dir + "--output-split-waypoint-path", self.unsaved_markers_dir ] print(args) var result: int = OS.execute(self.executable_path, args, true, output, true) diff --git a/Route.gd b/Route.gd index 9606d6ad..8a930e4d 100644 --- a/Route.gd +++ b/Route.gd @@ -86,7 +86,7 @@ func get_point_count(): func get_point_position(index: int): return self.point_list[index] -func set_point_position(index: int, position: Vector3): +func set_point_position(position: Vector3, index: int): self.point_list[index] = position var trail_data = waypoint.get_trail_data() trail_data.get_points_x()[index] = self.point_list[index][0] diff --git a/SelectedNode.gd b/SelectedNode.gd new file mode 100644 index 00000000..67d1e990 --- /dev/null +++ b/SelectedNode.gd @@ -0,0 +1,7 @@ +var point_type: String +var object_index: int = 0 + +var icon = null +var path = null +var path2d = null +var gizmo = null diff --git a/Spatial.gd b/Spatial.gd index e0795171..9cf2f9c2 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -9,7 +9,7 @@ var map_is_open: bool var compass_is_top_right: bool var edit_panel_open: bool = false -var unsaved_changes: bool = false +var unsaved_changes: bool = false setget set_unsaved_changes # This is the path to the texture that will be used for the next created 3d-path # object or icon object in the UI @@ -55,6 +55,7 @@ const gizmo_scene = preload("res://Gizmo/PointEdit.tscn") const CategoryData = preload("res://CategoryData.gd") const Waypoint = preload("res://waypoint.gd") const PackDialog = preload("res://PackDialog.gd") +const SelectedNode = preload("res://SelectedNode.gd") ##########Node Connections########### onready var markers_ui := $Control/Dialogs/CategoriesDialog/MarkersUI as Tree @@ -389,12 +390,16 @@ func reset_3D_minimap_masks(category: Spatial): var waypoint_data: Waypoint.Waypoint = Waypoint.Waypoint.new() -const user_protobin_by_map_id_dir: String = "user://protobin_by_map_id/" -const user_marker_pack_dir: String = "user://marker_packs/" +# We save the marker data in this directory where the files are have been split +# by Map ID. All changes made by the editor are saved in these files. +const unsaved_markers_dir: String = "user://protobin_by_map_id/" +# This directory contains the packs that have been downloaded or converted into +# the protobin format. Any exported changes will be saved into this folder. +const downloaded_markers_dir: String = "user://marker_packs/" var marker_file_path: String = "" func load_waypoint_markers(map_id_to_load: int): - self.marker_file_path = self.user_protobin_by_map_id_dir + String(map_id_to_load) + ".data" + self.marker_file_path = self.user_protobin_by_map_id_dir + String(map_id_to_load) + ".bin" self.waypoint_data = Waypoint.Waypoint.new() clear_map_markers() init_category_tree() @@ -641,12 +646,18 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego ################################################################################ # Section of functions for saving changes to markers ################################################################################ +func set_unsaved_changes(value): + if self.unsaved_changes != value: + self.unsaved_changes = value + update_burrito_icon() + func update_burrito_icon(): if self.unsaved_changes: - $Control/GlobalMenuButton/TextureRect.modulate = Color(.78, 0.3, 0.3, 1.0) + #TODO: Determine if this is the best color and alpha value to use + $Control/GlobalMenuButton/TextureRect.modulate = ColorN("red", 1) $Control/GlobalMenuButton/main_menu_toggle.hint_tooltip = "Unsaved Data" else: - $Control/GlobalMenuButton/TextureRect.modulate = Color(1.0, 1.0, 1.0, 1.0) + $Control/GlobalMenuButton/TextureRect.modulate = ColorN("white", 0.44) $Control/GlobalMenuButton/main_menu_toggle.hint_tooltip = "" func save_current_map_data(): @@ -654,8 +665,7 @@ func save_current_map_data(): var file = File.new() file.open(self.marker_file_path, file.WRITE) file.store_buffer(packed_bytes) - self.unsaved_changes = false - update_burrito_icon() + set_unsaved_changes(false) ################################################################################ # Adjustment and gizmo functions @@ -690,30 +700,35 @@ func gen_adjustment_nodes(): continue var new_gizmo = gizmo_scene.instance() new_gizmo.translation = gizmo_position - new_gizmo.link_point("path", route, path2d, i) - new_gizmo.connect("selected", self, "on_gizmo_selected") + new_gizmo.connect("selected", self, "on_gizmo_selected", ["path", [route, path2d, i]]) new_gizmo.connect("deselected", self, "on_gizmo_deselected") - new_gizmo.connect("update", self, "on_update_made") + new_gizmo.connect("update", self, "on_point_updated") $Gizmos.add_child(new_gizmo) for icon in category3d.icons: var new_gizmo = gizmo_scene.instance() new_gizmo.translation = icon.translation - new_gizmo.link_point("icon", icon) - new_gizmo.connect("selected", self, "on_gizmo_selected") + new_gizmo.connect("selected", self, "on_gizmo_selected", ["icon", [icon]]) new_gizmo.connect("deselected", self, "on_gizmo_deselected") - new_gizmo.connect("update", self, "on_update_made") + new_gizmo.connect("update", self, "on_point_updated") $Gizmos.add_child(new_gizmo) var currently_selected_node = null -func on_gizmo_selected(object): - self.currently_selected_node = object +func on_gizmo_selected(object, point_type: String, binds: Array): + self.currently_selected_node = SelectedNode.new() + self.currently_selected_node.gizmo = object + self.currently_selected_node.point_type = point_type $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/DeleteNode.disabled = false # Only enable these buttons if the object selected is a point on the path not an icon - if object.point_type == "path": + if point_type == "path": + self.currently_selected_node.path = binds[0] + self.currently_selected_node.path2d = binds[1] + self.currently_selected_node.object_index = binds[2] $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewNodeAfter.disabled = false $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/ReversePathDirection.disabled = false $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SetActivePath.disabled = false + if point_type == "icon": + self.currently_selected_node.icon = binds[0] $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SnapSelectedToPlayer.disabled = false $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/XZSnapToPlayer.disabled = false $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/YSnapToPlayer.disabled = false @@ -729,9 +744,14 @@ func on_gizmo_deselected(object): $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SetActivePath.disabled = true $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/ReversePathDirection.disabled = true -func on_update_made(): - self.unsaved_changes = true - update_burrito_icon() +func on_point_updated(position: Vector3): + set_unsaved_changes(true) + if self.currently_selected_node.point_type == "icon": + self.currently_selected_node.icon.set_point_position(self.currently_selected_node.gizmo.translation) + if self.currently_selected_node.point_type == "path": + var index = self.currently_selected_node.object_index + self.currently_selected_node.path.set_point_position(position, index) + self.currently_selected_node.path2d.points[index] = Vector2(position.x, position.z) func clear_adjustment_nodes(): for child in $Gizmos.get_children(): @@ -825,6 +845,7 @@ func _on_NewPathPoint_pressed(): self.currently_active_path_2d.add_point(Vector2(self.player_position.x, -self.player_position.z)) + func _on_NodeEditorDialog_hide(): self.currently_selected_node = null clear_adjustment_nodes() @@ -833,18 +854,18 @@ func _on_NodeEditorDialog_hide(): func _on_DeleteNode_pressed(): if self.currently_selected_node.point_type == "icon": - self.currently_selected_node.object_link.get_parent().remove_child(self.currently_selected_node.object_link) - self.currently_selected_node.object_link.queue_free() + self.currently_selected_node.icon.get_parent().remove_child(self.currently_selected_node.icon) + self.currently_selected_node.icon.queue_free() elif self.currently_selected_node.point_type == "path": - var path = self.currently_selected_node.object_link - var path2d = self.currently_selected_node.object_2d_link + var path = self.currently_selected_node.path + var path2d = self.currently_selected_node.path2d var index = self.currently_selected_node.object_index path.remove_point(index) path2d.remove_point(index) clear_adjustment_nodes() gen_adjustment_nodes() - on_gizmo_deselected(self.currently_selected_node) + on_gizmo_deselected(self.currently_selected_node.gizmo) func _on_NewNodeAfter_pressed(): @@ -852,8 +873,8 @@ func _on_NewNodeAfter_pressed(): print("Warning: Cannot add node to icon") elif self.currently_selected_node.point_type == "path": print("insert path node") - var path = self.currently_selected_node.object_link - var path2d = self.currently_selected_node.object_2d_link + var path = self.currently_selected_node.path + var path2d = self.currently_selected_node.path2d var index = self.currently_selected_node.object_index var start = path.get_point_position(index) @@ -868,32 +889,33 @@ func _on_NewNodeAfter_pressed(): clear_adjustment_nodes() gen_adjustment_nodes() - on_gizmo_deselected(self.currently_selected_node) + on_gizmo_deselected(self.currently_selected_node.gizmo) func _on_XZSnapToPlayer_pressed(): - self.currently_selected_node.translation.x = self.player_position.x - self.currently_selected_node.translation.z = -self.player_position.z - + self.currently_selected_node.gizmo.translation.x = self.player_position.x + self.currently_selected_node.gizmo.translation.z = -self.player_position.z + on_point_updated(self.currently_selected_node.gizmo.translation) func _on_YSnapToPlayer_pressed(): - self.currently_selected_node.translation.y = self.player_position.y - + self.currently_selected_node.gizmo.translation.y = self.player_position.y + on_point_updated(self.currently_selected_node.gizmo.translation) func _on_SnapSelectedToPlayer_pressed(): - self.currently_selected_node.translation.x = self.player_position.x - self.currently_selected_node.translation.z = -self.player_position.z - self.currently_selected_node.translation.y = self.player_position.y + self.currently_selected_node.gizmo.translation.x = self.player_position.x + self.currently_selected_node.gizmo.translation.z = -self.player_position.z + self.currently_selected_node.gizmo.translation.y = self.player_position.y + on_point_updated(self.currently_selected_node.gizmo.translation) func _on_SetActivePath_pressed(): if self.currently_selected_node.point_type == "icon": print("Warning: Cannot set icon as active path") elif self.currently_selected_node.point_type == "path": - self.currently_active_path = self.currently_selected_node.object_link - self.currently_active_path_2d = self.currently_selected_node.object_2d_link + self.currently_active_path = self.currently_selected_node.path + self.currently_active_path_2d = self.currently_selected_node.path2d func _on_ReversePathDirection_pressed(): - self.currently_selected_node.object_link.reverse() + self.currently_selected_node.path.reverse() func _on_ExitButton_pressed(): diff --git a/Spatial.tscn b/Spatial.tscn index ced08072..3b29875d 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -85,7 +85,7 @@ __meta__ = { } [node name="TextureRect" type="TextureRect" parent="Control/GlobalMenuButton"] -modulate = Color( 1, 1, 1, 0.439216 ) +modulate = Color( 1, 1, 1, 0.44 ) margin_top = 4.0 margin_right = 25.0 margin_bottom = 29.0 @@ -184,10 +184,10 @@ __meta__ = { } [node name="ImportPackDialog" type="FileDialog" parent="Control/Dialogs"] -margin_left = 777.0 -margin_top = 89.0 -margin_right = 1448.0 -margin_bottom = 587.0 +margin_left = 289.0 +margin_top = 60.0 +margin_right = 960.0 +margin_bottom = 534.0 window_title = "Open a Directory" mode = 2 access = 2 From e27380e31e14d99cf870883f90efce86e47627c8 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 6 Feb 2024 00:17:42 -0500 Subject: [PATCH 6/6] Renamed variables. Removed defunct function --- Gizmo/PointEdit.gd | 10 ---------- SelectedNode.gd | 2 +- Spatial.gd | 18 +++++++++--------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Gizmo/PointEdit.gd b/Gizmo/PointEdit.gd index b076d91f..c6cc96cc 100644 --- a/Gizmo/PointEdit.gd +++ b/Gizmo/PointEdit.gd @@ -29,16 +29,6 @@ func select(camera, event): emit_signal("selected", self) -func link_point(point_type: String, object_link, object_2d_link = null, object_index = 0): - self.point_type = point_type - self.object_link = object_link - if point_type == "path" || point_type == "area": - self.object_2d_link = object_2d_link - self.object_index = object_index - if point_type == "icon": - pass - - func update_point(): if self.translation != self.last_translation: print("update") diff --git a/SelectedNode.gd b/SelectedNode.gd index 67d1e990..376db5b2 100644 --- a/SelectedNode.gd +++ b/SelectedNode.gd @@ -1,5 +1,5 @@ var point_type: String -var object_index: int = 0 +var point_index: int = 0 var icon = null var path = null diff --git a/Spatial.gd b/Spatial.gd index 9cf2f9c2..d7e2b67a 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -700,7 +700,7 @@ func gen_adjustment_nodes(): continue var new_gizmo = gizmo_scene.instance() new_gizmo.translation = gizmo_position - new_gizmo.connect("selected", self, "on_gizmo_selected", ["path", [route, path2d, i]]) + new_gizmo.connect("selected", self, "on_gizmo_selected", ["path", [route, path2d], i]) new_gizmo.connect("deselected", self, "on_gizmo_deselected") new_gizmo.connect("update", self, "on_point_updated") $Gizmos.add_child(new_gizmo) @@ -714,21 +714,21 @@ func gen_adjustment_nodes(): var currently_selected_node = null -func on_gizmo_selected(object, point_type: String, binds: Array): +func on_gizmo_selected(object, point_type: String, nodes: Array, point_index: int): self.currently_selected_node = SelectedNode.new() self.currently_selected_node.gizmo = object self.currently_selected_node.point_type = point_type $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/DeleteNode.disabled = false # Only enable these buttons if the object selected is a point on the path not an icon if point_type == "path": - self.currently_selected_node.path = binds[0] - self.currently_selected_node.path2d = binds[1] - self.currently_selected_node.object_index = binds[2] + self.currently_selected_node.path = nodes[0] + self.currently_selected_node.path2d = nodes[1] + self.currently_selected_node.point_index = point_index $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewNodeAfter.disabled = false $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/ReversePathDirection.disabled = false $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SetActivePath.disabled = false if point_type == "icon": - self.currently_selected_node.icon = binds[0] + self.currently_selected_node.icon = nodes[0] $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SnapSelectedToPlayer.disabled = false $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/XZSnapToPlayer.disabled = false $Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/YSnapToPlayer.disabled = false @@ -749,7 +749,7 @@ func on_point_updated(position: Vector3): if self.currently_selected_node.point_type == "icon": self.currently_selected_node.icon.set_point_position(self.currently_selected_node.gizmo.translation) if self.currently_selected_node.point_type == "path": - var index = self.currently_selected_node.object_index + var index = self.currently_selected_node.point_index self.currently_selected_node.path.set_point_position(position, index) self.currently_selected_node.path2d.points[index] = Vector2(position.x, position.z) @@ -859,7 +859,7 @@ func _on_DeleteNode_pressed(): elif self.currently_selected_node.point_type == "path": var path = self.currently_selected_node.path var path2d = self.currently_selected_node.path2d - var index = self.currently_selected_node.object_index + var index = self.currently_selected_node.point_index path.remove_point(index) path2d.remove_point(index) @@ -875,7 +875,7 @@ func _on_NewNodeAfter_pressed(): print("insert path node") var path = self.currently_selected_node.path var path2d = self.currently_selected_node.path2d - var index = self.currently_selected_node.object_index + var index = self.currently_selected_node.point_index var start = path.get_point_position(index) var midpoint = self.player_position