"""Contratos estaticos de la banda. No ejecutan GDScript ni simulan la fisica.""" from pathlib import Path import re import unittest import xml.etree.ElementTree as ET ROOT = Path(__file__).resolve().parents[1] ROLES = ('guitarist', 'drummer', 'bassist', 'singer') NAMES = ('Diego', 'Ivan', 'Fer', 'Hector') SVG_NS = '{http://www.w3.org/2000/svg}' def source(path): return (ROOT / path).read_text(encoding='utf-8') def cell_groups(path): return {group.attrib['id']: group for group in ET.parse(ROOT / path).getroot().findall(SVG_NS + 'g')} 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 = 390.0', 'jump_velocity = -600.0', 'basic_attack_damage = 5'): self.assertIn(stat, data) player = source('player/player.gd') 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: atlas = ET.parse(ROOT / f'assets/characters/band/{role}.svg').getroot() self.assertEqual((atlas.attrib['width'], atlas.attrib['height']), ('512', '320')) self.assertEqual(atlas.attrib['shape-rendering'], 'geometricPrecision') self.assertFalse(list(atlas.iter(SVG_NS + 'image'))) self.assertFalse(list(atlas.iter(SVG_NS + 'text'))) text = source(f'player/characters/animations/{role}_frames.tres') self.assertEqual(set(re.findall(r'"name": &"([^"]+)"', text)), expected_names) declared = re.findall(r'\[sub_resource type="AtlasTexture" id="([^"]+)"\]', text) self.assertEqual(len(declared), 40) self.assertEqual(set(declared), set(re.findall(r'SubResource\("([^"]+)"\)', text))) self.assertEqual(set(declared), set(cell_groups(f'assets/characters/band/{role}.svg'))) for x, y, w, h in re.findall(r'region = Rect2\((\d+), (\d+), (\d+), (\d+)\)', text): x, y, w, h = map(int, (x, y, w, h)) self.assertEqual((w, h), (64, 64)) self.assertLessEqual(x+w, 512) self.assertLessEqual(y+h, 320) 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): generator = source('tools/generate_vector_character_art.py') # Rasgos visibles y paletas propias, no solo cambios de nombre en los SVG. for token in ('Barba abundante', 'Chaleco vaquero oscuro', 'Camiseta negra', 'Rizo pequeño', 'Chaqueta negra con solapas', 'count = 4 if is_bass else 6'): self.assertIn(token, generator) guitarist = source('assets/characters/band/guitarist.svg') bassist = source('assets/characters/band/bassist.svg') drummer = source('assets/characters/band/drummer.svg') singer = source('assets/characters/band/singer.svg') self.assertIn('Diego', guitarist) self.assertIn('Fer', bassist) self.assertIn('Iván', drummer) self.assertIn('Héctor', singer) # El instrumento aparece en las poses especiales, no en el idle. for role in ROLES: groups = cell_groups(f'assets/characters/band/{role}.svg') idle_paths = list(groups['idle_0'].iter(SVG_NS + 'path')) special_paths = list(groups['special_0'].iter(SVG_NS + 'path')) self.assertGreater(len(special_paths), len(idle_paths), role) self.assertIn('Dos baquetas cruzadas', generator) self.assertIn('nunca aparecen en Fer', generator) self.assertIn('verde de cuatro cuerdas', source('assets/characters/band/README.md')) def test_vector_walk_uses_six_distinct_leg_contacts(self): # Ninguna celda conserva los rectangulos originales; pasos con tobillo y rodilla. for role in ROLES: groups = cell_groups(f'assets/characters/band/{role}.svg') paths = [] for i in range(6): group = groups[f'walk_{i}'] paths.append(group.find(SVG_NS+'path').attrib['d']) self.assertTrue(any('url(#jacket)' in str(node.attrib) for node in group.iter(SVG_NS+'path')), role) self.assertGreaterEqual(len(set(paths)), 5, role) self.assertIn('def draw_shoe(', source('tools/generate_vector_character_art.py')) self.assertIn('def pose_parameters(', source('tools/generate_vector_character_art.py')) 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_colored_polygon(dome', 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()