Files
stickman/scripts/stickman_factory.gd
T
ryan 3a1d522ec9 Add Phase 4 Final Bugs Specification and Tests
- Introduced a new architecture specification for Phase 4 final bugs, detailing scope, decisions, runtime data contracts, action roles, execution lanes, speech ownership, and signal flow.
- Implemented changes in `scripts/action_registry.gd`, `scripts/action_editor.gd`, `scripts/sandbox_stage.gd`, `scripts/stage_gizmos.gd`, `scripts/stickman_factory.gd`, and `scripts/stickman_rig.gd` to address identified bugs.
- Created a new test suite `tests/test_phase4_final_bugs.gd` to validate the implementation, covering action roles, grid snapping, prop manipulation, reactive runtime lane, spawn pose preservation, and more.
- Added a unique identifier for the test file to ensure proper tracking and management.
2026-09-13 23:20:01 -04:00

49 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)
rig.initialize_spawn_pose_from_skeleton()
return rig
static func spawn(path: String) -> StickmanRig:
var data := load_stk(path)
if data.is_empty():
return null
return spawn_from_data(data)