Skip to content

Commit

Permalink
Refactor rally point handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Jun 29, 2023
1 parent 04bda65 commit 82386eb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
20 changes: 10 additions & 10 deletions source/match/players/human/UnitActionsController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ class Actions:
)
const AutoAttacking = preload("res://source/match/units/actions/AutoAttacking.gd")
const Constructing = preload("res://source/match/units/actions/Constructing.gd")
const Rallying = preload("res://source/match/units/actions/Rallying.gd")


func _ready():
MatchSignals.terrain_targeted.connect(_on_terrain_targeted)
MatchSignals.unit_targeted.connect(_on_unit_targeted)


func _navigate_selected_units_towards_position(target_point):
func _try_navigating_selected_units_towards_position(target_point):
var terrain_units_to_move = get_tree().get_nodes_in_group("selected_units").filter(
func(unit): return (
unit.is_in_group("controlled_units")
Expand All @@ -45,15 +44,16 @@ func _navigate_selected_units_towards_position(target_point):
unit.action = Actions.Moving.new(new_target)


func _set_rally_point(target_point: Vector3):
var structures = get_tree().get_nodes_in_group("selected_units").filter(
func _try_setting_rally_points(target_point: Vector3):
var controlled_structures = get_tree().get_nodes_in_group("selected_units").filter(
func(unit): return (
unit.is_in_group("controlled_units") and Actions.Rallying.is_applicable(unit)
unit.is_in_group("controlled_units") and unit.find_child("RallyPoint") != null
)
)

for structure in structures:
Actions.Rallying._set_rally_point(structure, target_point)
for structure in controlled_structures:
var rally_point = structure.find_child("RallyPoint")
if rally_point != null:
rally_point.global_position = target_point


func _navigate_selected_units_towards_unit(target_unit):
Expand Down Expand Up @@ -86,8 +86,8 @@ func _navigate_selected_units_towards_unit(target_unit):


func _on_terrain_targeted(position):
_navigate_selected_units_towards_position(position)
_set_rally_point(position)
_try_navigating_selected_units_towards_position(position)
_try_setting_rally_points(position)


func _on_unit_targeted(unit):
Expand Down
10 changes: 0 additions & 10 deletions source/match/units/actions/Rallying.gd

This file was deleted.

6 changes: 3 additions & 3 deletions source/match/units/traits/RallyPoint.gd
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
extends Node3D

@onready var _unit = get_parent()
@onready var _line = get_node("Line")
@onready var _marker = get_node("Marker")
@onready var _animation_player = find_child("AnimationPlayer")


func _ready():
get_node("AnimationPlayer").play("idle")
_animation_player.play("idle")


func _process(_delta):
# TODO: calculate based on signals to avoid polling
visible = _unit.is_in_group("selected_units")
1 change: 0 additions & 1 deletion source/match/units/traits/RallyPoint.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ _data = {
script = ExtResource("1_jne3g")

[node name="Marker" type="MeshInstance3D" parent="."]
transform = Transform3D(0.845995, 0, 0, 0, 0.845995, 0, 0, 0, 0.845995, 0, 0, 0)
mesh = SubResource("CylinderMesh_phq1d")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
Expand Down

0 comments on commit 82386eb

Please sign in to comment.