- Added a new animation specification document for Phase 9 Task 5 detailing the requirements for rig animation controls. - Introduced a new `StickmanRig` script to manage the facing direction and joint bending for the rig. - Implemented UI elements in the test harness for selecting animations, controlling playback (play/pause/resume/stop), and toggling loop mode. - Enhanced the `test_harness.gd` script to handle animation playback state and UI interactions. - Updated documentation in `AGENTS.md`, `README.md`, and `RIGGING.md` to reflect the new animation features.
48 lines
1.5 KiB
GDScript
48 lines
1.5 KiB
GDScript
class_name StickmanFactory
|
|
extends RefCounted
|
|
## StickmanFactory - Runtime factory for spawning rig instances from .stk files
|
|
## (Phase 9).
|
|
##
|
|
## Loads a versioned .stk JSON dictionary and instantiates a master_rig.tscn,
|
|
## adapting it via StkRigAdapter. Consumed by the standalone test harness, not
|
|
## referenced by the editor.
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Constants
|
|
# ---------------------------------------------------------------------------
|
|
|
|
const RIG_SCENE := preload("res://master_rig.tscn")
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Public API
|
|
# ---------------------------------------------------------------------------
|
|
|
|
static func load_stk(path: String) -> Dictionary:
|
|
var file := FileAccess.open(path, FileAccess.READ)
|
|
if file == null:
|
|
push_warning("StickmanFactory: failed to open '%s' (error %d)." % [path, FileAccess.get_open_error()])
|
|
return {}
|
|
|
|
var text := file.get_as_text()
|
|
file.close()
|
|
|
|
var parsed: Variant = JSON.parse_string(text)
|
|
if parsed == null or not parsed is Dictionary:
|
|
push_warning("StickmanFactory: failed to parse '%s' as JSON." % path)
|
|
return {}
|
|
|
|
return parsed as Dictionary
|
|
|
|
|
|
static func spawn_from_data(stk_data: Dictionary) -> StickmanRig:
|
|
var rig := RIG_SCENE.instantiate() as StickmanRig
|
|
StkRigAdapter.apply(stk_data, rig)
|
|
return rig
|
|
|
|
|
|
static func spawn(path: String) -> StickmanRig:
|
|
var data := load_stk(path)
|
|
if data.is_empty():
|
|
return null
|
|
return spawn_from_data(data)
|