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) - -