Fix async handling in game walkthrough script
- Add await to engine.execute_action() calls (energy attach and attack) - Update entry point to use asyncio.run() - Fix game creation result handling (use game_creation.game) - Fix AttachEnergyAction parameter name (energy_card_id)
This commit is contained in:
parent
cd8226c4e6
commit
9564916c87
@ -25,6 +25,7 @@ if str(backend_dir) not in sys.path:
|
||||
# IMPORTS
|
||||
# =============================================================================
|
||||
|
||||
import asyncio
|
||||
import uuid
|
||||
from typing import Callable
|
||||
|
||||
@ -525,7 +526,7 @@ def build_player2_deck(
|
||||
# =============================================================================
|
||||
|
||||
|
||||
def run_walkthrough():
|
||||
async def run_walkthrough():
|
||||
"""Run the interactive game walkthrough."""
|
||||
clear_screen()
|
||||
print_divider("*")
|
||||
@ -707,16 +708,17 @@ The engine will:
|
||||
"player2": p2_energy,
|
||||
}
|
||||
|
||||
game = engine.create_game(
|
||||
game_creation = engine.create_game(
|
||||
player_ids=["player1", "player2"],
|
||||
decks=decks,
|
||||
energy_decks=energy_decks,
|
||||
card_registry=card_registry,
|
||||
)
|
||||
game = game_creation.game
|
||||
|
||||
print_result(f"Game created! ID: {game.game_id[:8]}...")
|
||||
print_result(f"Turn order: {game.turn_order}")
|
||||
print_result(f"Current phase: {game.phase.value}")
|
||||
print_result(f"Game created! ID: {game_creation.game.game_id[:8]}...")
|
||||
print_result(f"Turn order: {game_creation.game.turn_order}")
|
||||
print_result(f"Current phase: {game_creation.game.phase.value}")
|
||||
|
||||
if not wait_for_continue():
|
||||
return
|
||||
@ -877,12 +879,12 @@ Let's attach energy to our active Pokemon!
|
||||
|
||||
# Create and execute attach energy action
|
||||
action = AttachEnergyAction(
|
||||
energy_instance_id=energy_card.instance_id,
|
||||
energy_card_id=energy_card.instance_id,
|
||||
target_pokemon_id=active_pokemon.instance_id,
|
||||
from_energy_zone=True,
|
||||
)
|
||||
|
||||
result = engine.execute_action(game, game.current_player_id, action)
|
||||
result = await engine.execute_action(game, game.current_player_id, action)
|
||||
|
||||
if result.success:
|
||||
print_result(
|
||||
@ -927,7 +929,7 @@ if it has enough energy attached.
|
||||
print_action(f"Using {chosen_attack.name}!")
|
||||
|
||||
action = AttackAction(attack_index=0)
|
||||
result = engine.execute_action(game, game.current_player_id, action)
|
||||
result = await engine.execute_action(game, game.current_player_id, action)
|
||||
|
||||
if result.success:
|
||||
print_result(f"Attack successful!")
|
||||
@ -1020,7 +1022,7 @@ until someone reaches 4 points (or another win condition is met).
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
run_walkthrough()
|
||||
asyncio.run(run_walkthrough())
|
||||
except KeyboardInterrupt:
|
||||
print("\n\nWalkthrough interrupted. Goodbye!")
|
||||
except Exception as e:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user