Files
stickman/scripts/stickman_library.gd
ryan 1f91f3d2e5 Add headless regression tests for Phase 4b features
- Implement test for popup anchor behavior in rule-builder menus to ensure consistent anchor positioning during menu transitions.
- Create tests for stage logic, including mode transitions, toolbar visibility, and status bar updates.
- Add terrain drag-painting tests to verify correct block placement behavior and conflict handling.
- Introduce walk waypoint tests to check for arrival conditions and position stability after navigation.
2026-09-04 15:08:08 -04:00

68 lines
1.9 KiB
GDScript

class_name StickmanLibrary
extends RefCounted
const STICKMAN_FACTORY := preload("res://scripts/stickman_factory.gd")
const STICKMEN_DIR := "res://stickmen"
var entries: Array[Dictionary] = []
func scan(dir_path: String = STICKMEN_DIR) -> Array[Dictionary]:
entries = _scan_dir(dir_path)
return entries
func get_entries() -> Array[Dictionary]:
return entries
func find_by_path(path: String) -> Dictionary:
for e: Dictionary in entries:
if String(e.get("path", "")) == path:
return e
return {}
func make_entry(path: String) -> Dictionary:
var data: Dictionary = STICKMAN_FACTORY.load_stk(path)
if data.is_empty() or not data.has("body_parts"):
if not data.is_empty():
push_warning("StickmanLibrary: skipped '%s' (missing body_parts)." % path)
return {}
var name := String(data.get("stickman_name", "")).strip_edges()
if name.is_empty():
name = path.get_file().get_basename()
return { "path": path, "name": name, "data": data }
func _scan_dir(dir_path: String) -> Array[Dictionary]:
if not DirAccess.dir_exists_absolute(dir_path):
push_warning("StickmanLibrary: stickmen dir '%s' not found." % dir_path)
return []
var dir := DirAccess.open(dir_path)
if dir == null:
push_warning("StickmanLibrary: failed to open '%s'." % dir_path)
return []
var files: Array[String] = []
dir.list_dir_begin()
var fname := dir.get_next()
while fname != "":
if not dir.current_is_dir() and fname.get_extension().to_lower() == "stk":
files.append(dir_path + "/" + fname)
fname = dir.get_next()
dir.list_dir_end()
var built: Array[Dictionary] = []
for path: String in files:
var entry := make_entry(path)
if not entry.is_empty():
built.append(entry)
built.sort_custom(func(a: Dictionary, b: Dictionary) -> bool:
var na := String(a["name"])
var nb := String(b["name"])
if na != nb:
return na < nb
return String(a["path"]) < String(b["path"])
)
return built