extends GutTest const ActorState = preload("res://scripts/domain/actor_state.gd") const CompanionState = preload("res://scripts/domain/entities/companion_state.gd") const GameScene = preload("res://scenes/Game.tscn") const RunSettings = preload("res://scripts/domain/run/run_settings.gd") var game: Game func before_each() -> void: game = GameScene.instantiate() game.configure_new_run(RunSettings.new("E4-PET-E2E", &"crawler", false, true), "Pet Tester") add_child_autofree(game) await get_tree().process_frame await get_tree().process_frame func test_pet_choice_spawns_visible_companion_and_real_input_changes_command_stance() -> void: var companion := game.get_game_state().companion assert_not_null(companion) assert_true(companion.is_alive()) assert_not_null(game.get_node_or_null("World/Companion")) var panel := game.get_node("HUD/CompanionPanel") as PanelContainer assert_false(panel.visible) await _dispatch_key(KEY_K) assert_true(panel.visible) var panel_text := (panel.get_node("Body") as RichTextLabel).get_parsed_text() assert_string_contains(panel_text, "Reste en arrière") assert_string_contains(panel_text, "Défends-moi") assert_string_contains(panel_text, "Attaque à vue") await _dispatch_key(KEY_RIGHT) assert_eq(companion.stance, CompanionState.Stance.DEFEND_ME) assert_string_contains(String(game.get_run_state().recent_events(1)[0].kind), "companion_stance") await _dispatch_key(KEY_ESCAPE) assert_false(panel.visible) func test_companion_uses_the_temporary_dog_sprite() -> void: var companion_sprite := game.get_node("World/Companion") as Sprite2D assert_not_null(companion_sprite.texture) assert_string_contains(companion_sprite.texture.resource_path, "war_dog.png") func test_floor_transition_places_the_living_pet_next_to_the_player() -> void: var state := game.get_game_state() state.player.cell = state.floor_state.exit state.exit_reached = false game.get_run_state().current_floor_deadline().turns_remaining = 0 game.submit_player_action(preload("res://scripts/domain/run/player_action.gd").new(&"interact")) assert_eq(game.get_run_state().current_floor, 1) assert_lte(state.companion.actor.cell.distance_to(state.player.cell), 1.0) assert_ne(state.companion.actor.cell, state.player.cell) func test_live_enemy_attack_is_intercepted_in_support_and_companion_death_leaves_player_run_alive() -> void: var state := game.get_game_state() var companion := state.companion companion.actor.hit_points = 1 companion.actor.max_hit_points = 1 companion.actor.cell = state.player.cell + Vector2i.RIGHT assert_true(companion.set_stance(CompanionState.Stance.DEFEND_ME)) var enemy: ActorState = state.enemies.values()[0] enemy.cell = state.player.cell + Vector2i.LEFT enemy.weapon_damage = 20 enemy.attack_damage = 20 enemy.ai_behavior = &"aggressive" enemy.vision_range = 6 state.map.set_cell(state.player.cell + Vector2i.UP, GridMapState.CellKind.CHEST) await _dispatch_key(KEY_E) assert_eq(state.player.hit_points, state.player.max_hit_points) assert_false(companion.is_alive()) assert_not_null(game.get_node_or_null("World/Companion")) assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "companion") func _dispatch_key(keycode: Key) -> void: Input.parse_input_event(_key_event(keycode, true)) await get_tree().process_frame Input.parse_input_event(_key_event(keycode, false)) await get_tree().process_frame func _key_event(keycode: Key, pressed: bool) -> InputEventKey: var event := InputEventKey.new() event.keycode = keycode event.physical_keycode = keycode event.pressed = pressed return event