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

210 lines
12 KiB
Python

"""Contratos estaticos de la banda. No ejecutan GDScript ni simulan la fisica."""
from pathlib import Path
import re
import unittest
try:
from .art_asset_helpers import animation_frames, atlas_path, atlas_regions, region_hash, rgba_png
except ImportError: # unittest discover -s tests imports each module at the top level.
from art_asset_helpers import animation_frames, atlas_path, atlas_regions, region_hash, rgba_png
ROOT = Path(__file__).resolve().parents[1]
ROLES = ('guitarist', 'drummer', 'bassist', 'singer')
NAMES = ('Diego', 'Ivan', 'Fer', 'Hector')
def source(path):
return (ROOT / path).read_text(encoding='utf-8')
class BandResourceTests(unittest.TestCase):
def test_named_profiles_have_independent_frames(self):
for role, name in zip(ROLES, NAMES):
data = source(f'player/characters/{role}.tres')
self.assertIn(f'id = &"{role}"', data)
self.assertIn(f'display_name = "{name}"', data)
self.assertIn(f'res://player/characters/animations/{role}_frames.tres', data)
self.assertNotIn('prototype_sprite_frames', data)
self.assertIn('role_name = ', data)
def test_base_stats_remain_shared(self):
for role in ROLES:
data = source(f'player/characters/{role}.tres')
for stat in ('max_health = 30', 'move_speed = 250.0', 'jump_velocity = -600.0', 'basic_attack_damage = 5'):
self.assertIn(stat, data)
self.assertIn('move_speed: float = 250.0', source('player/character_data.gd'))
player = source('player/player.gd')
self.assertIn('ground_acceleration: float = 1800.0', player)
self.assertIn('lerpf(0.65, 1.0, clampf(pace, 0.0, 1.0))', player)
for stat in ('special_charge_per_kill: int = 10', 'special_min_use_charge: int = 25',
'special_max_damage: int = 30', 'special_pulse_count: int = 4',
'ground_pound_max_damage: int = 12'):
self.assertIn(stat, player)
def test_visual_mapping_and_shared_doubled_radius(self):
expected = {
'guitarist': ('electric_pound', 'solo'),
'drummer': ('ground_pound', 'drum_cymbals'),
'bassist': ('bass_cracks', 'bass_pulse'),
'singer': ('vocal_dome', 'vocal_wave'),
}
for role, (pound, special) in expected.items():
text = source(f'player/characters/{role}.tres')
self.assertNotIn('ground_pound_radius', text)
self.assertIn(f'ground_pound_effect = "{pound}"', text)
self.assertIn(f'special_effect = "{special}"', text)
player = source('player/player.gd')
self.assertIn('ground_pound_radius: float = 108.0', player)
self.assertIn('pound_shape.radius = ground_pound_radius', player)
self.assertIn('query.shape = ground_pound_collision.shape', player)
self.assertIn('StringName(character_data.ground_pound_effect), facing_direction, ground_pound_radius)', player)
self.assertNotIn('ground_pound_radius_multiplier', source('player/character_data.gd'))
self.assertNotIn('ground_pound_radius_multiplier', player)
def test_attack_resolution_never_branches_on_character_or_effect(self):
player = source('player/player.gd')
# El efecto no elige objetivos, no decide dano y no genera colisiones nuevas.
functions = ('_apply_special_attack', '_update_punch_damage', '_damage_target')
for name in functions:
body = player.split(f'func {name}(', 1)[1].split('\nfunc ', 1)[0]
self.assertNotIn('character_data.id', body)
self.assertNotIn('character_data.special_effect', body)
self.assertNotIn('character_data.ground_pound_effect', body)
pound = player.split('func _ground_pound_impact()', 1)[1]
pound = pound.split('var height_reached:', 1)[1].split('func _start_special_attack', 1)[0]
self.assertNotIn('character_data', pound)
for token in ('query.shape', 'query.collision_mask', 'final_damage', '_damage_target'):
self.assertIn(token, pound)
def test_only_ivan_keeps_the_stick_trails(self):
code = source('player/player.gd')
self.assertIn('if ground_pound_active and character_data != null and character_data.ground_pound_effect == "ground_pound":', code)
def test_four_atlases_are_self_contained_and_all_regions_fit(self):
expected_names = {'idle', 'walk', 'jump', 'fall', 'punch', 'ground_pound',
'land', 'pound_land', 'special_start', 'special', 'special_end', 'hurt'}
for role in ROLES:
text = source(f'player/characters/animations/{role}_frames.tres')
atlas_file = atlas_path(ROOT, text)
self.assertEqual(atlas_file.suffix, '.png')
width, height, rgba = rgba_png(atlas_file)
self.assertEqual((width, height), (1152, 768))
alpha = rgba[3::4]
self.assertEqual(min(alpha), 0, 'El fondo del atlas debe ser transparente')
self.assertGreaterEqual(max(alpha), 250, 'Los cuerpos deben contener pixeles opacos')
self.assertTrue(expected_names <= set(re.findall(r'"name": &"([^"]+)"', text)))
declared = re.findall(r'\[sub_resource type="AtlasTexture" id="([^"]+)"\]', text)
self.assertGreaterEqual(len(declared), 40)
self.assertEqual(set(declared), set(re.findall(r'SubResource\("([^"]+)"\)', text)))
regions = atlas_regions(text)
self.assertEqual(set(declared), set(regions))
for x, y, w, h in regions.values():
self.assertEqual((w, h), (192, 192))
self.assertEqual((x % 192, y % 192), (0, 0))
self.assertLessEqual(x+w, width)
self.assertLessEqual(y+h, height)
self.assertEqual(int(re.search(r'load_steps=(\d+)', text)[1]),
1+len(re.findall(r'^\[(?:ext|sub)_resource ', text, re.M)))
def test_playable_art_has_distinct_identity_and_correct_instruments(self):
identities = set()
for role in ROLES:
frames = source(f'player/characters/animations/{role}_frames.tres')
regions = atlas_regions(frames)
image = rgba_png(atlas_path(ROOT, frames))
idle = region_hash(image, regions[animation_frames(frames, 'idle')[0]])
special = {region_hash(image, regions[name]) for name in animation_frames(frames, 'special')}
self.assertTrue(any(pose != idle for pose in special), role)
identities.add(idle)
# Los instrumentos y siluetas se inspeccionan ademas en la captura real.
portrait = ROOT / f'assets/ashen/portraits/{role}.png'
self.assertTrue(portrait.is_file(), role)
self.assertEqual(len(identities), 4, 'Cada integrante conserva un sprite propio')
def test_pixel_walk_uses_distinct_animation_cells(self):
for role in ROLES:
frames = source(f'player/characters/animations/{role}_frames.tres')
walk = animation_frames(frames, 'walk')
regions = atlas_regions(frames)
image = rgba_png(atlas_path(ROOT, frames))
self.assertEqual(len(walk), 6)
self.assertGreaterEqual(len({region_hash(image, regions[name]) for name in walk}), 5, role)
def test_punch_uses_identical_timing_in_every_profile(self):
expected = [('1.0', 'punch_0'), ('0.75', 'punch_1'), ('1.15', 'punch_2'),
('0.8', 'punch_3'), ('1.3', 'punch_4')]
for role in ROLES:
text = source(f'player/characters/animations/{role}_frames.tres')
self.assertEqual(re.findall(r'"duration": ([\d.]+), "texture": SubResource\("(punch_\d)"\)', text), expected)
self.assertIn('"name": &"punch",\n"speed": 18.0', text)
# El controlador unico mantiene la ventana danina compartida.
self.assertEqual(source('player/player.gd').count('func _update_punch_damage()'), 1)
def test_new_pound_pose_does_not_replace_regular_landing(self):
code = source('player/player.gd')
self.assertIn('animation_name = &"pound_land"', code)
self.assertIn('animation_name = &"land"', code)
self.assertIn('_pound_landing_timer = 0.28', code)
def test_effects_have_no_damage_or_collision_authority(self):
fx = source('effects/combat_fx.gd')
for identifier in ('take_damage', 'Area2D', 'PhysicsShapeQuery', 'CharacterBody2D'):
self.assertNotIn(identifier, fx)
for kind in ('electric_pound', 'vocal_dome', 'bass_cracks', 'vocal_wave', 'drum_cymbals', 'bass_pulse'):
self.assertIn(f'func _draw_{kind}(', fx)
self.assertIn('draw_texture_rect_region(FX_ATLAS', fx)
self.assertIn('CanvasItem.TEXTURE_FILTER_NEAREST', fx)
self.assertIn('draw_set_transform(Vector2.ZERO, 0.0, Vector2.ONE)', fx)
def test_bass_notes_and_camera_share_the_combat_pulse(self):
player = source('player/player.gd')
self.assertIn('if character_data.special_effect == "bass_pulse":', player)
self.assertIn('animated_sprite.set_frame_and_progress(0, 0.0)', player)
self.assertIn('character_data.special_shake_frequency', player)
self.assertIn('special_shake_frequency = 18.0', source('player/characters/bassist.tres'))
frames = source('player/characters/animations/bassist_frames.tres')
self.assertIn('"loop": false,\n"name": &"special"', frames)
camera = source('player/camera_2d.gd')
self.assertIn('minf(_shake_amplitude, 3.0)', camera)
self.assertIn('* feedback_strength', camera)
def test_selector_is_four_data_driven_touch_cards_in_two_columns(self):
scene = source('ui/menu/character_select.tscn')
self.assertIn('columns = 2', scene)
self.assertEqual(scene.count('instance=ExtResource("card")'), 4)
self.assertIn('follow_focus = true', scene)
for name, role in zip(NAMES, ROLES):
self.assertIn(f'[node name="{name}" ', scene)
self.assertIn(f'res://player/characters/{role}.tres', scene)
card = source('ui/menu/character_card.gd')
self.assertIn('frames.get_frame_texture(&"idle", 0)', card)
self.assertEqual(source('ui/menu/character_card.tscn').count('mouse_filter = 2'), 5)
def test_menu_waits_for_character_and_has_back_and_failure_paths(self):
menu = source('ui/menu/main_menu.gd')
self.assertIn('button.pressed.connect(_show_characters.bind(path))', menu)
self.assertIn('_load_level(_selected_level_path, character)', menu)
self.assertIn('session.begin_level(path, character)', menu)
select = menu.split('func _show_characters(', 1)[1].split('\n\nfunc ', 1)[0]
self.assertNotIn('load_threaded_request', select)
self.assertGreaterEqual(menu.count('if characters_panel.visible:'), 2)
error = menu.split('func _show_load_error(', 1)[1].split('\n\nfunc ', 1)[0]
self.assertIn('session.clear()', error)
self.assertIn('_show_characters(_selected_level_path)', error)
def test_ephemeral_selection_does_not_change_the_save_format(self):
session = source('game/run_session.gd')
for name in ('FileAccess', 'user://', 'JSON', 'PlayerProgress', 'unlock_items'):
self.assertNotIn(name, session)
self.assertIn('ancestor.scene_file_path == level_path', session)
player = source('player/player.gd')
self.assertLess(player.index('session.character_for(self)'), player.index('current_health = get_max_health()'))
self.assertLess(player.index('character_data = selected'), player.index('_setup_attack_hitboxes()'))
self.assertNotIn('reload_current_scene()', player.split('func _die()', 1)[1].split('func _update_timers(', 1)[0])
self.assertIn('session.begin_level(_next_level_path, character)', source('ui/menu/level_navigation.gd'))
self.assertIn('SAVE_VERSION: int = 1', source('game/player_progress.gd'))
self.assertIn('res://player/characters/guitarist.tres', source('player/player.tscn'))
if __name__ == '__main__':
unittest.main()