89 lines
5.0 KiB
Python
89 lines
5.0 KiB
Python
"""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()
|