Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save current state to split files #267

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Icon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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])
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -9,6 +9,12 @@ var category: TreeItem

var point_list := PoolVector3Array()

func update_waypoint_trail(index):
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved
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]
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved

func create_mesh(point_list: PoolVector3Array):
self.point_list = point_list
refresh_mesh()
Expand Down
73 changes: 36 additions & 37 deletions Spatial.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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:
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved
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()

Expand Down Expand Up @@ -387,12 +389,13 @@ 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/"
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved
var marker_file_path = ""

func load_waypoint_markers(map_id):
self.marker_file_path = self.marker_file_dir + String(map_id) + ".data"
self.waypoint_data.clear_category()
func load_waypoint_markers():
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved
self.marker_file_path = self.split_marker_file_dir + String(self.map_id) + ".data"
self.waypoint_data = Waypoint.Waypoint.new()
clear_map_markers()
init_category_tree()
var file = File.new()
Expand Down Expand Up @@ -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()):
Expand All @@ -541,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)


Expand All @@ -555,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():
Expand Down Expand Up @@ -632,31 +638,18 @@ 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)

# 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():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are no longer relying on the internal state of the nodes how can we be sure that the state of the nodes is in sync with whatever we are saving

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be relying on the proto as the source of truth. So Icon.gd and Route.gd should now be set to update the proto any time a change is made to the node.

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
})
################################################################################
# Section of functions for saving changes to markers
################################################################################
func on_change_made():
self.unsaved_data_icon.visible = true

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 save_current_map_data():
var packed_bytes = self.waypoint_data.to_bytes()
if packed_bytes.size() > 0:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this check prevent saving a file which went from having "some markers" to "no markers" ?
IE: prevent deleting the last marker on a map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using the check to not make a blank file but you are correct it would prevent that. I'm going to remove the check.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make and link issue to track this theoretical case of creating blank files. Because that is possible, maybe the correct logic here will be to delete files that are empty instead of not saving/overwriting them. But something a future pass can deal with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var file = File.new()
file.open(self.marker_file_path, file.WRITE)
file.store_buffer(packed_bytes)

################################################################################
# Adjustment and gizmo functions
Expand Down Expand Up @@ -822,16 +815,14 @@ func _on_NewPathPoint_pressed():
#
################################################################################
func _on_SavePath_pressed():
$Control/Dialogs/SaveDialog.show()
#TODO: Save split files into individual files
pass

################################################################################
# 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
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved

func _on_NodeEditorDialog_hide():
self.currently_selected_node = null
Expand Down Expand Up @@ -905,6 +896,8 @@ func _on_ReversePathDirection_pressed():


func _on_ExitButton_pressed():
if unsaved_data_icon.visible:
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved
save_current_map_data()
exit_burrito()


Expand All @@ -927,3 +920,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 = ""
20 changes: 16 additions & 4 deletions Spatial.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

AsherGlick marked this conversation as resolved.
Show resolved Hide resolved
[node name="main_menu_toggle" type="Button" parent="Control/GlobalMenuButton"]
modulate = Color( 1, 1, 1, 0 )
margin_left = -2.0
Expand Down Expand Up @@ -184,10 +195,10 @@ __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
margin_left = 777.0
margin_top = 89.0
margin_right = 1448.0
margin_bottom = 587.0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for moving the window?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several windows that overlap each other. This moves this window to an unused space. This is something to keep in mind when we do the larger UI update.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is overlapping windows a problem?
Keep in mind the default minimum burrito overlay size is 800x600

window_title = "Open a Directory"
mode = 2
access = 2
Expand Down Expand Up @@ -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"]
Expand Down