hadean-godot/Scripts/SelectionManager.gd

40 lines
858 B
GDScript
Raw Permalink Normal View History

2024-05-13 18:16:23 -04:00
extends Node2D
class_name SelectionManager
2025-10-10 03:01:08 -04:00
signal selection_updated
2024-05-13 18:16:23 -04:00
@export var selected_box_hidden_color = Color(1, 1, 1, 0)
@export var selected_box_color = Color(1, 1, 1, 0.6)
2025-10-10 03:01:08 -04:00
@onready var selection: Array[Building] = []
2024-05-13 18:16:23 -04:00
var anim_t: float = 0.0
func _process(delta):
anim_t += delta * 8
anim_t = clamp(anim_t, 0, 1)
queue_redraw()
func clear():
anim_t = 0
selection = []
2025-10-10 03:01:08 -04:00
selection_updated.emit(selection)
2024-05-13 18:16:23 -04:00
2025-10-10 03:01:08 -04:00
func append_array(items: Array[Building]):
2024-05-13 18:16:23 -04:00
selection.append_array(items)
2025-10-10 03:01:08 -04:00
selection_updated.emit(selection)
2024-05-13 18:16:23 -04:00
2025-10-10 03:01:08 -04:00
func select_array(items: Array[Building]):
2024-05-13 18:16:23 -04:00
clear()
if items.is_empty():
return
append_array(items)
func _draw():
if selection.is_empty():
return
for tile in selection:
draw_rect(
2025-09-24 20:01:45 -04:00
tile.get_worldbox().grow(lerp(-16, 0, anim_t)),
2024-05-13 18:16:23 -04:00
lerp(selected_box_hidden_color, selected_box_color, anim_t ** 1.3),
false, 3
)