extends GutTest const ActorState = preload("res://scripts/domain/actor_state.gd") const GridMapState = preload("res://scripts/domain/grid_map_state.gd") const GameScene = preload("res://scenes/Game.tscn") func test_enemy_view_is_hidden_until_its_cell_enters_current_field_of_view() -> void: var game := GameScene.instantiate() as Game add_child_autofree(game) await get_tree().process_frame var state := game.get_game_state() state.enemies.clear() var enemy := ActorState.new(&"hidden_enemy", Vector2i(24, 8), 6, 2) state.enemies[enemy.id] = enemy game._sync_enemy_views() var view := game.enemy_views[enemy.id] as ActorView assert_false(state.visible_cells.has(enemy.cell)) assert_false(view.visible) enemy.cell = state.player.cell + Vector2i.RIGHT game.sync_presentation_for_testing() game._sync_enemy_views() assert_true(state.visible_cells.has(enemy.cell)) assert_true(view.visible) func test_real_game_enemy_detects_approaches_attacks_and_dies_with_feedback() -> void: var game := GameScene.instantiate() as Game add_child_autofree(game) await get_tree().process_frame var state := game.get_game_state() var enemy := ActorState.new(&"goblin", state.player.cell + Vector2i(3, 0), 3, 2) state.enemies[enemy.id] = enemy game._sync_enemy_views() enemy.cell = state.player.cell + Vector2i(3, 0) enemy.hit_points = 3 enemy.max_hit_points = 3 enemy.content_id = &"enemy_goblin" enemy.ai_behavior = &"aggressive" enemy.vision_range = 6 var approach := game.submit_test_action(Vector2i.DOWN) assert_eq(approach.map(func(result: TurnResult) -> StringName: return result.kind), [&"moved", &"enemy_moved"]) assert_eq(enemy.cell, state.player.cell + Vector2i(2, -1)) assert_ne(enemy.cell, state.player.cell) assert_eq((game.get_node("World/Enemies/Goblin") as ActorView).position, Vector2(enemy.cell * ActorView.TILE_SIZE)) # A real contextual action keeps the player in place, allowing the detected # enemy to execute its adjacent C2 melee turn. enemy.cell = state.player.cell + Vector2i.RIGHT state.map.set_cell(state.player.cell + Vector2i.UP, GridMapState.CellKind.CHEST) var attack := game.submit_test_interact() assert_eq(attack.map(func(result: TurnResult) -> StringName: return result.kind), [&"chest_opened", &"enemy_melee"]) assert_eq(state.player.hit_points, 10) var death := game.submit_test_action(Vector2i.RIGHT) assert_eq(death.map(func(result: TurnResult) -> StringName: return result.kind), [&"melee", &"enemy_defeated"]) assert_false(state.enemies.has(&"goblin")) await get_tree().create_timer(1.2).timeout assert_eq(game.get_node("World/Enemies").get_child_count(), 0) assert_string_contains(game.get_node("HUD/EventLog").get_parsed_text(), "Le gobelin est vaincu.")