134 lines
3.9 KiB
GDScript
134 lines
3.9 KiB
GDScript
class_name ActionRegistry
|
|
extends RefCounted
|
|
## ActionRegistry - Registry of director action templates (Phase 3c).
|
|
##
|
|
## Single source of truth for the action types the Director Tool and the event
|
|
## system understand. Adding a new action type is just appending an entry here;
|
|
## the ActionEditor and the panels generate their UI from this registry, so no
|
|
## other code changes are required.
|
|
|
|
const ACTION_TEMPLATES := {
|
|
"walk_to": {
|
|
"label": "Walk To",
|
|
"icon": "🚶",
|
|
"params": [
|
|
{ "key": "target", "type": "position", "required": true },
|
|
],
|
|
},
|
|
"speak": {
|
|
"label": "Speak",
|
|
"icon": "💬",
|
|
"params": [
|
|
{ "key": "text", "type": "text", "required": true },
|
|
{ "key": "duration", "type": "float", "default": 2.0 },
|
|
],
|
|
},
|
|
"wait": {
|
|
"label": "Wait",
|
|
"icon": "⏳",
|
|
"params": [
|
|
{ "key": "duration", "type": "float", "required": true },
|
|
],
|
|
},
|
|
"ragdoll": {
|
|
"label": "Ragdoll",
|
|
"icon": "💥",
|
|
"params": [],
|
|
},
|
|
"recover": {
|
|
"label": "Recover",
|
|
"icon": "🔄",
|
|
"params": [],
|
|
},
|
|
}
|
|
|
|
|
|
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
|
|
# ActionEditor._current_type / RuleEditor._select_action_type).
|
|
var out: Array[String] = []
|
|
out.assign(ACTION_TEMPLATES.keys())
|
|
return out
|
|
|
|
|
|
static func has_type(type: String) -> bool:
|
|
return ACTION_TEMPLATES.has(type)
|
|
|
|
|
|
static func label(type: String) -> String:
|
|
var tpl: Dictionary = ACTION_TEMPLATES.get(type, {})
|
|
return String(tpl.get("label", type))
|
|
|
|
|
|
static func icon(type: String) -> String:
|
|
var tpl: Dictionary = ACTION_TEMPLATES.get(type, {})
|
|
return String(tpl.get("icon", ""))
|
|
|
|
|
|
## Converts a flat queue action into a rule-action shape (adds `target` + nests
|
|
## params). `target_id` is the acting stickman's instance id.
|
|
static func to_rule_action(action: Dictionary, target_id: int) -> Dictionary:
|
|
var params: Dictionary = {}
|
|
match String(action.get("type", "")):
|
|
"walk_to":
|
|
params["target"] = action.get("target", Vector2.ZERO)
|
|
"speak":
|
|
params["text"] = String(action.get("text", ""))
|
|
params["duration"] = float(action.get("duration", 2.0))
|
|
"wait":
|
|
params["duration"] = float(action.get("duration", 0.0))
|
|
return {
|
|
"type": String(action.get("type", "")),
|
|
"target": target_id,
|
|
"params": params,
|
|
}
|
|
|
|
|
|
## Converts a rule-action shape back into a flat queue action (drops `target`).
|
|
static func from_rule_action(rule_action: Dictionary) -> Dictionary:
|
|
var params: Dictionary = rule_action.get("params", {})
|
|
match String(rule_action.get("type", "")):
|
|
"walk_to":
|
|
return { "type": "walk_to", "target": params.get("target", Vector2.ZERO) }
|
|
"speak":
|
|
return {
|
|
"type": "speak",
|
|
"text": String(params.get("text", "")),
|
|
"duration": float(params.get("duration", 2.0)),
|
|
}
|
|
"wait":
|
|
return { "type": "wait", "duration": float(params.get("duration", 0.0)) }
|
|
_:
|
|
return { "type": String(rule_action.get("type", "")) }
|
|
|
|
|
|
## Human-readable one-line summary for both flat queue actions and rule-action
|
|
## shapes (the get() fallbacks tolerate either key layout).
|
|
static func summarize(action: Dictionary) -> String:
|
|
var type := String(action.get("type", ""))
|
|
var params: Dictionary = action.get("params", {})
|
|
match type:
|
|
"walk_to":
|
|
var t: Vector2 = action.get("target", params.get("target", Vector2.ZERO))
|
|
return "Walk To (%d, %d)" % [int(roundf(t.x)), int(roundf(t.y))]
|
|
"speak":
|
|
var text := String(action.get("text", params.get("text", "")))
|
|
var dur := float(action.get("duration", params.get("duration", 2.0)))
|
|
return "Speak \"%s\" (%ss)" % [text, _fmt_duration(dur)]
|
|
"wait":
|
|
var wd := float(action.get("duration", params.get("duration", 0.0)))
|
|
return "Wait %ss" % _fmt_duration(wd)
|
|
"ragdoll":
|
|
return "Ragdoll"
|
|
"recover":
|
|
return "Recover"
|
|
_:
|
|
return type
|
|
|
|
|
|
static func _fmt_duration(v: float) -> String:
|
|
if v == roundf(v):
|
|
return str(int(v))
|
|
return str(v)
|