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
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
2026-11-10 18:47:05 -06:00
|
|
|
## Fits every expanded, unfrozen group's frame around its visible members and
|
|
|
|
|
## inner groups, innermost first so outer frames fit the inner ones' new size.
|
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
|
|
|
func refit() -> void:
|
2026-11-10 18:47:05 -06:00
|
|
|
var order := main.data.groups.duplicate()
|
|
|
|
|
if order.size() > 1:
|
|
|
|
|
order.sort_custom(func(a: TableGroup, b: TableGroup) -> bool: return main.data.depth_of(a) > main.data.depth_of(b))
|
|
|
|
|
for g: TableGroup in order:
|
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
|
|
|
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))
|
2026-11-10 18:47:05 -06:00
|
|
|
for inner in main.data.child_groups(g.id):
|
|
|
|
|
var n := main.group_node(inner.id)
|
|
|
|
|
if n and n.visible:
|
|
|
|
|
rects.append(Rect2(n.position, n.size) if inner.collapsed else inner.rect())
|
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
|
|
|
if g.fit_to(rects):
|
|
|
|
|
var n := main.group_node(g.id)
|
|
|
|
|
if n:
|
|
|
|
|
n.sync_rect()
|