Files
stickman/tests/test_prop_editor_thumb.gd
ryan 97f3730413 feat: Integrate custom prop library and sandbox functionality
- Added support for custom props in the sandbox, including loading, saving, and rendering.
- Implemented `PropLibrary` for managing custom prop entries and scanning for `.prop` files.
- Introduced `PropVisuals` for shared visual and collision representation of custom props.
- Enhanced `StageSpawner` to handle spawning of custom props with layered visuals and collision hulls.
- Created `MissingPropPlaceholder` to manage missing custom props during scene reloads.
- Updated thumbnail generation to support custom props with unique keys based on file paths.
- Added tests for custom prop lifecycle, authored visual values, and missing prop handling.
- Refactored existing code to accommodate new prop functionalities and ensure backward compatibility.
2026-09-21 23:13:35 -04:00

81 lines
3.0 KiB
GDScript

# Phase 9 Prop Editor - headless regression checks for the ThumbnailCache
# extension (prop_file_key / prop_file_png) and PNG round-trip.
# Run with:
# & "C:\Godot4\Godot_v4.7.1-stable_win64_console.exe" --headless --path "C:\tmp\stickman" --script "res://tests/test_prop_editor_thumb.gd"
extends SceneTree
const THUMBNAIL_CACHE := preload("res://scripts/thumbnails/thumbnail_cache.gd")
var _checks: int = 0
var _failures: int = 0
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
print("\n=== PHASE 9 PROP THUMB TEST ===")
await _test_prop_file_keys()
await _test_builtin_prop_png_unchanged()
await _test_png_round_trip()
await _test_missing_file()
print("----------------------------------------")
if _failures == 0:
print("RESULT: ALL PASSED (%d assertions)" % _checks)
quit(0)
else:
print("RESULT: %d FAILURE(S) out of %d assertions" % [_failures, _checks])
quit(1)
func check(label: String, condition: bool) -> void:
_checks += 1
if condition:
print("PASS: %s" % label)
else:
_failures += 1
print("FAIL: %s" % label)
func _test_prop_file_keys() -> void:
var cache: ThumbnailCache = THUMBNAIL_CACHE.new()
var path := "user://prop_thumb_key_test.prop"
var f := FileAccess.open(path, FileAccess.WRITE)
f.store_string("{}")
f.close()
var key: String = cache.prop_file_key(path)
var mtime: int = FileAccess.get_modified_time(path)
check("prop_file_key includes file namespace and mtime", key.begins_with("file_") and key.ends_with("_%d" % mtime))
check("prop_file_png uses PROP_DIR", cache.prop_file_png(path) == "user://thumbnails/props/%s.png" % key)
check("prop_file_key missing file still formats", cache.prop_file_key("res://nope.prop").begins_with("file_") and cache.prop_file_key("res://nope.prop").ends_with("_0"))
DirAccess.remove_absolute(path)
func _test_builtin_prop_png_unchanged() -> void:
var cache: ThumbnailCache = THUMBNAIL_CACHE.new()
check("prop_png keeps version key", cache.prop_png("crate") == "user://thumbnails/props/crate_v%d.png" % THUMBNAIL_CACHE.PROP_VERSION)
check("stickman_png unchanged", cache.stickman_png("abc_123") == "user://thumbnails/stickmen/abc_123.png")
func _test_png_round_trip() -> void:
var cache: ThumbnailCache = THUMBNAIL_CACHE.new()
var img := Image.create_empty(4, 4, false, Image.FORMAT_RGBA8)
img.fill(Color(1.0, 0.0, 0.0, 1.0))
var tex := ImageTexture.create_from_image(img)
var png_path := "user://thumbnails/props/test_roundtrip_v9.png"
var err: Error = cache.save_png(tex, png_path)
check("save_png succeeds", err == OK)
check("png exists on disk", FileAccess.file_exists(png_path))
cache.clear_memory()
var loaded: Texture2D = cache.load_png(png_path)
check("load_png round trip", loaded != null and loaded.get_size() == Vector2(4, 4))
check("save_png null texture rejected", cache.save_png(null, "user://thumbnails/props/null_v9.png") != OK)
DirAccess.remove_absolute(png_path)
func _test_missing_file() -> void:
var cache: ThumbnailCache = THUMBNAIL_CACHE.new()
check("load_png missing -> null", cache.load_png("user://thumbnails/props/definitely_missing.png") == null)