Skip to content

Commit

Permalink
Saves Waypoint data to file. Includes autosaving at key points
Browse files Browse the repository at this point in the history
  • Loading branch information
klingbolt committed Aug 25, 2023
1 parent b75d681 commit 24acc83
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Gizmo/PointEdit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ func update_point():
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)
self.object_link.update_waypoint_trail(self.object_index)
if point_type == "icon":
self.object_link.translation = self.translation
self.object_link.update_waypoint_icon()
print("update")
self.last_translation = self.translation

Expand Down
6 changes: 6 additions & 0 deletions Icon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const Waypoint = preload("res://waypoint.gd")
var texture_path
var waypoint: Waypoint.Icon

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

Expand Down
6 changes: 6 additions & 0 deletions Route.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ var waypoint: Waypoint.Trail

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()
Expand Down
54 changes: 49 additions & 5 deletions Spatial.gd
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ 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:
auto_saving()
print("Loading New Map")
load_waypoint_markers(self.map_id)

Expand Down Expand Up @@ -289,10 +291,12 @@ func reset_minimap_masks():
var Waypoint_data = Waypoint.Waypoint.new()
var marker_file_dir = Directory.new()
var marker_file_path = ""
var auto_save_file_path = ""
var root: TreeItem

##########Node Connections###########
onready var marker_packs = $Control/Dialogs/MarkerPacks/MarkerPacks
onready var unsaved_data_icon = $Control/GlobalMenuButton/BurritoIcon/UnsavedData
onready var icons = $Icons
onready var paths = $Paths
onready var minimap = $Control/MiniMap
Expand All @@ -304,9 +308,17 @@ func load_waypoint_markers(map_id):
clear_map_markers()
root.free()
init_category_tree()
self.auto_save_file_path = self.marker_file_dir.get_current_dir() + String(map_id) + "_auto.data"
var file = File.new()
print("Loading protobuf file from path ", self.marker_file_path)
file.open(self.marker_file_path, file.READ)
if self.marker_file_dir.file_exists(self.auto_save_file_path):
print("Loading autosave file from path ", self.auto_save_file_path)
file.open(self.auto_save_file_path, file.READ)
self.unsaved_data_icon.visible = true
elif self.marker_file_dir.file_exists(self.marker_file_path):
print("Loading protobuf file from path ", self.marker_file_path)
file.open(self.marker_file_path, file.READ)
else:
print("No markers on this map")
var data = file.get_buffer(file.get_len())
self.Waypoint_data.from_bytes(data)
if !Waypoint.PB_ERR.NO_ERRORS:
Expand Down Expand Up @@ -566,7 +578,30 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego
new_icon.visible = false
icons.add_child(new_icon)


################################################################################
# Section of functions for saving changes to markers
################################################################################
func on_change_made():
unsaved_data_icon.visible = true

func auto_saving():
print("Auto save")
var packed_bytes = self.Waypoint_data.to_bytes()
if packed_bytes.size() > 0:
var file = File.new()
file.open(self.auto_save_file_path, file.WRITE)
file.store_buffer(packed_bytes)

func manual_save():
print("Saving")
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)
if self.marker_file_dir.file_exists(self.auto_save_file_path):
self.marker_file_dir.remove(self.auto_save_file_path)
unsaved_data_icon.visible = false

################################################################################
# Adjustment and gizmo functions
Expand Down Expand Up @@ -619,6 +654,7 @@ func gen_adjustment_nodes():

var currently_selected_node = null
func on_gizmo_selected(object):
on_change_made()
self.currently_selected_node = object
$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
Expand Down Expand Up @@ -738,8 +774,7 @@ func _on_NewPathPoint_pressed():
#
################################################################################
func _on_SavePath_pressed():
#TODO: Save to Waypoint
pass
manual_save()

################################################################################
# TODO: This function will be used when exporting packs
Expand Down Expand Up @@ -820,6 +855,8 @@ func _on_ReversePathDirection_pressed():


func _on_ExitButton_pressed():
if unsaved_data_icon.visible:
auto_saving()
get_tree().quit()


Expand All @@ -837,3 +874,10 @@ 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)


func _on_UnsavedData_visibility_changed():
if $Control/GlobalMenuButton/BurritoIcon/UnsavedData.visible:
$Control/GlobalMenuButton/main_menu_toggle.hint_tooltip = "Unsaved Data"
else:
$Control/GlobalMenuButton/main_menu_toggle.hint_tooltip = ""
12 changes: 10 additions & 2 deletions Spatial.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="TextureRect" type="TextureRect" parent="Control/GlobalMenuButton"]
[node name="BurritoIcon" type="TextureRect" parent="Control/GlobalMenuButton"]
modulate = Color( 1, 1, 1, 0.439216 )
margin_left = 1.591
margin_left = 2.0
margin_top = 3.18198
margin_right = 26.591
margin_bottom = 28.182
Expand All @@ -89,6 +89,13 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="UnsavedData" type="TextureRect" parent="Control/GlobalMenuButton/BurritoIcon"]
visible = false
modulate = Color( 1, 0.0313726, 0.0313726, 1 )
margin_right = 40.0
margin_bottom = 40.0
texture = ExtResource( 3 )

[node name="main_menu_toggle" type="Button" parent="Control/GlobalMenuButton"]
modulate = Color( 1, 1, 1, 0 )
margin_right = 27.0
Expand Down Expand Up @@ -821,6 +828,7 @@ color = Color( 0, 0, 0, 1 )
mesh = SubResource( 3 )
material/0 = SubResource( 4 )

[connection signal="visibility_changed" from="Control/GlobalMenuButton/BurritoIcon/UnsavedData" to="." method="_on_UnsavedData_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"]
Expand Down

0 comments on commit 24acc83

Please sign in to comment.