99 lines
2.8 KiB
GDScript
99 lines
2.8 KiB
GDScript
extends SceneTree
|
|
|
|
## Pruebas de motor: puerta configurable, victoria por senal y arena relativa al jefe.
|
|
## godot --headless --path . --script res://tests/test_level_components_runtime.gd
|
|
|
|
class DummyActor:
|
|
extends Node2D
|
|
signal died
|
|
var is_dead: bool = false
|
|
|
|
var _failures: int = 0
|
|
var _victories: int = 0
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _run() -> void:
|
|
preload("res://tests/runtime_test_profile.gd").prepare(self)
|
|
await _test_gate()
|
|
await _test_boss_victory()
|
|
await _test_movable_arena()
|
|
print("LEVEL COMPONENTS: %d failures" % _failures)
|
|
quit(0 if _failures == 0 else 1)
|
|
|
|
|
|
func _test_gate() -> void:
|
|
var world := Node2D.new()
|
|
root.add_child(world)
|
|
var enemies := Node2D.new()
|
|
enemies.name = "Enemies"
|
|
world.add_child(enemies)
|
|
var foe := DummyActor.new()
|
|
enemies.add_child(foe)
|
|
var gate := preload("res://world/triggers/kill_gate.tscn").instantiate() as StaticBody2D
|
|
gate.set("enemies_root_path", NodePath("../Enemies"))
|
|
world.add_child(gate)
|
|
await process_frame
|
|
_check(int(gate.get("remaining")) == 1, "Gate counts configured enemies")
|
|
foe.died.emit()
|
|
_check(int(gate.get("remaining")) == 0, "Gate tracks enemy death")
|
|
gate.get_node("Visual").call("_process", 1.3)
|
|
await process_frame
|
|
await physics_frame
|
|
_check((gate.get_node("CollisionShape2D") as CollisionShape2D).disabled,
|
|
"Gate collision is removed after full visual opening")
|
|
world.queue_free()
|
|
await process_frame
|
|
|
|
|
|
func _test_boss_victory() -> void:
|
|
var level := LevelRoot.new()
|
|
level.enable_level_menu = false
|
|
var player := DummyActor.new()
|
|
player.name = "Player"
|
|
level.add_child(player)
|
|
var boss := DummyActor.new()
|
|
boss.name = "Boss"
|
|
level.add_child(boss)
|
|
var victory := preload("res://world/triggers/boss_victory.tscn").instantiate()
|
|
victory.set("boss_path", NodePath("../Boss"))
|
|
victory.set("completion_delay", 0.0)
|
|
level.add_child(victory)
|
|
level.level_completed.connect(_on_level_completed)
|
|
root.add_child(level)
|
|
await process_frame
|
|
boss.died.emit()
|
|
await create_timer(0.06).timeout
|
|
_check(_victories == 1, "Boss victory finishes exactly once")
|
|
boss.died.emit()
|
|
await create_timer(0.06).timeout
|
|
_check(_victories == 1, "Duplicate boss signal cannot finish twice")
|
|
level.queue_free()
|
|
await process_frame
|
|
|
|
|
|
func _test_movable_arena() -> void:
|
|
var boss := preload("res://bosses/spectral_death/spectral_death.tscn").instantiate() as Node2D
|
|
boss.position = Vector2(2400, 800)
|
|
root.add_child(boss)
|
|
await process_frame
|
|
var rect: Rect2 = boss.get("_arena_world")
|
|
_check(is_equal_approx(rect.position.x, 1810.0) and is_equal_approx(rect.end.y, 920.0),
|
|
"Boss arena follows its initial placement, not hardcoded world coordinates")
|
|
boss.queue_free()
|
|
await process_frame
|
|
|
|
|
|
func _on_level_completed() -> void:
|
|
_victories += 1
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
if condition:
|
|
return
|
|
_failures += 1
|
|
push_error(message)
|