Files
stickman/scripts/stickman_factory.gd
ryan db4ff8d939 Implement Phase 8: Rig Relocation and Component Modularization
- Moved the rig scene from `res://master_rig.tscn` to `res://scenes/stickman_rig.tscn`, preserving its UID.
- Split the `StickmanRig` controller into three components: `StickmanLocomotion`, `StickmanRagdoll`, and `StickmanActionRunner`.
- Updated the architecture to ensure `StickmanRig` acts as the public facade for the new components.
- Created a new test suite `test_phase8_rig_modularization.gd` to verify the integrity of the relocated rig and its components.
- Added checks for scene loading, component resolution, action queue delegation, and state authority.
2026-09-18 14:11:53 -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 scenes/stickman_rig.tscn,
## adapting it via StkRigAdapter. Consumed by the standalone test harness, not
## referenced by the editor.
# ---------------------------------------------------------------------------
# Constants
# ---------------------------------------------------------------------------
const RIG_SCENE := preload("res://scenes/stickman_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)