"""Geometry/resource contracts; runtime tests cover real physics and input.""" from pathlib import Path import re import unittest ROOT = Path(__file__).resolve().parents[1] def read(path): return (ROOT / path).read_text(encoding='utf-8') class CrouchResources(unittest.TestCase): def test_high_punch_clears_crouch_but_not_standing(self): player = read('player/player.gd') walker = read('enemies/walker/walker.gd') body_h = float(re.search(r'size = Vector2\(26, (\d+)\)', read('player/player.tscn'))[1]) ratio = float(re.search(r'var crouch_height_ratio: float = ([\d.]+)', player)[1]) attack_y = float(re.search(r'var attack_start_offset: Vector2 = Vector2\(34.0, (-?[\d.]+)\)', walker)[1]) attack_h = float(re.search(r'size = Vector2\(32, (\d+)\)', read('enemies/walker/walker.tscn'))[1]) feet = body_h / 2 crouch_top = feet - body_h * ratio attack_bottom = attack_y + attack_h / 2 self.assertGreater(crouch_top, attack_bottom) self.assertGreater(attack_bottom, -feet) self.assertIn('attack_collision.shape.collide(', walker) # Taking damage itself must not branch on the crouch state. damage = player.split('func take_damage(', 1)[1].split('\nfunc ', 1)[0] self.assertNotIn('is_crouching', damage) def test_all_four_reuse_real_crouched_pose(self): for role in ('guitarist', 'drummer', 'bassist', 'singer'): frames = read(f'player/characters/animations/{role}_frames.tres') self.assertRegex(frames, r'"frames": \[\{"duration": 1\.0, "texture": SubResource\("land_0"\)\}\],\n"loop": true,\n"name": &"crouch"') def test_drop_excludes_only_actual_one_way_support(self): player = read('player/player.gd') drop = player.split('func _try_drop_through()', 1)[1].split('\nfunc ', 1)[0] restore = player.split('func _restore_platform_collisions()', 1)[1].split('\nfunc ', 1)[0] self.assertIn('test_move(global_transform', drop) self.assertIn('not platform.one_way', drop) self.assertIn('add_collision_exception_with(platform)', drop) self.assertNotIn('collision_mask =', drop) self.assertNotIn('set_collision_mask_value', drop) self.assertIn('coyote_timer = 0.0', drop) self.assertIn('remove_collision_exception_with(platform)', restore) self.assertIn('intersects(standing_bounds', restore) self.assertIn('one_way = true', read('world/terrain/platform.tscn')) self.assertNotIn('one_way = true', read('world/terrain/ground.tscn')) def test_down_input_already_exists_and_is_released(self): mobile = read('ui/mobile_controls/mobile_controls.gd') self.assertIn('move_down={', read('project.godot')) self.assertIn('_set_direction(&"move_down", 1.0)', mobile) self.assertIn('Input.action_release(_direction_action)', mobile) self.assertIn('_set_direction(&"")', mobile) self.assertIn('joystick_crouch_release_at', mobile) if __name__ == '__main__': unittest.main()