extends SceneTree const BattleStateScript := preload("res://scripts/core/battle_state.gd") const BattleSceneScript := preload("res://scripts/scenes/battle_scene.gd") func _init() -> void: var failures: Array[String] = [] _check_deferred_move_events(failures) _check_scene_post_move_menu_flow(failures) if failures.is_empty(): print("post move action flow smoke ok") quit(0) return for failure in failures: push_error(failure) quit(1) func _check_deferred_move_events(failures: Array[String]) -> void: var state = BattleStateScript.new() if not state.load_battle("res://data/scenarios/001_yellow_turbans.json"): failures.append("could not load opening battle for pending move state") return var from_cell := Vector2i(1, 3) var to_cell := Vector2i(2, 3) state.battle_events.append({ "id": "pending_move_gold", "once": true, "when": { "type": "unit_reaches_tile", "unit_ids": ["cao_cao"], "pos": [to_cell.x, to_cell.y] }, "actions": [{"type": "grant_gold", "amount": 77}] }) if not state.select_unit("cao_cao"): failures.append("could not select Cao Cao for pending move state") return if not state.try_move_selected(to_cell, true): failures.append("tentative move should succeed") return var cao_cao: Dictionary = state.get_unit("cao_cao") if cao_cao.get("pos", Vector2i.ZERO) != to_cell: failures.append("tentative move should update position") if not bool(cao_cao.get("moved", false)) or bool(cao_cao.get("acted", false)): failures.append("tentative move should mark moved but not acted") if state.get_battle_gold_reward() != 0: failures.append("tentative move should defer unit_reaches_tile rewards") if not state.cancel_pending_move("cao_cao", from_cell, to_cell): failures.append("pending move cancel should succeed") cao_cao = state.get_unit("cao_cao") if cao_cao.get("pos", Vector2i.ZERO) != from_cell or bool(cao_cao.get("moved", false)) or bool(cao_cao.get("acted", false)): failures.append("pending move cancel should restore original action state") if state.get_battle_gold_reward() != 0: failures.append("canceled pending move should not fire movement event") if not state.try_move_selected(to_cell, true): failures.append("second tentative move should succeed") if not state.commit_pending_move_events("cao_cao"): failures.append("pending move commit should keep battle active") if state.get_battle_gold_reward() != 77: failures.append("pending move commit should fire deferred movement event") func _check_scene_post_move_menu_flow(failures: Array[String]) -> void: var scene = BattleSceneScript.new() scene._create_hud() if not scene.state.load_battle("res://data/scenarios/001_yellow_turbans.json"): failures.append("could not load opening battle for scene flow") scene.free() return scene.battle_started = true scene.campaign_complete_screen = false scene.briefing_panel.visible = false scene.result_panel.visible = false scene._clear_pending_move_state() if not scene.state.select_unit("cao_cao"): failures.append("could not select Cao Cao for scene flow") scene.free() return scene._refresh_ranges() scene._handle_board_click(_screen_for_cell(Vector2i(2, 3))) var cao_cao: Dictionary = scene.state.get_unit("cao_cao") if not scene._has_pending_move(): failures.append("scene should keep pending move metadata after move click") if scene.post_move_menu == null or not scene.post_move_menu.visible: failures.append("post-move action menu should be visible after moving") if cao_cao.get("pos", Vector2i.ZERO) != Vector2i(2, 3) or not bool(cao_cao.get("moved", false)) or bool(cao_cao.get("acted", false)): failures.append("scene move should be pending with action still available") if scene.state.get_selected_unit().is_empty(): failures.append("scene should keep moved unit selected for follow-up action") if not scene.attack_cells.is_empty(): failures.append("attack cells should wait until Attack is chosen from the post-move menu") scene._handle_cancel_input() cao_cao = scene.state.get_unit("cao_cao") if scene._has_pending_move() or (scene.post_move_menu != null and scene.post_move_menu.visible): failures.append("right-click cancel handler should clear pending move menu state") if cao_cao.get("pos", Vector2i.ZERO) != Vector2i(1, 3) or bool(cao_cao.get("moved", false)) or bool(cao_cao.get("acted", false)): failures.append("right-click cancel handler should restore the starting cell") scene._refresh_ranges() scene._handle_board_click(_screen_for_cell(Vector2i(2, 3))) scene._on_post_move_wait_pressed() cao_cao = scene.state.get_unit("cao_cao") if cao_cao.get("pos", Vector2i.ZERO) != Vector2i(2, 3) or not bool(cao_cao.get("moved", false)) or not bool(cao_cao.get("acted", false)): failures.append("post-move Wait should commit movement and end the unit action") if not scene.state.get_selected_unit().is_empty() or scene._has_pending_move(): failures.append("post-move Wait should clear selection and pending metadata") scene.free() func _screen_for_cell(cell: Vector2i) -> Vector2: return BattleSceneScript.BOARD_OFFSET + Vector2(cell.x, cell.y) * BattleSceneScript.TILE_SIZE + Vector2.ONE * (BattleSceneScript.TILE_SIZE * 0.5)