forked from AdriaGual/pokemon-pocket-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
78 lines (65 loc) · 2.73 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# src/bot.py
import os
from controllers.battle_controller import BattleController
from controllers.emulator_controller import EmulatorController
from controllers.game_controller import GameController
from models.game_state import GameState
from services.card_data_service import CardDataService
from services.card_recognition_service import CardRecognitionService
from utils.image_utils import ImageProcessor
from utils.loaders import load_all_cards, load_template_images
class PokemonBot:
def __init__(self, app_state, log_callback, ui_instance):
self.app_state = app_state
self.log_callback = log_callback
self.ui_instance = ui_instance
self.debug_window = ui_instance.debug_window
try:
self.log_callback("🔄 Initializing bot components...")
# Load images
self.template_images = load_template_images("images")
images_cards_folder = "images/cards"
if not os.path.exists(images_cards_folder):
os.makedirs(images_cards_folder)
self.log_callback("📁 Created cards folder")
self.card_images = load_all_cards(images_cards_folder)
self.log_callback(f"📦 Loaded {len(self.card_images)} card images")
# Initialize services
self.card_data_service = CardDataService()
self.image_processor = ImageProcessor(self.log_callback, self.debug_window)
self.battle_controller = BattleController(
self.image_processor,
self.template_images,
self.card_images,
self.log_callback,
)
self.game_state = GameState()
self.emulator_controller = EmulatorController(
self.app_state, self.log_callback
)
self.card_recognition_service = CardRecognitionService(
self.image_processor,
self.card_data_service,
self.ui_instance,
self.log_callback,
self.card_images,
)
self.game_controller = GameController(
self.app_state,
self.emulator_controller,
self.battle_controller,
self.image_processor,
self.card_recognition_service,
self.game_state,
self.template_images,
self.log_callback,
self.debug_window,
)
self.log_callback("✅ Bot initialization complete")
except Exception as e:
self.log_callback(f"❌ Bot initialization failed: {e!s}")
raise
def start(self):
self.game_controller.start()
def stop(self):
self.game_controller.stop()