Files
mortal-maze-the-game/tests/test_level_02_resources.py
T

84 lines
3.9 KiB
Python

"""Fast, engine-independent checks of the Level 02 alpha route.
Run: python -m unittest discover -s tests -v
A Godot playtest is still needed for physics, importing, and Android controls.
"""
from pathlib import Path
import re
import unittest
import struct
ROOT = Path(__file__).resolve().parents[1]
LEVEL = (ROOT / "levels/level_02.tscn").read_text(encoding="utf-8")
SCRIPT = (ROOT / "levels/level_02.gd").read_text(encoding="utf-8")
class Level02ResourceTests(unittest.TestCase):
def test_asset_references_exist(self):
for path in re.findall(r'path="res://([^"]+)"', LEVEL):
self.assertTrue((ROOT / path).is_file(), path)
for asset in re.findall(r'preload\("res://([^"]+)"\)', SCRIPT):
self.assertTrue((ROOT / asset).is_file(), asset)
def test_pixel_art_is_real_rgba_png_and_parallax_is_repeated(self):
graphics = list((ROOT / "assets/city").glob("*.png"))
self.assertEqual(len(graphics), 15)
for png in graphics:
content = png.read_bytes()
self.assertTrue(content.startswith(b"\x89PNG\r\n\x1a\n"), png.name)
width, height = struct.unpack(">II", content[16:24])
self.assertGreater(width, 15)
self.assertGreater(height, 15)
self.assertEqual(LEVEL.count('type="Parallax2D"'), 4)
self.assertEqual(LEVEL.count('repeat_size = Vector2(1024, 0)'), 4)
self.assertIn('autoscroll = Vector2(3, 0)', LEVEL)
self.assertIn('texture_repeat = 2', LEVEL)
def test_road_is_continuous_and_has_end_walls(self):
widths = [float(w) for w in re.findall(
r'\[sub_resource type="RectangleShape2D" id="Ground\d+"\]\nsize = Vector2\((\d+), 500\)', LEVEL
)]
# Each section uses a native CollisionShape2D with its own width.
sections = re.findall(
r'\[node name="Street\d+" type="CollisionShape2D" parent="World/Ground"\]\n'
r'position = Vector2\((\d+(?:\.\d+)?), (\d+(?:\.\d+)?)\)\n'
r'shape = SubResource\("Ground\d+"\)', LEVEL,
)
self.assertEqual(len(sections), 8)
self.assertEqual(len(widths), len(sections))
left_edge = 0
tops = []
for w, (center,y) in zip(widths, sections):
self.assertEqual(float(center) - w / 2, left_edge)
left_edge += w
tops.append(float(y) - 250.0)
self.assertEqual(left_edge, 11000)
self.assertTrue(all(a-b <= 110 for a,b in zip(tops, tops[1:])), tops)
for name in ('Left', 'Right'):
self.assertRegex(LEVEL, rf'\[node name="{name}" type="CollisionShape2D" parent="World/Barriers"\]')
self.assertIn('camera.limit_right = WORLD_WIDTH', SCRIPT)
self.assertIn('collision_mask = 2', LEVEL)
def test_multiple_encounters_and_optional_items(self):
enemies = re.findall(r'\[node name="Enemy\d+" parent="Enemies" instance=ExtResource\("enemy_([^\"]+)"\)\]', LEVEL)
pickups = re.findall(r'\[node name="Pickup\d+" parent="Items" instance=ExtResource\("pickup"\)\]', LEVEL)
self.assertEqual(len(enemies), 29)
self.assertEqual(len(set(enemies)), 5)
self.assertEqual(len(pickups), 14)
self.assertEqual(LEVEL.count('one_way_collision = true'), 11)
self.assertIn('run/main_scene="res://levels/level_02.tscn"', (ROOT / 'project.godot').read_text())
self.assertIn('respawn_delay = 0.0', (ROOT / 'enemies/variants/roadie.tscn').read_text())
def test_50_hp_all_characters_and_12_point_ground_pound(self):
for data in (ROOT / "player/characters").glob("*.tres"):
self.assertIn('max_health = 50', data.read_text(), data.name)
player = (ROOT / 'player/player.gd').read_text()
self.assertIn('ground_pound_min_damage: int = 7', player)
self.assertIn('ground_pound_max_damage: int = 12', player)
self.assertIn('mini(\n\t\troundi(damage', player)
if __name__ == '__main__':
unittest.main()