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

[XML Converter] Save Protobins within Godot #265

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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])

func set_icon_image(texture_path: String):
self.texture_path = texture_path

Expand Down
31 changes: 30 additions & 1 deletion PackDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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
]
print(args)
var result: int = OS.execute(self.executable_path, args, true, output, true)
Expand All @@ -42,3 +41,33 @@ 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,
])
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.")
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):
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
88 changes: 50 additions & 38 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:
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/"
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():
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,32 @@ 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():
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
################################################################################
# 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():
Copy link
Owner

Choose a reason for hiding this comment

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

Do we need to "save" every top-level category every time the button is pressed?

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

################################################################################
# Adjustment and gizmo functions
Expand Down Expand Up @@ -822,16 +829,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
Expand Down Expand Up @@ -905,6 +909,8 @@ func _on_ReversePathDirection_pressed():


func _on_ExitButton_pressed():
if unsaved_data_icon.visible:
save_current_map_data()
exit_burrito()


Expand All @@ -927,3 +933,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 = ""
26 changes: 20 additions & 6 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
}

[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,15 +195,16 @@ __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
Comment on lines +198 to +202
Copy link
Owner

Choose a reason for hiding this comment

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

?

window_title = "Open a Directory"
mode = 2
access = 2
current_dir = ""
current_path = ""
current_dir = "."
current_path = "."
Comment on lines +206 to +207
Copy link
Owner

Choose a reason for hiding this comment

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

?

script = ExtResource( 14 )
__meta__ = {
"_edit_use_anchors_": false
Expand Down Expand Up @@ -784,6 +796,7 @@ margin_bottom = 304.0
text = "Load Lutris Profile"

[node name="CategoriesDialog" type="WindowDialog" parent="Control/Dialogs"]
visible = true
Copy link
Owner

Choose a reason for hiding this comment

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

?

margin_left = 280.0
margin_top = 105.0
margin_right = 751.0
Expand Down Expand Up @@ -879,6 +892,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
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
config_version=4

_global_script_classes=[ {
"base": "Node",
"base": "",
Copy link
Owner

Choose a reason for hiding this comment

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

?

"class": "TacoParser",
"language": "NativeScript",
"path": "res://tacoparser.gdns"
Expand Down