111 lines
4.9 KiB
GDScript
111 lines
4.9 KiB
GDScript
extends SceneTree
|
|
|
|
## Integracion de intro, menu, cambios de escena y retorno. Utiliza un perfil de pruebas aislado.
|
|
## Los botones se activan por su senal; el tacto real se comprueba en dispositivo.
|
|
const MENU_SCRIPT: Script = preload("res://ui/menu/main_menu.gd")
|
|
const BOOT_PATH: String = "res://game/main.tscn"
|
|
const MENU_PATH: String = "res://ui/menu/main_menu.tscn"
|
|
const BETA_PATH: String = "res://levels/level_00.tscn"
|
|
const VERTICAL_PATH: String = "res://levels/level_01.tscn"
|
|
var _failures: int = 0
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _run() -> void:
|
|
preload("res://tests/runtime_test_profile.gd").prepare(self)
|
|
_check(change_scene_to_file(BOOT_PATH) == OK, "Debe abrirse la intro")
|
|
var boot: Node = await _wait_for_scene(BOOT_PATH)
|
|
if boot == null:
|
|
quit(1)
|
|
return
|
|
_check(is_equal_approx(float(boot.get("intro_duration_seconds")), 10.0), "La duracion por defecto debe ser 10 s")
|
|
await create_timer(0.05).timeout
|
|
_check(current_scene == boot, "La intro no debe terminar antes de tiempo")
|
|
(boot.get_node("Margin/IntroContent/Skip") as Button).pressed.emit()
|
|
boot.call("_on_skip_pressed")
|
|
var menu: Node = await _wait_for_scene(MENU_PATH)
|
|
if menu == null:
|
|
quit(1)
|
|
return
|
|
_check(not quit_on_go_back, "Atras en Android no debe cerrar automaticamente la app")
|
|
var paths: PackedStringArray = MENU_SCRIPT.discover_level_paths()
|
|
_check(paths.has(BETA_PATH) and paths.has(VERTICAL_PATH), "Deben aparecer beta y nivel vertical")
|
|
for index: int in range(paths.size()):
|
|
_check(paths[index].get_base_dir() == "res://levels", "No se incluyen subcarpetas")
|
|
if index > 0:
|
|
_check(paths[index - 1].naturalnocasecmp_to(paths[index]) < 0, "La lista se ordena de forma natural")
|
|
(menu.get_node("Margin/Layout/Home/Play") as Button).pressed.emit()
|
|
var list: VBoxContainer = menu.get_node("Margin/Layout/Levels/Scroll/LevelList") as VBoxContainer
|
|
_check(list.get_child_count() == paths.size(), "Un boton por cada nivel descubierto")
|
|
(menu.get_node("Margin/Layout/Levels/Back") as Button).pressed.emit()
|
|
_check((menu.get_node("Margin/Layout/Home") as Control).visible, "Volver debe mostrar el inicio")
|
|
menu.call("_show_levels")
|
|
menu.call("_load_level", "res://levels/no_such_level.tscn")
|
|
_check((menu.get_node("Margin/Layout/Error") as Label).visible, "Un nivel inexistente debe mostrar un error recuperable")
|
|
_check((menu.get_node("Margin/Layout/Levels") as Control).visible, "Un fallo debe conservar el selector")
|
|
menu.call("_load_level", BETA_PATH)
|
|
menu.call("_load_level", VERTICAL_PATH)
|
|
_check(String(menu.get("_loading_path")) == BETA_PATH, "Una doble pulsacion no inicia dos niveles")
|
|
var level: Node = await _wait_for_scene(BETA_PATH)
|
|
if level == null:
|
|
quit(1)
|
|
return
|
|
var player: Node = level.get_node("Player")
|
|
_check((player.get("character_data") as CharacterData).id == &"singer", "Se conserva el personaje asignado, sin selector")
|
|
_check(int(player.get("special_charge")) == 0, "Cada nueva escena inicia su estado de combate")
|
|
Input.action_press("move_right")
|
|
level.get_node("LevelNavigation").call("return_to_menu")
|
|
menu = await _wait_for_scene(MENU_PATH)
|
|
_check(not Input.is_action_pressed("move_right"), "Salir libera los botones virtuales")
|
|
if menu == null:
|
|
quit(1)
|
|
return
|
|
menu.call("_show_levels")
|
|
menu.call("_load_level", VERTICAL_PATH)
|
|
level = await _wait_for_scene(VERTICAL_PATH)
|
|
if level == null:
|
|
quit(1)
|
|
return
|
|
_check(level.has_node("Triggers/Exit"), "El nuevo nivel necesita una salida")
|
|
# La salida es de un solo disparo; no vuelve a la intro.
|
|
var exit_area: Node = level.get_node("Triggers/Exit")
|
|
exit_area.call("_on_body_entered", level.get_node("Player"))
|
|
exit_area.call("_on_body_entered", level.get_node("Player"))
|
|
menu = await _wait_for_scene(MENU_PATH)
|
|
_check(menu != null, "La salida devuelve al menu")
|
|
|
|
# Segunda ruta: vencimiento del temporizador sin pulsar Saltar.
|
|
_check(change_scene_to_file(BOOT_PATH) == OK, "Debe poder abrirse de nuevo la intro")
|
|
boot = await _wait_for_scene(BOOT_PATH)
|
|
if boot != null:
|
|
# Se acorta solo esta prueba, sin alterar el recurso ni esperar diez segundos por test.
|
|
boot.set("intro_duration_seconds", 0.2)
|
|
menu = await _wait_for_scene(MENU_PATH)
|
|
_check(menu != null, "La intro debe finalizar por tiempo sin pulsar un boton")
|
|
if current_scene != null:
|
|
current_scene.queue_free()
|
|
current_scene = null
|
|
await process_frame
|
|
if _failures == 0:
|
|
print("OK MENU: intro, salto, temporizador, catalogo, error, doble pulsacion, niveles y regreso")
|
|
quit(0 if _failures == 0 else 1)
|
|
|
|
|
|
func _wait_for_scene(path: String) -> Node:
|
|
var deadline: int = Time.get_ticks_msec() + 15000
|
|
while Time.get_ticks_msec() < deadline:
|
|
if current_scene != null and current_scene.scene_file_path == path and current_scene.is_node_ready():
|
|
return current_scene
|
|
await create_timer(0.01).timeout
|
|
_check(false, "No llego a abrirse " + path)
|
|
return null
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
_failures += 1
|
|
push_error(message)
|