Mejoras en la creacion de niveles, y el hud del jugador
This commit is contained in:
1 parent
fd0118d964
commit
5b1a434778
29 files changed
+3210
-101
No files matched your search
@@ -0,0 +1,54 @@
|
||||
"""Contratos de conexion de la visibilidad de UI; no sustituyen al motor."""
|
||||
|
||||
from pathlib import Path
|
||||
import re
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
UI_SCENES = {
|
||||
"ui/hud/player_health_hud.tscn": ".",
|
||||
"ui/hud/special_charge_hud.tscn": ".",
|
||||
"ui/mobile_controls/mobile_controls.tscn": ".",
|
||||
"levels/level_01.tscn": "TestHUD",
|
||||
"levels/level_02.tscn": "LevelHUD",
|
||||
}
|
||||
|
||||
|
||||
class EditorUIResourceTests(unittest.TestCase):
|
||||
def test_each_existing_overlay_has_a_visibility_component(self):
|
||||
for relative, parent in UI_SCENES.items():
|
||||
with self.subTest(scene=relative):
|
||||
text = (ROOT / relative).read_text(encoding="utf-8")
|
||||
self.assertIn('path="res://ui/editor_ui_visibility.gd"', text)
|
||||
self.assertIn(
|
||||
f'[node name="EditorVisibility" type="Node" parent="{parent}"]\n'
|
||||
'script = ExtResource("editor_ui_visibility")', text,
|
||||
)
|
||||
|
||||
def test_gameplay_ui_scripts_do_not_run_inside_the_editor(self):
|
||||
for relative in (
|
||||
"ui/hud/player_health_hud.gd",
|
||||
"ui/hud/special_charge_hud.gd",
|
||||
"ui/mobile_controls/mobile_controls.gd",
|
||||
"player/player.gd",
|
||||
):
|
||||
with self.subTest(script=relative):
|
||||
self.assertNotIn("@tool", (ROOT / relative).read_text(encoding="utf-8"))
|
||||
|
||||
def test_component_is_editor_aware_and_does_not_move_ui(self):
|
||||
text = (ROOT / "ui/editor_ui_visibility.gd").read_text(encoding="utf-8")
|
||||
self.assertTrue(text.startswith("@tool\n"))
|
||||
self.assertIn("func _ready() -> void:\n\tset_process(Engine.is_editor_hint())", text)
|
||||
self.assertIn("edited_scene_root == canvas_layer", text)
|
||||
self.assertIn("@export var preview_in_editor: bool = false", text)
|
||||
for property_name in ("position", "offset", "scale", "rotation", "layer"):
|
||||
self.assertNotRegex(text, rf"canvas_layer\.{property_name}\s*=")
|
||||
|
||||
def test_component_does_not_modify_child_visibility(self):
|
||||
text = (ROOT / "ui/editor_ui_visibility.gd").read_text(encoding="utf-8")
|
||||
self.assertEqual(re.findall(r"^\s*(\w+)\.visible\s*=", text, re.MULTILINE), ["canvas_layer"])
|
||||
self.assertNotIn("get_children()", text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,47 @@
|
||||
extends SceneTree
|
||||
|
||||
## Ejecutar despues de importar el proyecto, igual que las otras suites.
|
||||
## Comprueba restauracion, visibilidad de hijos y ausencia de interferencia al jugar.
|
||||
## La previsualizacion en el editor se debe comprobar tambien abriendo las escenas.
|
||||
|
||||
const VISIBILITY_SCRIPT: Script = preload("res://ui/editor_ui_visibility.gd")
|
||||
var _failures: int = 0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("_run")
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
var canvas_layer := CanvasLayer.new()
|
||||
canvas_layer.visible = false
|
||||
var panel := Control.new()
|
||||
canvas_layer.add_child(panel)
|
||||
var hidden_message := Label.new()
|
||||
hidden_message.visible = false
|
||||
panel.add_child(hidden_message)
|
||||
var visibility := Node.new()
|
||||
visibility.set_script(VISIBILITY_SCRIPT)
|
||||
canvas_layer.add_child(visibility)
|
||||
root.add_child(canvas_layer)
|
||||
await process_frame
|
||||
_check(canvas_layer.visible, "La interfaz debe reaparecer al ejecutar una escena guardada oculta")
|
||||
_check(panel.is_visible_in_tree(), "Los controles normales deben seguir visibles al jugar")
|
||||
_check(not hidden_message.visible, "No se deben mostrar mensajes o paneles ocultos individualmente")
|
||||
_check(not visibility.is_processing(), "El componente no debe procesar cada frame de la partida")
|
||||
canvas_layer.hide()
|
||||
visibility.set("preview_in_editor", true)
|
||||
await process_frame
|
||||
await process_frame
|
||||
_check(not canvas_layer.visible, "El juego debe poder ocultar su UI sin que el componente la reactive")
|
||||
canvas_layer.queue_free()
|
||||
await process_frame
|
||||
if _failures == 0:
|
||||
print("OK EDITOR UI: restauracion, hijos y visibilidad de partida")
|
||||
quit(0 if _failures == 0 else 1)
|
||||
|
||||
|
||||
func _check(condition: bool, message: String) -> void:
|
||||
if not condition:
|
||||
_failures += 1
|
||||
push_error(message)
|
||||
@@ -90,7 +90,7 @@ func _run() -> void:
|
||||
_check(_death_signals == 1, "Death signal must fire once")
|
||||
enemy.call("take_damage", 1000, player.global_position)
|
||||
_check(_death_signals == 1, "Repeated hits must not produce another death")
|
||||
_check(int(player.get("special_charge")) == mini(100, charge_before_death + 25),
|
||||
_check(int(player.get("special_charge")) == mini(int(player.get("special_max_charge")), charge_before_death + int(player.get("special_charge_per_kill"))),
|
||||
"Death must grant special charge exactly once")
|
||||
enemy.call("_update_death_animation", 0.20)
|
||||
var enemy_visual: Sprite2D = enemy.get_node("Visual") as Sprite2D
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
"""Contratos estaticos del HUD y su parche; no sustituyen la ejecucion en Godot."""
|
||||
from pathlib import Path
|
||||
import math
|
||||
import re
|
||||
import unittest
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SCENES = ("ui/hud/player_health_hud.tscn", "ui/hud/special_charge_hud.tscn")
|
||||
|
||||
|
||||
class ThrashHUDResourceTests(unittest.TestCase):
|
||||
def test_shared_resources_exist_and_load_steps_match(self):
|
||||
for relative in (*SCENES, "ui/hud/thrash_hud_theme.tres"):
|
||||
with self.subTest(resource=relative):
|
||||
text = (ROOT / relative).read_text(encoding="utf-8")
|
||||
for path in re.findall(r'path="res://([^"]+)"', text):
|
||||
self.assertTrue((ROOT / path).is_file(), path)
|
||||
steps = int(re.search(r"load_steps=(\d+)", text).group(1))
|
||||
self.assertEqual(steps, 1 + len(re.findall(r"^\[(?:ext|sub)_resource ", text, re.M)))
|
||||
|
||||
def test_hud_controls_do_not_capture_mouse_or_touch(self):
|
||||
for relative in SCENES:
|
||||
for block in re.split(r"(?=^\[node )", (ROOT / relative).read_text(), flags=re.M):
|
||||
if re.match(r'\[node .*type="(?:Control|Label|TextureRect|ProgressBar)"', block):
|
||||
self.assertIn("mouse_filter = 2", block, (relative, block.splitlines()[0]))
|
||||
|
||||
def test_visual_only_script_is_the_shared_meter(self):
|
||||
script = (ROOT / "ui/hud/thrash_meter.gd").read_text()
|
||||
self.assertTrue(script.startswith("@tool\nclass_name ThrashMeter\nextends ProgressBar\n"))
|
||||
self.assertIn("Engine.is_editor_hint()", script)
|
||||
self.assertIn("@export var animations_enabled: bool = true", script)
|
||||
self.assertNotIn("take_damage(", script)
|
||||
self.assertNotIn("Input.", script)
|
||||
for relative in SCENES:
|
||||
scene = (ROOT / relative).read_text()
|
||||
self.assertIn('path="res://ui/hud/thrash_meter.gd"', scene)
|
||||
self.assertIn('path="res://ui/hud/thrash_hud_theme.tres"', scene)
|
||||
|
||||
def test_svg_art_is_self_contained_and_has_no_embedded_fonts(self):
|
||||
for asset in (ROOT / "assets/ui/hud").glob("*.svg"):
|
||||
with self.subTest(asset=asset.name):
|
||||
root = ET.parse(asset).getroot()
|
||||
self.assertGreater(int(root.attrib["width"]), 0)
|
||||
self.assertGreater(int(root.attrib["height"]), 0)
|
||||
for node in root.iter():
|
||||
self.assertNotIn(node.tag.rsplit("}", 1)[-1], {"image", "text", "script", "foreignObject"})
|
||||
for key in node.attrib:
|
||||
self.assertFalse(key.endswith("href"))
|
||||
|
||||
def test_bar_and_readout_paths_are_preserved(self):
|
||||
for relative, name in zip(SCENES, ("Health", "Special")):
|
||||
text = (ROOT / relative).read_text()
|
||||
self.assertIn(f'[node name="{name}Bar" type="ProgressBar" parent="HUD"]', text)
|
||||
self.assertIn(f'[node name="{name}Label" type="Label" parent="HUD/{name}Bar"]', text)
|
||||
theme = (ROOT / "ui/hud/thrash_hud_theme.tres").read_text()
|
||||
self.assertIn('path="res://assets/fonts/PixelOperator8.ttf"', theme)
|
||||
self.assertIn('ProgressBar/styles/background = SubResource("EmptyBar")', theme)
|
||||
self.assertIn('ProgressBar/styles/fill = SubResource("EmptyBar")', theme)
|
||||
|
||||
def test_charge_defaults_and_economy(self):
|
||||
script = (ROOT / "player/player.gd").read_text()
|
||||
values = {}
|
||||
for key in ("special_max_charge", "special_min_use_charge", "special_charge_per_kill"):
|
||||
values[key] = int(re.search(rf"var {key}: int = (\d+)", script).group(1))
|
||||
self.assertEqual(values, {"special_max_charge": 100, "special_min_use_charge": 25, "special_charge_per_kill": 10})
|
||||
self.assertEqual(math.ceil(values["special_max_charge"] / values["special_charge_per_kill"]), 10)
|
||||
self.assertEqual(math.ceil(values["special_min_use_charge"] / values["special_charge_per_kill"]), 3)
|
||||
self.assertIn("@export var special_kills_grant_charge: bool = false", script)
|
||||
|
||||
def test_special_reward_context_does_not_gate_all_deaths_during_solo(self):
|
||||
script = (ROOT / "player/player.gd").read_text()
|
||||
damage_call = '\t\t_applying_special_damage = true\n\t\tenemy.call("take_damage", damage, global_position)\n\t\t_applying_special_damage = false'
|
||||
self.assertIn(damage_call, script)
|
||||
callback = script.split("func _on_enemy_died(", 1)[1].split("\nfunc ", 1)[0]
|
||||
self.assertIn("_applying_special_damage and not special_kills_grant_charge", callback)
|
||||
self.assertNotIn("_special_active", callback)
|
||||
|
||||
def test_meter_protects_zero_capacity_and_special_has_no_damage_trail(self):
|
||||
meter = (ROOT / "ui/hud/thrash_meter.gd").read_text()
|
||||
special = (ROOT / "ui/hud/special_charge_hud.gd").read_text()
|
||||
self.assertIn("max_value = maxf(capacity, 1.0)", meter)
|
||||
self.assertIn("float(amount) / float(maxi(capacity, 1))", special)
|
||||
self.assertIn('show_damage_trail = false', (ROOT / SCENES[1]).read_text())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,140 @@
|
||||
extends SceneTree
|
||||
|
||||
## Ejecutar despues de importar el proyecto:
|
||||
## godot --headless --path . --script res://tests/test_thrash_hud_runtime.gd
|
||||
## Verifica valores reales, animacion, umbrales y bajas causadas por el especial.
|
||||
## La composicion visual y el editor requieren ademas una revision interactiva.
|
||||
|
||||
var _failures: int = 0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("_run")
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
root.size = Vector2i(1152, 648)
|
||||
var arena := Node2D.new()
|
||||
var player: CharacterBody2D = load("res://player/player.tscn").instantiate() as CharacterBody2D
|
||||
var enemy: CharacterBody2D = load("res://enemies/walker/walker.tscn").instantiate() as CharacterBody2D
|
||||
player.position = Vector2(200, 200)
|
||||
enemy.position = Vector2(250, 200)
|
||||
enemy.set("drops_handled_by_level", true)
|
||||
enemy.set("respawn_delay", 0.0)
|
||||
# El enemigo entra primero: Player conecta los miembros actuales de su grupo en _ready.
|
||||
arena.add_child(enemy)
|
||||
arena.add_child(player)
|
||||
root.add_child(arena)
|
||||
current_scene = arena
|
||||
player.set_physics_process(false)
|
||||
enemy.set_physics_process(false)
|
||||
var camera: Camera2D = player.get_node("Camera2D") as Camera2D
|
||||
camera.force_update_scroll()
|
||||
await process_frame
|
||||
|
||||
var health_hud: CanvasLayer = player.get_node("PlayerHealthHUD") as CanvasLayer
|
||||
var special_hud: CanvasLayer = player.get_node("SpecialChargeHUD") as CanvasLayer
|
||||
var health_bar: ThrashMeter = health_hud.get_node("HUD/HealthBar") as ThrashMeter
|
||||
var special_bar: ThrashMeter = special_hud.get_node("HUD/SpecialBar") as ThrashMeter
|
||||
var health_label: Label = health_bar.get_node("HealthLabel") as Label
|
||||
var special_label: Label = special_bar.get_node("SpecialLabel") as Label
|
||||
var warning_label: Label = health_hud.get_node("HUD/WarningLabel") as Label
|
||||
var status_label: Label = special_hud.get_node("HUD/StatusLabel") as Label
|
||||
_check(health_hud.visible and special_hud.visible, "Los dos HUD deben verse al jugar")
|
||||
_check(health_label.text == "50 / 50", "La primera lectura de vida debe llegar sin animacion")
|
||||
_check(is_equal_approx(health_bar.value, 50.0), "Vida inicial incorrecta")
|
||||
_check(special_label.text == "0%", "El especial debe empezar vacio")
|
||||
|
||||
player.emit_signal("health_changed", 10, 50)
|
||||
_check(health_label.text == "10 / 50", "El numero debe cambiar en el mismo evento")
|
||||
_check(health_bar.highlighted and warning_label.visible, "Falta el aviso de poca vida")
|
||||
_check(is_equal_approx(float(health_bar.get("_display_ratio")), 0.2), "La perdida de vida no debe retrasarse")
|
||||
_check(is_equal_approx(float(health_bar.get("_trail_ratio")), 1.0), "La estela debe recordar la vida perdida")
|
||||
health_bar.call("_process", 1.0)
|
||||
_check(is_equal_approx(float(health_bar.get("_trail_ratio")), 0.2), "La estela debe desaparecer")
|
||||
player.emit_signal("health_changed", 40, 50)
|
||||
_check(not warning_label.visible and not health_bar.highlighted, "Curarse debe quitar el aviso")
|
||||
health_bar.animations_enabled = false
|
||||
player.emit_signal("health_changed", 25, 50)
|
||||
_check(not health_bar.is_processing(), "Sin animacion no debe haber procesamiento visual continuo")
|
||||
_check(is_equal_approx(float(health_bar.get("_display_ratio")), 0.5), "El modo estatico debe actualizarse al instante")
|
||||
player.emit_signal("health_changed", 0, 0)
|
||||
_check(health_label.text == "0 / 0" and is_zero_approx(health_bar.value), "Capacidad nula de vida")
|
||||
player.emit_signal("health_changed", 50, 50)
|
||||
|
||||
# Diez notificaciones de baja ordinaria; el test de combate ya verifica died una sola vez por muerte.
|
||||
for kills: int in range(1, 12):
|
||||
player.call("_on_enemy_died", enemy)
|
||||
_check(int(player.get("special_charge")) == mini(kills * 10, 100), "Carga o saturacion incorrecta")
|
||||
if kills == 1:
|
||||
_check(is_zero_approx(float(special_bar.get("_display_ratio"))), "La ganancia debe iniciar una subida, no saltar")
|
||||
special_bar.call("_process", 0.1)
|
||||
_check(is_equal_approx(float(special_bar.get("_display_ratio")), 0.05), "10 puntos deben interpolarse en 0.2 segundos")
|
||||
if kills == 2:
|
||||
_check(status_label.text == "CARGANDO" and not special_bar.highlighted, "20 puntos no bastan")
|
||||
player.call("_start_special_attack")
|
||||
_check(not bool(player.get("_special_active")), "No debe iniciarse el solo con 20 puntos")
|
||||
_check(int(player.get("special_charge")) == 20, "Un intento invalido no consume carga")
|
||||
if kills == 3:
|
||||
_check(status_label.text == "LISTO" and special_bar.highlighted, "30 puntos deben permitir el solo")
|
||||
_check(status_label.text == "AL 11" and special_label.text == "100%", "Falta el estado de carga completa")
|
||||
player.call("_start_special_attack")
|
||||
_check(bool(player.get("_special_active")), "La carga completa debe activar el solo")
|
||||
_check(int(player.get("special_charge")) == 0 and special_label.text == "0%", "El solo debe consumir la carga")
|
||||
_check(is_zero_approx(float(special_bar.get("_display_ratio"))), "La barra debe vaciarse sin retraso")
|
||||
|
||||
# Una baja ajena al dano del solo sigue concediendo carga aunque la animacion este activa.
|
||||
player.call("_on_enemy_died", enemy)
|
||||
_check(int(player.get("special_charge")) == 10, "No se deben filtrar otras bajas durante el solo")
|
||||
enemy.set("current_health", 1)
|
||||
player.call("_apply_special_attack", 100, 0)
|
||||
_check(bool(enemy.get("is_dead")), "El pulso de prueba debe matar al enemigo visible")
|
||||
_check(int(player.get("special_charge")) == 10, "El solo no debe recargarse con su propia baja")
|
||||
_check(not bool(player.get("_applying_special_damage")), "El contexto de dano debe restaurarse")
|
||||
|
||||
# Enemigo nuevo para comprobar la opcion de restaurar la regla anterior.
|
||||
var second_enemy: CharacterBody2D = load("res://enemies/walker/walker.tscn").instantiate() as CharacterBody2D
|
||||
second_enemy.position = player.position + Vector2(50, 0)
|
||||
second_enemy.set("drops_handled_by_level", true)
|
||||
second_enemy.set("respawn_delay", 0.0)
|
||||
arena.add_child(second_enemy)
|
||||
second_enemy.set_physics_process(false)
|
||||
second_enemy.set("current_health", 1)
|
||||
second_enemy.connect(&"died", Callable(player, "_on_enemy_died").bind(second_enemy))
|
||||
player.set("special_kills_grant_charge", true)
|
||||
player.call("_apply_special_attack", 100, 0)
|
||||
_check(bool(second_enemy.get("is_dead")), "El segundo pulso de prueba debe acertar")
|
||||
_check(int(player.get("special_charge")) == 20, "La opcion de recarga propia debe funcionar")
|
||||
_check(not bool(player.get("_applying_special_damage")), "El contexto no debe quedar activado")
|
||||
|
||||
# La UI respeta capacidad y minimo configurados, en vez de asumir siempre 100 y 25.
|
||||
player.set("special_max_charge", 50)
|
||||
player.set("special_min_use_charge", 25)
|
||||
player.emit_signal("special_charge_changed", 25, 50)
|
||||
_check(special_label.text == "50%", "25 de 50 debe indicar 50%")
|
||||
_check(is_equal_approx(special_bar.activation_ratio, 0.5), "La marca debe seguir el umbral real")
|
||||
player.set("special_min_use_charge", 60)
|
||||
player.emit_signal("special_charge_changed", 50, 50)
|
||||
_check(status_label.text == "DESACTIVADO" and not special_bar.highlighted, "Un umbral imposible no debe aparecer listo")
|
||||
player.emit_signal("special_charge_changed", 0, 0)
|
||||
_check(special_label.text == "0%" and is_zero_approx(special_bar.value), "Capacidad cero de especial")
|
||||
|
||||
# Los objetos conservan su potencia; el cambio de balance solo afecta a las bajas.
|
||||
player.set("special_max_charge", 100)
|
||||
player.set("special_min_use_charge", 25)
|
||||
player.set("special_charge", 0)
|
||||
var tape: PickupData = load("res://pickups/data/casete_demo.tres") as PickupData
|
||||
_check(bool(player.call("collect_pickup", tape)), "El casete debe seguir recargando")
|
||||
_check(int(player.get("special_charge")) == 25, "No debe alterarse la recompensa del casete")
|
||||
|
||||
arena.queue_free()
|
||||
await process_frame
|
||||
if _failures == 0:
|
||||
print("OK THRASH HUD: vida, estela, estados, umbrales, capacidad cero y economia del solo")
|
||||
quit(0 if _failures == 0 else 1)
|
||||
|
||||
|
||||
func _check(condition: bool, message: String) -> void:
|
||||
if not condition:
|
||||
_failures += 1
|
||||
push_error(message)
|
||||
Reference in new issue
Block a user