Files
stickman/scripts/trigger_registry.gd

72 lines
2.0 KiB
GDScript

class_name TriggerRegistry
extends RefCounted
## TriggerRegistry - Registry of rule trigger templates (Phase 3c).
##
## Single source of truth for the trigger types the event system understands.
## Adding a new trigger type is just appending an entry here; the RuleEditor and
## the panels generate their UI from this registry.
const TRIGGER_TEMPLATES := {
"arrived_at_waypoint": {
"label": "Arrives at waypoint",
"icon": "📍",
"target_type": "waypoint",
},
"action_finished": {
"label": "Completes any action",
"icon": "✅",
"target_type": "action_type",
},
"speech_finished": {
"label": "Finishes speaking",
"icon": "💬",
"target_type": "none",
},
"entered_area": {
"label": "Enters trigger area",
"icon": "🎯",
"target_type": "area",
},
"collided": {
"label": "Collides with something",
"icon": "💥",
"target_type": "prop",
},
}
static func types() -> Array[String]:
# Dictionary.keys() returns an untyped Array at runtime; build a genuinely
# typed Array[String] so callers can store it in typed locals (see
# RuleEditor._current_type).
var out: Array[String] = []
out.assign(TRIGGER_TEMPLATES.keys())
return out
static func has_type(type: String) -> bool:
return TRIGGER_TEMPLATES.has(type)
static func label(type: String) -> String:
var tpl: Dictionary = TRIGGER_TEMPLATES.get(type, {})
return String(tpl.get("label", type))
static func icon(type: String) -> String:
var tpl: Dictionary = TRIGGER_TEMPLATES.get(type, {})
return String(tpl.get("icon", ""))
## Which kind of stage target a trigger needs: "waypoint", "action_type",
## "area", "prop", or "none".
static func target_type(type: String) -> String:
var tpl: Dictionary = TRIGGER_TEMPLATES.get(type, {})
return String(tpl.get("target_type", "none"))
## Human-readable summary of a trigger, e.g. "Arrives at waypoint".
static func summarize(trigger: Dictionary) -> String:
var type := String(trigger.get("type", ""))
return "%s %s" % [icon(type), label(type)]