Skip to content

Commit

Permalink
Refactor the codebase after #99
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Jan 9, 2024
1 parent a77cf53 commit 70104be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 62 deletions.
2 changes: 1 addition & 1 deletion source/match/Match.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
[ext_resource type="PackedScene" uid="uid://bocb7hjilvri5" path="res://source/match/handlers/ArealUnitSelectionHandler.tscn" id="24_aug7m"]
[ext_resource type="PackedScene" uid="uid://pi813oou7xim" path="res://source/match/handlers/DoubleClickUnitSelectionHandler.tscn" id="25_ldkhw"]
[ext_resource type="PackedScene" uid="uid://yn470qvc3eak" path="res://source/match/handlers/MatchEndHandler.tscn" id="26_4d7im"]
[ext_resource type="PackedScene" uid="uid://ck6vrgdyg7hja" path="res://source/match/handlers/UnitGroupSelectionHandler.tscn" id="27_j2drv"]
[ext_resource type="PackedScene" path="res://source/match/handlers/UnitGroupSelectionHandler.tscn" id="27_j2drv"]
[ext_resource type="PackedScene" uid="uid://b8p6lcwubx1tp" path="res://source/match/handlers/UnitVisibilityHandler.tscn" id="32_fci1c"]

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_ysb0j"]
Expand Down
84 changes: 28 additions & 56 deletions source/match/handlers/UnitGroupSelectionHandler.gd
Original file line number Diff line number Diff line change
@@ -1,65 +1,37 @@
extends Node3D

var _set_action_names = [null]
var _get_action_names = [null]
var _unit_group_names = [null]

# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.

func _ready():
for group_id in range(1, 10):
_set_action_names.append("unit_groups_set_{0}".format([group_id]))
_get_action_names.append("unit_groups_access_{0}".format([group_id]))
_unit_group_names.append("unit_group_{0}".format([group_id]))

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

func _input(event):
if event.is_action_pressed("unit_groups_set_1"):
set_group(1)
elif event.is_action_pressed("unit_groups_set_2"):
set_group(2)
elif event.is_action_pressed("unit_groups_set_3"):
set_group(3)
elif event.is_action_pressed("unit_groups_set_4"):
set_group(4)
elif event.is_action_pressed("unit_groups_set_5"):
set_group(5)
elif event.is_action_pressed("unit_groups_set_6"):
set_group(6)
elif event.is_action_pressed("unit_groups_set_7"):
set_group(7)
elif event.is_action_pressed("unit_groups_set_8"):
set_group(8)
elif event.is_action_pressed("unit_groups_set_9"):
set_group(9)
elif event.is_action_pressed("unit_groups_access_1"):
access_group(1)
elif event.is_action_pressed("unit_groups_access_2"):
access_group(2)
elif event.is_action_pressed("unit_groups_access_3"):
access_group(3)
elif event.is_action_pressed("unit_groups_access_4"):
access_group(4)
elif event.is_action_pressed("unit_groups_access_5"):
access_group(5)
elif event.is_action_pressed("unit_groups_access_6"):
access_group(6)
elif event.is_action_pressed("unit_groups_access_7"):
access_group(7)
elif event.is_action_pressed("unit_groups_access_8"):
access_group(8)
elif event.is_action_pressed("unit_groups_access_9"):
access_group(9)
for group_id in range(1, 10):
if event.is_action_pressed(_set_action_names[group_id]):
set_group(group_id)
return
if event.is_action_pressed(_get_action_names[group_id]):
access_group(group_id)
return


func access_group(group_id: int):
var units_in_group = Utils.Set.from_array(
get_tree().get_nodes_in_group(_unit_group_names[group_id])
)
Utils.Match.select_units(units_in_group)


func access_group(group_id:int):
var unit_group = Utils.Set.new()
for unit in get_tree().get_nodes_in_group("unit_group_"+str(group_id)):
if unit != null:
unit_group.add(unit)
Utils.Match.select_units(unit_group)


func set_group(group_id:int):
for unit in get_tree().get_nodes_in_group("unit_group_"+str(group_id)):
unit.remove_from_group("unit_group_"+str(group_id))
var unit_group = get_tree().get_nodes_in_group("selected_units")
for unit in unit_group:
func set_group(group_id: int):
for unit in get_tree().get_nodes_in_group(_unit_group_names[group_id]):
unit.remove_from_group(_unit_group_names[group_id])
for unit in get_tree().get_nodes_in_group("selected_units"):
if unit.is_in_group("controlled_units"):
unit.add_to_group("unit_group_"+str(group_id))
unit.add_to_group(_unit_group_names[group_id])
5 changes: 0 additions & 5 deletions source/match/units/traits/Selection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ func deselect():
_unit.deselected.emit()
MatchSignals.unit_deselected.emit(_unit)

func assign_group(group_id:int):
if _unit.is_in_group("unit_group_"+str(group_id)):
return
else:
_unit.add_to_group("unit_group_"+str(group_id))

func _set_radius(a_radius):
radius = a_radius
Expand Down

0 comments on commit 70104be

Please sign in to comment.