From 87dec589e582301cd58b91f6acdcabe7c029959c Mon Sep 17 00:00:00 2001 From: klingbolt Date: Thu, 24 Aug 2023 22:24:24 -0400 Subject: [PATCH 1/7] Reworked to read data from PR #152 --- Spatial.gd | 140 ++++++++++++++++++----------------------------------- 1 file changed, 46 insertions(+), 94 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 60c48d98..981cec92 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -287,16 +287,23 @@ func reset_minimap_masks(): var markerdata = Waypoint.Waypoint.new() var marker_file_dir = "user://protobins/" var marker_file_path = "" -var marker_packs_array = Array() +var root: TreeItem + +##########Node Connections########### onready var marker_packs = $Control/Dialogs/MarkerPacks/MarkerPacks +onready var icons = $Icons +onready var paths = $Paths +onready var minimap = $Control/MiniMap + func load_waypoint_markers(map_id): - self.marker_file_path = self.marker_file_dir + String(map_id) + ".data" - print("Loading protobuf file from path ", self.marker_file_path) - self.markerdata.clear_category() - self.markerdata.clear_icon() - self.markerdata.clear_trail() + self.marker_file_path = self.marker_file_dir.get_current_dir() + String(map_id) + ".data" + self.Waypoint_data.clear_category() + clear_map_markers() + root.free() + init_category_tree() var file = File.new() + print("Loading protobuf file from path ", self.marker_file_path) file.open(self.marker_file_path, file.READ) var data = file.get_buffer(file.get_len()) self.markerdata.from_bytes(data) @@ -382,11 +389,7 @@ func _unhandled_input(event): ################################################################################ # ################################################################################ -onready var icons = $Icons -onready var paths = $Paths -onready var minimap = $Control/MiniMap - -func gen_map_markers(): +func clear_map_markers(): # Clear all the rendered assets to make way for the new ones for path in paths.get_children(): path.queue_free() @@ -397,56 +400,6 @@ func gen_map_markers(): for icon in icons.get_children(): icon.queue_free() - self.marker_packs.clear() - build_category_tree() - - # Load the data from the markers - for path in self.markerdata.get_trail(): - var path_points := PoolVector3Array() - var trail_data = path.get_trail_data() - 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 ", path.get_category.get_name(), " does not have equal number of X, Y, and Z coordinates.") - for index in range(0, trail_data.get_points_z().size()): - path_points.append(Vector3(trail_data.get_points_x()[index], trail_data.get_points_y()[index], trail_data.get_points_z()[index])) - var texture_path = path.get_texture_path() - if texture_path == null: - print("Warning: No texture found in " , path.get_category().name()) - continue - var full_texture_path = self.marker_file_dir + texture_path.get_path() - #TODO This tree look up is unnescary if we make path a child of Category in protobuf - var split_name = path.get_category().get_name().split(".") - var category_item = search_category_tree(split_name, self.marker_packs.get_root()) - gen_new_path(path_points, full_texture_path, path, category_item) - for icon in self.markerdata.get_icon(): - var position = icon.get_position() - if position == null: - print("Warning: No position found for icon ", icon.get_category().name()) - continue - var position_vector = Vector3(position.get_x(), position.get_y(), position.get_z()) - var texture_path = icon.get_texture_path() - if texture_path == null: - print("Warning: No texture found in " , icon.get_category().name()) - continue - var full_texture_path = self.marker_file_dir + texture_path.get_path() - #TODO This tree look up is unnescary if we make path a child of Category in protobuf - var split_name = icon.get_category().get_name().split(".") - var category_item = search_category_tree(split_name, self.marker_packs.get_root()) - gen_new_icon(position_vector, full_texture_path, icon, category_item) - - -func search_category_tree(split_name: PoolStringArray, category_item: TreeItem, index: int = 0): - if index == split_name.size(): - return category_item - var child_item = category_item.get_children() - while child_item != null: - var joined_name = "" - for i in range(index): - joined_name += split_name[i] - if child_item.get_metadata(0) == joined_name: - return search_category_tree(split_name, child_item, index + 1) - child_item = child_item.get_next() - print("No category found for ", split_name) - return null func build_category_tree(): var root = self.marker_packs.create_item() @@ -474,6 +427,34 @@ func add_category(item: TreeItem, category, full_category_name: String, collapse category_item.set_tooltip(1, "Show/Hide") category_item.set_editable(1, true) category_item.set_collapsed(collapsed) + + for path in category.get_trail(): + var path_points := PoolVector3Array() + var trail_data = path.get_trail_data() + 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 ", full_category_name, " does not have equal number of X, Y, and Z coordinates.") + for index in range(0, trail_data.get_points_z().size()): + path_points.append(Vector3(trail_data.get_points_x()[index], trail_data.get_points_y()[index], trail_data.get_points_z()[index])) + var texture_path = path.get_texture_path() + if texture_path == null: + print("Warning: No texture found in " , full_category_name) + continue + var full_texture_path = self.marker_file_dir.get_current_dir() + texture_path.get_path() + gen_new_path(path_points, full_texture_path, path, category_item) + + for icon in category.get_icon(): + var position = icon.get_position() + if position == null: + print("Warning: No position found for icon ", full_category_name) + continue + var position_vector = Vector3(position.get_x(), position.get_y(), position.get_z()) + var texture_path = icon.get_texture_path() + if texture_path == null: + print("Warning: No texture found in " , full_category_name) + continue + var full_texture_path = self.marker_file_dir.get_current_dir() + texture_path.get_path() + gen_new_icon(position_vector, full_texture_path, icon, category_item) + for category_child in category.get_children(): add_category(category_item, category_child, full_category_name + "." + category_child.get_name(), true) @@ -586,32 +567,6 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego new_icon.visible = false icons.add_child(new_icon) -# 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 - func _on_main_menu_toggle_pressed(): $Control/Dialogs/MainMenu.show() set_maximal_mouse_block() @@ -619,6 +574,7 @@ func _on_main_menu_toggle_pressed(): func _on_FileDialog_file_selected(path): pass + ################################################################################ # The adjust nodes button creates handles at all the node points to allow for # editing of them via in-game interface. (Nodes can only be edited if the input @@ -775,17 +731,15 @@ func _on_NewPathPoint_pressed(): # _on_SaveDialog_file_selected() will be called with the user specified path. ################################################################################ func _on_SavePath_pressed(): - $Control/Dialogs/SaveDialog.show() + #TODO: Save to Waypoint + pass ################################################################################ # Save the current markers to a file, this includes all markers in memory not # just the markers on the current map. ################################################################################ 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(): @@ -877,5 +831,3 @@ func _on_MarkerPacks_cell_selected(): func _on_MarkerPacks_item_edited(): var category_item = self.marker_packs.get_edited() apply_category_visibility_to_nodes(category_item) - - From 6608991ba30f709d5f1ac5cebfca47279f608b8e Mon Sep 17 00:00:00 2001 From: klingbolt Date: Thu, 24 Aug 2023 22:56:47 -0400 Subject: [PATCH 2/7] Cleaning up from split in PRs --- Spatial.gd | 55 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 981cec92..c73946b3 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -257,7 +257,6 @@ func decode_context_packet(spb: StreamPeerBuffer): if self.map_id != old_map_id: print("Loading New Map") load_waypoint_markers(self.map_id) - gen_map_markers() # TODO move this to reset_minimap_masks for child in $Paths.get_children(): @@ -284,7 +283,7 @@ func reset_minimap_masks(): minimap_path.material.set_shader_param("minimap_corner", compass_corner1) minimap_path.material.set_shader_param("minimap_corner2", compass_corner2) -var markerdata = Waypoint.Waypoint.new() +var Waypoint_data = Waypoint.Waypoint.new() var marker_file_dir = "user://protobins/" var marker_file_path = "" var root: TreeItem @@ -306,12 +305,12 @@ func load_waypoint_markers(map_id): print("Loading protobuf file from path ", self.marker_file_path) file.open(self.marker_file_path, file.READ) var data = file.get_buffer(file.get_len()) - self.markerdata.from_bytes(data) + self.Waypoint_data.from_bytes(data) if !Waypoint.PB_ERR.NO_ERRORS: print("OK") else: print(Waypoint.PB_ERR) - + parse_Waypoint() var route_scene = load("res://Route.tscn") var icon_scene = load("res://Icon.tscn") @@ -401,18 +400,19 @@ func clear_map_markers(): icon.queue_free() -func build_category_tree(): - var root = self.marker_packs.create_item() +func init_category_tree(): + self.root = self.marker_packs.create_item() root.set_text(0, "Markers available on current map") root.set_selectable(0, false) root.set_text(1, "Visible") - - for category in self.markerdata.get_category(): - self.marker_packs_array.append(category.get_name()) - add_category(root, category, category.get_name(), false) -func add_category(item: TreeItem, category, full_category_name: String, collapsed: bool): +func parse_Waypoint(): + for category in self.Waypoint_data.get_category(): + parse_category(root, category, category.get_name(), false) + + +func parse_category(item: TreeItem, category, full_category_name: String, collapsed: bool): var category_item = self.marker_packs.create_item(item) if category.get_name() == "": # If this is called, there is an error in the Waypoint data @@ -456,7 +456,7 @@ func add_category(item: TreeItem, category, full_category_name: String, collapse gen_new_icon(position_vector, full_texture_path, icon, category_item) for category_child in category.get_children(): - add_category(category_item, category_child, full_category_name + "." + category_child.get_name(), true) + parse_category(category_item, category_child, full_category_name + "." + category_child.get_name(), true) func apply_category_visibility_to_nodes(category_item: TreeItem): @@ -505,7 +505,6 @@ func is_category_visible(category_item: TreeItem) -> bool: func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_item: TreeItem): - # Create the texture to use from an image file # TODO: We want to be able to cache this data so that if a texture is used # by multiple objects we only need to keep ony copy of it in memory. #22. @@ -552,9 +551,6 @@ func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_ minimap.add_child(new_2d_path) -################################################################################ -# -################################################################################ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, category_item: TreeItem): position.z = -position.z var new_icon = icon_scene.instance() @@ -567,14 +563,10 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego new_icon.visible = false icons.add_child(new_icon) -func _on_main_menu_toggle_pressed(): - $Control/Dialogs/MainMenu.show() - set_maximal_mouse_block() - -func _on_FileDialog_file_selected(path): - pass +################################################################################ +# Adjustment and gizmo functions ################################################################################ # The adjust nodes button creates handles at all the node points to allow for # editing of them via in-game interface. (Nodes can only be edited if the input @@ -588,6 +580,10 @@ func _on_AdjustNodesButton_pressed(): func gen_adjustment_nodes(): + if self.currently_active_category == null: + print("No category selected") + return + for index in range(self.paths.get_child_count()): var route = self.paths.get_child(index) var path2d = self.minimap.get_child(index) @@ -648,6 +644,15 @@ func clear_adjustment_nodes(): $Gizmos.remove_child(child) child.queue_free() +################################################################################ +# Signal Functions +################################################################################ +func _on_main_menu_toggle_pressed(): + $Control/Dialogs/MainMenu.show() + set_maximal_mouse_block() + +func _on_FileDialog_file_selected(path): + pass func _on_Dialog_hide(): for dialog in $Control/Dialogs.get_children(): @@ -727,16 +732,14 @@ func _on_NewPathPoint_pressed(): ################################################################################ -# open the save dialog window. When a path is selected -# _on_SaveDialog_file_selected() will be called with the user specified path. +# ################################################################################ func _on_SavePath_pressed(): #TODO: Save to Waypoint pass ################################################################################ -# Save the current markers to a file, this includes all markers in memory not -# just the markers on the current map. +# TODO: This function will be used when exporting packs ################################################################################ func _on_SaveDialog_file_selected(path): pass From 419f1568cdcf0eec2b2605413623b23d614397f5 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sun, 27 Aug 2023 13:41:52 -0400 Subject: [PATCH 3/7] Needed to add lines for initializing some variables --- Spatial.gd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Spatial.gd b/Spatial.gd index c73946b3..00e48000 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -60,6 +60,8 @@ func _ready(): # Postion at top left corner OS.set_window_position(Vector2(0,0)) set_minimal_mouse_block() + init_category_tree() + marker_file_dir.open("user://protobins/") server.listen(4242) func set_minimal_mouse_block(): From 10aa509c7bfbc4a5be849e16ce9cd01bd15e737d Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sun, 27 Aug 2023 13:43:49 -0400 Subject: [PATCH 4/7] Regenerated gdscript for proto --- Spatial.gd | 2 +- waypoint.gd | 146 ++++++++++++++++++++++++---------------------------- 2 files changed, 67 insertions(+), 81 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 00e48000..0ab2d1d7 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -286,7 +286,7 @@ func reset_minimap_masks(): minimap_path.material.set_shader_param("minimap_corner2", compass_corner2) var Waypoint_data = Waypoint.Waypoint.new() -var marker_file_dir = "user://protobins/" +var marker_file_dir = Directory.new() var marker_file_path = "" var root: TreeItem diff --git a/waypoint.gd b/waypoint.gd index 0e9da02b..9af1a9f5 100644 --- a/waypoint.gd +++ b/waypoint.gd @@ -670,18 +670,6 @@ class Waypoint: service.func_ref = funcref(self, "add_category") data[_category.tag] = service - _icon = PBField.new("icon", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 2, true, []) - service = PBServiceField.new() - service.field = _icon - service.func_ref = funcref(self, "add_icon") - data[_icon.tag] = service - - _trail = PBField.new("trail", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 3, true, []) - service = PBServiceField.new() - service.field = _trail - service.func_ref = funcref(self, "add_trail") - data[_trail.tag] = service - var data = {} var _category: PBField @@ -695,28 +683,6 @@ class Waypoint: _category.value.append(element) return element - var _icon: PBField - func get_icon() -> Array: - return _icon.value - func clear_icon() -> void: - data[2].state = PB_SERVICE_STATE.UNFILLED - _icon.value = [] - func add_icon() -> Icon: - var element = Icon.new() - _icon.value.append(element) - return element - - var _trail: PBField - func get_trail() -> Array: - return _trail.value - func clear_trail() -> void: - data[3].state = PB_SERVICE_STATE.UNFILLED - _trail.value = [] - func add_trail() -> Trail: - var element = Trail.new() - _trail.value.append(element) - return element - func to_string() -> String: return PBPacker.message_to_string(data) @@ -773,6 +739,18 @@ class Category: service.func_ref = funcref(self, "add_children") data[_children.tag] = service + _icon = PBField.new("icon", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 7, true, []) + service = PBServiceField.new() + service.field = _icon + service.func_ref = funcref(self, "add_icon") + data[_icon.tag] = service + + _trail = PBField.new("trail", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 8, true, []) + service = PBServiceField.new() + service.field = _trail + service.func_ref = funcref(self, "add_trail") + data[_trail.tag] = service + var data = {} var _default_visibility: PBField @@ -831,6 +809,28 @@ class Category: _children.value.append(element) return element + var _icon: PBField + func get_icon() -> Array: + return _icon.value + func clear_icon() -> void: + data[7].state = PB_SERVICE_STATE.UNFILLED + _icon.value = [] + func add_icon() -> Icon: + var element = Icon.new() + _icon.value.append(element) + return element + + var _trail: PBField + func get_trail() -> Array: + return _trail.value + func clear_trail() -> void: + data[8].state = PB_SERVICE_STATE.UNFILLED + _trail.value = [] + func add_trail() -> Trail: + var element = Trail.new() + _trail.value.append(element) + return element + func to_string() -> String: return PBPacker.message_to_string(data) @@ -856,12 +856,6 @@ class Icon: func _init(): var service - _category = PBField.new("category", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 1, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) - service = PBServiceField.new() - service.field = _category - service.func_ref = funcref(self, "new_category") - data[_category.tag] = service - _texture_path = PBField.new("texture_path", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 2, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) service = PBServiceField.new() service.field = _texture_path @@ -1034,18 +1028,14 @@ class Icon: service.field = _bhdraft__schedule_duration data[_bhdraft__schedule_duration.tag] = service + _category = PBField.new("category", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 2054, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) + service = PBServiceField.new() + service.field = _category + service.func_ref = funcref(self, "new_category") + data[_category.tag] = service + var data = {} - var _category: PBField - func get_category() -> Category: - return _category.value - func clear_category() -> void: - data[1].state = PB_SERVICE_STATE.UNFILLED - _category.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE] - func new_category() -> Category: - _category.value = Category.new() - return _category.value - var _texture_path: PBField func get_texture_path() -> TexturePath: return _texture_path.value @@ -1346,6 +1336,16 @@ class Icon: func set_bhdraft__schedule_duration(value : float) -> void: _bhdraft__schedule_duration.value = value + var _category: PBField + func get_category() -> Category: + return _category.value + func clear_category() -> void: + data[2054].state = PB_SERVICE_STATE.UNFILLED + _category.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE] + func new_category() -> Category: + _category.value = Category.new() + return _category.value + func to_string() -> String: return PBPacker.message_to_string(data) @@ -1371,12 +1371,6 @@ class Trail: func _init(): var service - _category = PBField.new("category", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 1, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) - service = PBServiceField.new() - service.field = _category - service.func_ref = funcref(self, "new_category") - data[_category.tag] = service - _texture_path = PBField.new("texture_path", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 2, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) service = PBServiceField.new() service.field = _texture_path @@ -1517,18 +1511,14 @@ class Trail: service.field = _bhdraft__schedule_duration data[_bhdraft__schedule_duration.tag] = service + _category = PBField.new("category", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 2054, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) + service = PBServiceField.new() + service.field = _category + service.func_ref = funcref(self, "new_category") + data[_category.tag] = service + var data = {} - var _category: PBField - func get_category() -> Category: - return _category.value - func clear_category() -> void: - data[1].state = PB_SERVICE_STATE.UNFILLED - _category.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE] - func new_category() -> Category: - _category.value = Category.new() - return _category.value - var _texture_path: PBField func get_texture_path() -> TexturePath: return _texture_path.value @@ -1773,6 +1763,16 @@ class Trail: func set_bhdraft__schedule_duration(value : float) -> void: _bhdraft__schedule_duration.value = value + var _category: PBField + func get_category() -> Category: + return _category.value + func clear_category() -> void: + data[2054].state = PB_SERVICE_STATE.UNFILLED + _category.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE] + func new_category() -> Category: + _category.value = Category.new() + return _category.value + func to_string() -> String: return PBPacker.message_to_string(data) @@ -4260,11 +4260,6 @@ class TrailData: func _init(): var service - _trail_data = PBField.new("trail_data", PB_DATA_TYPE.STRING, PB_RULE.OPTIONAL, 1, true, DEFAULT_VALUES_3[PB_DATA_TYPE.STRING]) - service = PBServiceField.new() - service.field = _trail_data - data[_trail_data.tag] = service - _points_x = PBField.new("points_x", PB_DATA_TYPE.FLOAT, PB_RULE.REPEATED, 2, true, []) service = PBServiceField.new() service.field = _points_x @@ -4282,15 +4277,6 @@ class TrailData: var data = {} - var _trail_data: PBField - func get_trail_data() -> String: - return _trail_data.value - func clear_trail_data() -> void: - data[1].state = PB_SERVICE_STATE.UNFILLED - _trail_data.value = DEFAULT_VALUES_3[PB_DATA_TYPE.STRING] - func set_trail_data(value : String) -> void: - _trail_data.value = value - var _points_x: PBField func get_points_x() -> Array: return _points_x.value From 760d9e0a54a4e8b62d317b3506aa8e7d3b833390 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sat, 7 Oct 2023 13:09:30 -0400 Subject: [PATCH 5/7] Addressing code review --- Spatial.gd | 89 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 0ab2d1d7..92b6d773 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -48,6 +48,20 @@ var taco_parser: TacoParser var x11_window_id_burrito: int var is_transient:bool = false +# Scenes used throughout this scene +var route_scene = load("res://Route.tscn") +var icon_scene = load("res://Icon.tscn") +var path2d_scene = load("res://Route2D.tscn") +var gizmo_scene = load("res://Gizmo/PointEdit.tscn") + +##########Node Connections########### +onready var marker_packs := $Control/Dialogs/MarkerPacks/MarkerPacks as Tree +onready var root := self.marker_packs.create_item() as TreeItem +onready var icons := $Icons as Spatial +onready var paths := $Paths as Spatial +onready var minimap := $Control/MiniMap as Node2D + + # Called when the node enters the scene tree for the first time. func _ready(): get_tree().get_root().set_transparent_background(true) @@ -60,8 +74,7 @@ func _ready(): # Postion at top left corner OS.set_window_position(Vector2(0,0)) set_minimal_mouse_block() - init_category_tree() - marker_file_dir.open("user://protobins/") + server.listen(4242) func set_minimal_mouse_block(): @@ -285,39 +298,26 @@ func reset_minimap_masks(): minimap_path.material.set_shader_param("minimap_corner", compass_corner1) minimap_path.material.set_shader_param("minimap_corner2", compass_corner2) -var Waypoint_data = Waypoint.Waypoint.new() -var marker_file_dir = Directory.new() +var waypoint_data = Waypoint.Waypoint.new() +var marker_file_dir = "user://protobins/" var marker_file_path = "" -var root: TreeItem - -##########Node Connections########### -onready var marker_packs = $Control/Dialogs/MarkerPacks/MarkerPacks -onready var icons = $Icons -onready var paths = $Paths -onready var minimap = $Control/MiniMap - func load_waypoint_markers(map_id): - self.marker_file_path = self.marker_file_dir.get_current_dir() + String(map_id) + ".data" - self.Waypoint_data.clear_category() + self.marker_file_path = self.marker_file_dir + String(map_id) + ".data" + self.waypoint_data.clear_category() clear_map_markers() - root.free() init_category_tree() var file = File.new() print("Loading protobuf file from path ", self.marker_file_path) file.open(self.marker_file_path, file.READ) var data = file.get_buffer(file.get_len()) - self.Waypoint_data.from_bytes(data) + self.waypoint_data.from_bytes(data) if !Waypoint.PB_ERR.NO_ERRORS: print("OK") else: print(Waypoint.PB_ERR) - parse_Waypoint() + Waypoint_categories_to_godot_nodes() -var route_scene = load("res://Route.tscn") -var icon_scene = load("res://Icon.tscn") -var path2d_scene = load("res://Route2D.tscn") -var gizmo_scene = load("res://Gizmo/PointEdit.tscn") ##########Gizmo Stuff########### # How long the ray to search for 3D clickable object should be. @@ -409,12 +409,12 @@ func init_category_tree(): root.set_text(1, "Visible") -func parse_Waypoint(): - for category in self.Waypoint_data.get_category(): - parse_category(root, category, category.get_name(), false) +func Waypoint_categories_to_godot_nodes(): + for category in self.waypoint_data.get_category(): + _Waypoint_categories_to_godot_nodes(root, category, category.get_name(), false) -func parse_category(item: TreeItem, category, full_category_name: String, collapsed: bool): +func _Waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category_name: String, collapsed: bool): var category_item = self.marker_packs.create_item(item) if category.get_name() == "": # If this is called, there is an error in the Waypoint data @@ -441,7 +441,7 @@ func parse_category(item: TreeItem, category, full_category_name: String, collap if texture_path == null: print("Warning: No texture found in " , full_category_name) continue - var full_texture_path = self.marker_file_dir.get_current_dir() + texture_path.get_path() + var full_texture_path = self.marker_file_dir + texture_path.get_path() gen_new_path(path_points, full_texture_path, path, category_item) for icon in category.get_icon(): @@ -454,11 +454,11 @@ func parse_category(item: TreeItem, category, full_category_name: String, collap if texture_path == null: print("Warning: No texture found in " , full_category_name) continue - var full_texture_path = self.marker_file_dir.get_current_dir() + texture_path.get_path() + var full_texture_path = self.marker_file_dir + texture_path.get_path() gen_new_icon(position_vector, full_texture_path, icon, category_item) for category_child in category.get_children(): - parse_category(category_item, category_child, full_category_name + "." + category_child.get_name(), true) + _Waypoint_categories_to_godot_nodes(category_item, category_child, full_category_name + "." + category_child.get_name(), true) func apply_category_visibility_to_nodes(category_item: TreeItem): @@ -565,7 +565,31 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego new_icon.visible = false icons.add_child(new_icon) +# 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 @@ -737,15 +761,16 @@ func _on_NewPathPoint_pressed(): # ################################################################################ func _on_SavePath_pressed(): - #TODO: Save to Waypoint - pass + $Control/Dialogs/SaveDialog.show() ################################################################################ # TODO: This function will be used when exporting packs ################################################################################ func _on_SaveDialog_file_selected(path): - pass - + 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)) func _on_NodeEditorDialog_hide(): self.currently_selected_node = null From 8d1eb3c09500f865dc815050203eafe60374b75f Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sun, 8 Oct 2023 15:32:43 -0400 Subject: [PATCH 6/7] Removed capital letters --- Spatial.gd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index 92b6d773..b2f8d666 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -316,7 +316,7 @@ func load_waypoint_markers(map_id): print("OK") else: print(Waypoint.PB_ERR) - Waypoint_categories_to_godot_nodes() + waypoint_categories_to_godot_nodes() ##########Gizmo Stuff########### @@ -409,12 +409,12 @@ func init_category_tree(): root.set_text(1, "Visible") -func Waypoint_categories_to_godot_nodes(): +func waypoint_categories_to_godot_nodes(): for category in self.waypoint_data.get_category(): - _Waypoint_categories_to_godot_nodes(root, category, category.get_name(), false) + _waypoint_categories_to_godot_nodes(root, category, category.get_name(), false) -func _Waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category_name: String, collapsed: bool): +func _waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category_name: String, collapsed: bool): var category_item = self.marker_packs.create_item(item) if category.get_name() == "": # If this is called, there is an error in the Waypoint data @@ -458,7 +458,7 @@ func _Waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category gen_new_icon(position_vector, full_texture_path, icon, category_item) for category_child in category.get_children(): - _Waypoint_categories_to_godot_nodes(category_item, category_child, full_category_name + "." + category_child.get_name(), true) + _waypoint_categories_to_godot_nodes(category_item, category_child, full_category_name + "." + category_child.get_name(), true) func apply_category_visibility_to_nodes(category_item: TreeItem): From f43acca0c8759cc1e02b4bda8235881fab6ef9fe Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 7 Nov 2023 20:20:49 -0500 Subject: [PATCH 7/7] Changed scenes to const preload and changed root from a global variable --- Spatial.gd | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index cdde8e50..1f8113ed 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -49,14 +49,13 @@ var x11_window_id_burrito: int var is_transient:bool = false # Scenes used throughout this scene -var route_scene = load("res://Route.tscn") -var icon_scene = load("res://Icon.tscn") -var path2d_scene = load("res://Route2D.tscn") -var gizmo_scene = load("res://Gizmo/PointEdit.tscn") +const route_scene = preload("res://Route.tscn") +const icon_scene = preload("res://Icon.tscn") +const path2d_scene = preload("res://Route2D.tscn") +const gizmo_scene = preload("res://Gizmo/PointEdit.tscn") ##########Node Connections########### onready var marker_packs := $Control/Dialogs/MarkerPacks/MarkerPacks as Tree -onready var root := self.marker_packs.create_item() as TreeItem onready var icons := $Icons as Spatial onready var paths := $Paths as Spatial onready var minimap := $Control/MiniMap as Node2D @@ -480,7 +479,9 @@ func clear_map_markers(): func init_category_tree(): - self.root = self.marker_packs.create_item() + self.marker_packs.clear() + var root : TreeItem + root = self.marker_packs.create_item() root.set_text(0, "Markers available on current map") root.set_selectable(0, false) root.set_text(1, "Visible") @@ -488,7 +489,7 @@ func init_category_tree(): func waypoint_categories_to_godot_nodes(): for category in self.waypoint_data.get_category(): - _waypoint_categories_to_godot_nodes(root, category, category.get_name(), false) + _waypoint_categories_to_godot_nodes(null, category, category.get_name(), false) func _waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category_name: String, collapsed: bool):