TableTower/ui/group_layer.gd
RobinFiredrake 9fdf65c00b Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.

Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00

37 lines
1.1 KiB
GDScript

class_name GroupLayer
extends Control
## Holds the frames of expanded groups, behind the pipes and the cards, and
## keeps each frame fitted around its member cards. A group whose member is
## being dragged is frozen, so the card can be dragged out of the frame.
var main: Main
## Group ids that don't refit right now (a member is being dragged).
var frozen: Dictionary = {}
func _init() -> void:
mouse_filter = MOUSE_FILTER_IGNORE
# Controls only draw inside their own rect, so cover the whole world.
size = Vector2(BoardView.WORLD_SIZE, BoardView.WORLD_SIZE)
func _process(_delta: float) -> void:
if main == null or main.data == null:
return
refit()
## Fits every expanded, unfrozen group's frame around its visible members.
func refit() -> void:
for g in main.data.groups:
if g.collapsed or frozen.has(g.id):
continue
var rects: Array = []
for tid in g.members:
var c := main.card_for(tid)
if c and c.visible and c.size.x > 0.0:
rects.append(Rect2(c.position, c.size))
if g.fit_to(rects):
var n := main.group_node(g.id)
if n:
n.sync_rect()