Files
stickman/scripts/trigger_area.gd
T
ryan f208127917 feat: Implement Phase 4 Trigger Events System
- Added a new event-driven system for reactive storytelling, allowing rules like "When X happens, do Y."
- Introduced TriggerArea class for placeable sensors in the stage.
- Enhanced StickmanRig to emit signals for actions and arrivals.
- Updated StageDirectorVisuals to render rules visually with labels and badges.
- Modified StageSpawner to support spawning TriggerAreas.
- Improved text baseline calculations in speech bubbles and rule labels.
- Added tests for text baseline fixes to ensure proper rendering.
- Documented the implementation plan for Phase 4 in PHASE_4_TRIGGER_EVENTS.md.
- Created a polish plan for Phase 4 in PHASE_4b_POLISH.md.
2026-09-01 08:58:07 -04:00

51 lines
1.9 KiB
GDScript

class_name TriggerArea
extends Node2D
## TriggerArea - Placeable rectangular sensor for the Sandbox Stage (Phase 4).
##
## A drawn Node2D (NOT a physics Area2D) that the stage's geometric event engine
## polls for movable overlap. Purely visual plus a size query; no signals, no
## physics. Draws a translucent green fill with a dashed green border so it reads
## as a trigger zone in EDIT mode. World-space child, so no zoom division is
## needed for the dashed border.
## Half-extents of the rectangular sensor in local space.
@export var size: Vector2 = Vector2(96.0, 96.0):
set(value):
size = value
queue_redraw()
## Local-space rectangle (centered on the node origin) used for overlap tests.
func get_area_rect() -> Rect2:
return Rect2(-size * 0.5, size)
func _draw() -> void:
var rect := get_area_rect()
draw_rect(rect, Color(0.2, 0.8, 0.3, 0.12), true)
_draw_dashed_rect(rect, Color(0.2, 0.8, 0.3, 0.6), 2.0, 6.0, 4.0)
## Dashed border along each edge of `rect` (top/right/bottom/left), drawn with a
## small manual dash loop using draw_line.
func _draw_dashed_rect(rect: Rect2, color: Color, width: float, dash: float, gap: float) -> void:
var tl := rect.position
var tr := rect.position + Vector2(rect.size.x, 0.0)
var br := rect.position + rect.size
var bl := rect.position + Vector2(0.0, rect.size.y)
_draw_dashed_edge(tl, tr, color, width, dash, gap)
_draw_dashed_edge(tr, br, color, width, dash, gap)
_draw_dashed_edge(br, bl, color, width, dash, gap)
_draw_dashed_edge(bl, tl, color, width, dash, gap)
func _draw_dashed_edge(from: Vector2, to: Vector2, color: Color, width: float, dash: float, gap: float) -> void:
var dir := from.direction_to(to)
var total := from.distance_to(to)
var dist := 0.0
while dist < total:
var start := from + dir * dist
var len := minf(dash, total - dist)
draw_line(start, start + dir * len, color, width, true)
dist += dash + gap