Skip to content

Commit

Permalink
Addressing code review. Splits from using node to having explicit var…
Browse files Browse the repository at this point in the history
…iables and pathways
  • Loading branch information
klingbolt committed Jun 9, 2024
1 parent 26c23e2 commit b1e858e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Gizmo/PointEdit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Spatial

var camera: Camera
signal selected(selected_object)
signal deselected(selected_object)
signal deselected()
signal updated(point_position)
var last_translation
var selected: bool = false
Expand Down
6 changes: 3 additions & 3 deletions Icon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func set_icon_image(texture_path: String):
self.texture = texture
self.material_override.set_shader_param("texture_albedo", texture)

func update_poistion(position: Vector3):
func set_position(position: Vector3):
self.translation = position

func remove(index: int = 0):
queue_free()
func remove_icon():
self.queue_free()
6 changes: 3 additions & 3 deletions Route.gd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func get_point_count():
func get_point_position(index: int):
return self.point_list[index]

func update_poistion(position: Vector3, index: int):
func set_point_position(position: Vector3, index: int):
self.point_list[index] = position
refresh_mesh()

Expand All @@ -89,11 +89,11 @@ func add_point(position: Vector3, index: int = -1):
self.point_list.insert(index, position)
refresh_mesh()

func remove(index: int):
func remove_point(index: int):
self.point_list.remove(index)
refresh_mesh()

func new_point_after(midpoint: Vector3, index):
func new_point_after(midpoint: Vector3, index: int):
var start: Vector3 = self.get_point_position(index)
if self.get_point_count() > index+1:
var end: Vector3 = self.get_point_position(index+1)
Expand Down
12 changes: 7 additions & 5 deletions Route2D.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
extends Line2D

func add_new_point(position: Vector3, index: int = -1):
self.add_point(Vector2(position.x, position.z), index)

func update_poistion(position: Vector3, index: int):
func on_update_position(position: Vector3, index: int):
self.set_point_position(index, Vector2(position.x, position.z))

func new_point_after(midpoint: Vector3, index: int):
Expand All @@ -15,5 +12,10 @@ func new_point_after(midpoint: Vector3, index: int):
midpoint2d = ((start-end)/2) + end
add_point(midpoint2d, index+1)

func remove(index: int):
func remove_point(index: int):
self.remove_point(index)

func reverse():
var points = self.points
points.invert()
self.points = points
93 changes: 58 additions & 35 deletions Spatial.gd
Original file line number Diff line number Diff line change
Expand Up @@ -692,47 +692,56 @@ func gen_adjustment_nodes():
continue
var new_gizmo = gizmo_scene.instance()
new_gizmo.translation = gizmo_position
new_gizmo.connect("selected", self, "on_gizmo_selected", [route, "path", path2d, i])
new_gizmo.connect("deselected", self, "on_gizmo_deselected", [route, "path", path2d, i])
new_gizmo.connect("updated", route, "update_point_poistion", [i])
new_gizmo.connect("updated", path2d, "update_point_poistion", [i])
new_gizmo.connect("selected", self, "on_path_gizmo_selected", [route, path2d, i])
new_gizmo.connect("deselected", self, "on_gizmo_deselected")
new_gizmo.connect("updated", route, "set_point_position", [i])
new_gizmo.connect("updated", path2d, "on_update_position", [i])
$Gizmos.add_child(new_gizmo)
for icon in category3d.icons:
var new_gizmo = gizmo_scene.instance()
new_gizmo.translation = icon.translation
new_gizmo.connect("selected", self, "on_gizmo_selected", [icon, "icon"])
new_gizmo.connect("deselected", self, "on_gizmo_deselected", [icon, "icon"])
new_gizmo.connect("updated", icon, "update_point_poistion")
new_gizmo.connect("selected", self, "on_icon_gizmo_selected", [icon])
new_gizmo.connect("deselected", self, "on_gizmo_deselected")
new_gizmo.connect("updated", icon, "set_position")
$Gizmos.add_child(new_gizmo)

var currently_selected_gizmo = null
var currently_selected_node3d = null
var currently_selected_node2d = null
var currently_selected_icon = null
var currently_selected_path3d = null
var currently_selected_path2d = null
var currently_selected_index = 0

func on_gizmo_selected(object, node3d, point_type: String, node2d = null, index: int = 0):
func on_icon_gizmo_selected(object: Spatial, icon: Sprite3D):
self.currently_selected_gizmo = object
self.currently_selected_node3d = node3d
self.currently_selected_node2d = node2d
self.currently_selected_icon = icon
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/DeleteNode.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SnapSelectedToPlayer.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/XZSnapToPlayer.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/YSnapToPlayer.disabled = false


func on_path_gizmo_selected(object: Spatial, path3d: Spatial, path2d: Line2D, index: int):
self.currently_selected_gizmo = object
self.currently_selected_path3d = path3d
self.currently_selected_path2d = path2d
self.currently_selected_index = index
$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
if point_type == "path":
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewNodeAfter.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/ReversePathDirection.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SetActivePath.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewPathPointAfter.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/ReversePathDirection.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SetActivePath.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SnapSelectedToPlayer.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/XZSnapToPlayer.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/YSnapToPlayer.disabled = false


func on_gizmo_deselected(object):
func on_gizmo_deselected():
self.currently_selected_gizmo = null
self.currently_selected_node3d = null
self.currently_selected_node2d = null
self.currently_selected_icon = null
self.currently_selected_path3d = null
self.currently_selected_path2d = null
self.currently_selected_index = 0
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/DeleteNode.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewNodeAfter.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewPathPointAfter.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SnapSelectedToPlayer.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/XZSnapToPlayer.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/YSnapToPlayer.disabled = true
Expand Down Expand Up @@ -826,58 +835,72 @@ func _on_NewPathPoint_pressed():
var z_accurate_player_position = player_position
z_accurate_player_position.z = -z_accurate_player_position.z
self.currently_active_path.add_point(z_accurate_player_position)
self.currently_active_path2d.add_point(z_accurate_player_position)
self.currently_active_path2d.add_point(Vector2(z_accurate_player_position.x, z_accurate_player_position.z))

func _on_NodeEditorDialog_hide():
self.currently_selected_gizmo = null
on_gizmo_deselected()
clear_adjustment_nodes()
_on_Dialog_hide()


func _on_DeleteNode_pressed():
self.currently_selected_node3d.remove(self.currently_selected_index)
if self.currently_selected_node2d != null:
self.currently_selected_node2d.remove(self.currently_selected_index)
on_gizmo_deselected(self.currently_selected_gizmo)
if self.currently_selected_icon != null:
self.currently_selected_icon.remove_icon()
if self.currently_selected_path3d != null:
self.currently_selected_path3d.remove_point(self.currently_selected_index)
if self.currently_selected_path2d != null:
self.currently_selected_path2d.remove_point(self.currently_selected_index)
on_gizmo_deselected()
clear_adjustment_nodes()
gen_adjustment_nodes()


func _on_NewNodeAfter_pressed():
func _on_NewPathPointAfter_pressed():
print("insert path node")
var midpoint = self.player_position
midpoint.z = -midpoint.z
self.currently_selected_node3d.new_point_after(midpoint, self.currently_selected_index)
if self.currently_selected_node2d != null:
self.currently_selected_node2d.new_point_after(midpoint, self.currently_selected_index)
if self.currently_selected_path3d != null:
self.currently_selected_path3d.new_point_after(midpoint, self.currently_selected_index)
if self.currently_selected_path2d != null:
self.currently_selected_path2d.new_point_after(midpoint, self.currently_selected_index)

on_gizmo_deselected(self.currently_selected_gizmo)
on_gizmo_deselected()
clear_adjustment_nodes()
gen_adjustment_nodes()

func _on_XZSnapToPlayer_pressed():
if self.currently_selected_gizmo == null:
print("Warning: No Point Selected")
self.currently_selected_gizmo.translation.x = self.player_position.x
self.currently_selected_gizmo.translation.z = -self.player_position.z


func _on_YSnapToPlayer_pressed():
if self.currently_selected_gizmo == null:
print("Warning: No Point Selected")
self.currently_selected_gizmo.translation.y = self.player_position.y


func _on_SnapSelectedToPlayer_pressed():
if self.currently_selected_gizmo == null:
print("Warning: No Point Selected")
self.currently_selected_gizmo.translation.x = self.player_position.x
self.currently_selected_gizmo.translation.z = -self.player_position.z
self.currently_selected_gizmo.translation.y = self.player_position.y

func _on_SetActivePath_pressed():
self.currently_active_path = self.currently_selected_node3d
self.currently_active_path2d = self.currently_selected_node2d
self.currently_active_path = self.currently_selected_path3d
self.currently_active_path2d = self.currently_selected_path2d

func set_active_path(path):
self.currently_active_path = path

func _on_ReversePathDirection_pressed():
self.currently_selected_node3d.reverse()
self.currently_selected_path3d.reverse()
self.currently_selected_path2d.reverse()
on_gizmo_deselected()
clear_adjustment_nodes()
gen_adjustment_nodes()


func _on_ExitButton_pressed():
Expand Down
4 changes: 2 additions & 2 deletions Spatial.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ size_flags_horizontal = 3
disabled = true
text = "Delete Selected"

[node name="NewNodeAfter" type="Button" parent="Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer"]
[node name="NewPathPointAfter" type="Button" parent="Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer"]
margin_top = 44.0
margin_right = 323.0
margin_bottom = 84.0
Expand Down Expand Up @@ -917,7 +917,7 @@ material/0 = SubResource( 4 )
[connection signal="hide" from="Control/Dialogs/SaveDialog" to="." method="_on_Dialog_hide"]
[connection signal="hide" from="Control/Dialogs/NodeEditorDialog" to="." method="_on_NodeEditorDialog_hide"]
[connection signal="pressed" from="Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/DeleteNode" to="." method="_on_DeleteNode_pressed"]
[connection signal="pressed" from="Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewNodeAfter" to="." method="_on_NewNodeAfter_pressed"]
[connection signal="pressed" from="Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewPathPointAfter" to="." method="_on_NewPathPointAfter_pressed"]
[connection signal="pressed" from="Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SnapSelectedToPlayer" to="." method="_on_SnapSelectedToPlayer_pressed"]
[connection signal="pressed" from="Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/XZSnapToPlayer" to="." method="_on_XZSnapToPlayer_pressed"]
[connection signal="pressed" from="Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/YSnapToPlayer" to="." method="_on_YSnapToPlayer_pressed"]
Expand Down

0 comments on commit b1e858e

Please sign in to comment.