-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.py
More file actions
411 lines (352 loc) · 18.1 KB
/
templates.py
File metadata and controls
411 lines (352 loc) · 18.1 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
import json
from pathlib import Path
from typing import Dict, List, Tuple, Optional
from actions import Action
from images import Img, MatchingResult
BASE_PATH = Path(__file__).parent
class TemplateManager:
OFFLINE_EARNING_CLOSE_BOX = 'offline_earnings_close_box'
# CLOUD_SAVE_FOUND_CHOOSE_BOX = 'cloud_save_found_choose_box'
SETUP_GEAR_APPEAR = 'setup_gear_appear'
AWAY_EARN_CLOSE_BOX = 'away_earn_close_box'
# END_OF_RACE_CLOSE_BOX = 'end_of_race_box'
UPGRADE_SKILL_BUTTON = 'upgrade_skill_button'
SERVE_BOX = 'serve_box'
UPGRADABLE_FOOD_FACTORY_ICON = 'found_upgradable_food_factory'
FOOD_UPGRADE_COIN_ACTIVE = 'food_upgrade_coin_active'
UPGRADE_COIN_DEACTIVE = 'food_upgrade_coin_deactive'
REACH_TO_MAXIMUM_UPGRADE = 'reach_to_maximum_upgrade'
UNLOCK_FACTORY_TEXT = 'unlock_factory_text'
BUY_FOOD_FACTORY_COIN = 'buy_food_factory_coin'
GO_TO_NEXT_STAGE = 'go_to_next_stage'
BUY_NEXT_STAGE = 'buy_next_stage'
ON_NEW_STAGE_INTRO = 'on_new_stage_intro'
ON_NEW_STAGE_INTRO2 = 'on_new_stage_intro2'
GOOGLE_AD_TIMER = 'google_ad_timer'
GOOGLE_AD_SKIP = 'google_ad_skip'
GOOGLE_AD_EXIT = 'google_ad_exit'
GOOGLE_AD_MISS_CLICK = 'google_ad_miss_click'
MAX_LEVEL_25 = 'max_level_25'
MAX_LEVEL_50 = 'max_level_50'
MAX_LEVEL_75 = 'max_level_75'
MAX_LEVEL_150 = 'max_level_150'
MAX_LEVEL_250 = 'max_level_250'
ACTIVE_SKILL_SELECT_BUTTON = 'active_skill_select_button'
ACTIVE_SKILL_SELECT_TEXT = 'active_skill_select_text'
templates : Dict[str, Dict[str, List]]= {
OFFLINE_EARNING_CLOSE_BOX: {
'templates' : [
BASE_PATH / 'images' / 'templates' / 'offline_earn_x_button.png',
],
'actions': [ Action.click_center() ]
},
SETUP_GEAR_APPEAR: {
'templates' : [
BASE_PATH / 'images' / 'templates' / 'menu_gear_1.png',
],
'actions': []
},
AWAY_EARN_CLOSE_BOX: {
'templates' : [
BASE_PATH / 'images' / 'templates' / 'away_x_button.png',
],
'actions': [ Action.click_center() ]
},
################################################################################################################
#
################################################################################################################
MAX_LEVEL_25: {'templates' : [BASE_PATH / 'images' / 'templates' / 'map_25.png'], 'actions': []},
MAX_LEVEL_50: {'templates' : [BASE_PATH / 'images' / 'templates' / 'map_50.png'], 'actions': []},
MAX_LEVEL_75: {'templates' : [BASE_PATH / 'images' / 'templates' / 'map_75.png'], 'actions': []},
MAX_LEVEL_150: {'templates' : [BASE_PATH / 'images' / 'templates' / 'map_150.png'], 'actions': []},
MAX_LEVEL_250: {'templates' : [BASE_PATH / 'images' / 'templates' / 'map_250.png'], 'actions': []},
################################################################################################################
#
################################################################################################################
UPGRADE_SKILL_BUTTON: { # 우하단. 업그레이드 버튼
'templates': [
BASE_PATH / 'images' / 'templates' / 'skill_upgrade_1.png',
],
'actions':
[Action.click_abs(980, 2202)] + # 우하단 메뉴 버튼
[Action.click_abs(842, 954, 80)] * 10 + # 업글
[Action.click_abs(920, 778, 80)] # X 버튼
},
SERVE_BOX: { # 박스
'templates': [
BASE_PATH / 'images' / 'templates' / 'boxes.png',
],
'actions': [ Action.click_center(), ]
},
UPGRADABLE_FOOD_FACTORY_ICON: { # 빨간원 배경에 위를 가르키는 흰색 화살표
'templates': [
BASE_PATH / 'images' / 'templates' / 'factory_open_1.png',
],
'actions': [ Action.click_rb(x=40, y=80), ]
},
FOOD_UPGRADE_COIN_ACTIVE: { # 파랑 배경에 코인 (업그레이드) or Open
'templates': [
BASE_PATH / 'images' / 'templates' / 'factory_upgrade_gold_active.png',
],
'actions': [ Action.click_center(duration_ms=3000), ]
},
BUY_FOOD_FACTORY_COIN: { # 파랑 배경에 코인 (업그레이드) or Open
'templates': [
BASE_PATH / 'images' / 'templates' / 'factory_upgrade_gold_active.png',
],
'actions': [ Action.click_center(duration_ms=300), ]
},
UPGRADE_COIN_DEACTIVE: { # 회색 배경에 코인 (업그레이드) deactive (gold 부족)
'templates': [
BASE_PATH / 'images' / 'templates' / 'factory_upgrade_gold_deactive.png',
],
'actions': [ Action.click_center(duration_ms=2000), ]
},
UNLOCK_FACTORY_TEXT: { # 잠금 해제 text
'templates': [
BASE_PATH / 'images' / 'templates' / 'factory_unlock_text.png',
],
'actions': [ Action.click_center(duration_ms=500), ]
},
REACH_TO_MAXIMUM_UPGRADE: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'factory_upgrade_complete.png',
],
'actions': []
},
GO_TO_NEXT_STAGE: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'next_stage_can_go.png',
BASE_PATH / 'images' / 'templates' / 'next_stage_can_go_2.png',
],
'actions': [Action.click_lb(x=-20, y=-20)]
},
BUY_NEXT_STAGE: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'next_stage_remodeling.png',
BASE_PATH / 'images' / 'templates' / 'next_stage_remodeling_2.png',
],
'actions': [Action.click_center()]
},
ON_NEW_STAGE_INTRO: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'next_stage_new.png',
],
'actions': [Action.click_center()]
},
ON_NEW_STAGE_INTRO2: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'next_stage_new_2.png',
],
'actions': [Action.click_center()]
},
GOOGLE_AD_TIMER: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'ad_min.png',
BASE_PATH / 'images' / 'templates' / 'ad_sec.png',
],
'actions': [
# Action.click_abs(537, 2199)
]
},
GOOGLE_AD_SKIP: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'ad_skip_1.png',
BASE_PATH / 'images' / 'templates' / 'ad_skip_2.png',
BASE_PATH / 'images' / 'templates' / 'ad_skip_3.png',
BASE_PATH / 'images' / 'templates' / 'ad_skip_4.png',
],
'actions': [Action.click_center()]
},
GOOGLE_AD_EXIT: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'ad_exit_1.png',
BASE_PATH / 'images' / 'templates' / 'ad_exit_2.png',
BASE_PATH / 'images' / 'templates' / 'ad_exit_3.png',
],
'actions': [Action.click_center()]
},
GOOGLE_AD_MISS_CLICK: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'google_miss_click.png',
],
'actions': []
},
ACTIVE_SKILL_SELECT_BUTTON: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'active_skill_select.png',
],
'actions': [Action.click_center()]
},
ACTIVE_SKILL_SELECT_TEXT: {
'templates': [
BASE_PATH / 'images' / 'templates' / 'active_skill_select_text.png',
],
'actions': []
}
}
# ACTIVE_SKILL_SELECT_BUTTON = 'active_skill_select_button'
# ACTIVE_SKILL_SELECT_TEXT = 'active_skill_select_text'
images = {}
ranges = {}
def load_templates(self):
for key in self.templates:
for filepath in self.templates[key]['templates']:
p = str(filepath)
if p not in self.images:
self.images[p] = Img(filepath)
info_file = filepath.with_suffix('.json')
data = json.loads(info_file.read_text())
x, y = data['xy']
w, h = data['size']
self.ranges[p] = (x, y, x+w, y+h)
def _has_template(self, attr, key, capture_image: Tuple[Img, Img], threshold = 0.85) -> Tuple[bool, MatchingResult]:
for filepath in self.templates[key]['templates']:
p = str(filepath)
for target in capture_image:
result = None
if attr == 'png':
result = target.matching_png(self.images[p], self.ranges[p], threshold )
elif attr == 'gray':
result = target.matching_gray(self.images[p], self.ranges[p], threshold )
elif attr == 'hsv':
result = target.matching_hsv(self.images[p], self.ranges[p], threshold )
if result.is_found:
return True, result
return False, None
def _get_action(self, attr, key, capture_image: Tuple[Img, Img], threshold = 0.85) -> Tuple[List[Action], Optional[MatchingResult]]:
ret, result = self._has_template(attr, key, capture_image, threshold)
if ret:
return self.templates[key]['actions'], result
return [], None
def get_actions_offline_earning_close_box(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('png', self.OFFLINE_EARNING_CLOSE_BOX, capture_image)
# def get_actions_need_to_restart_client(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
# return self._get_action('png', self.NEED_TO_RESTART_CLIENT, capture_image)
def get_actions_away_earn_close_box(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('png', self.AWAY_EARN_CLOSE_BOX, capture_image)
# def get_actions_end_of_race_close_box(self, capture_image: Img ) -> Tuple[List[Action], Optional[MatchingResult]]:
# return self._get_action('png', self.END_OF_RACE_CLOSE_BOX, capture_image)
def has_setup_gear_menu(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.SETUP_GEAR_APPEAR, capture_image)
return ret
def get_actions_upgrade_skill_button(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('png', self.UPGRADE_SKILL_BUTTON, capture_image)
def has_upgrade_skill_button(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.UPGRADE_SKILL_BUTTON, capture_image)
return ret
def get_actions_serve_box(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('gray', self.SERVE_BOX, capture_image)
def has_serve_box(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('gray', self.SERVE_BOX, capture_image)
return ret
def get_actions_upgradable_food_factory_icon(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('gray', self.UPGRADABLE_FOOD_FACTORY_ICON, capture_image)
def has_upgradable_food_factory_icon(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('gray', self.UPGRADABLE_FOOD_FACTORY_ICON, capture_image)
return ret
def get_actions_upgrade_coin_active(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('png', self.FOOD_UPGRADE_COIN_ACTIVE, capture_image)
def has_upgrade_coin_active(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.FOOD_UPGRADE_COIN_ACTIVE, capture_image)
return ret
def get_actions_buy_food_factory_coin(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('png', self.BUY_FOOD_FACTORY_COIN, capture_image)
def has_buy_food_factory_coin(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.BUY_FOOD_FACTORY_COIN, capture_image)
return ret
def get_actions_upgrade_coin_deactive(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('png', self.UPGRADE_COIN_DEACTIVE, capture_image)
def has_upgrade_coin_deactive(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.UPGRADE_COIN_DEACTIVE, capture_image)
return ret
def get_actions_unlock_factory_text(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('png', self.UNLOCK_FACTORY_TEXT, capture_image)
def has_unlock_factory_text(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.UNLOCK_FACTORY_TEXT, capture_image)
return ret
def get_actions_reach_to_maximum_upgrade(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('png', self.REACH_TO_MAXIMUM_UPGRADE, capture_image)
def has_reach_to_maximum_upgrade(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.REACH_TO_MAXIMUM_UPGRADE, capture_image)
return ret
def get_actions_go_to_next_stage(self, capture_image: Tuple[Img, Img] ) -> Tuple[List[Action], Optional[MatchingResult]]:
"""
좌하단 업글 버튼
:param capture_image:
:return:
"""
return self._get_action('hsv', self.GO_TO_NEXT_STAGE, capture_image)
def has_go_to_next_stage(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.GO_TO_NEXT_STAGE, capture_image)
return ret
def get_actions_buy_new_stage(self, capture_image: Tuple[Img, Img]) -> Tuple[List[Action], Optional[MatchingResult]]:
"""
gold로 이동
:param capture_image:
:return:
"""
return self._get_action('png', self.BUY_NEXT_STAGE, capture_image)
def has_buy_new_stage(self, capture_image: Tuple[Img, Img]) -> bool:
ret, _ = self._has_template('png', self.BUY_NEXT_STAGE, capture_image)
return ret
def get_actions_on_new_stage_intro2(self, capture_image: Tuple[Img, Img]) -> Tuple[List[Action], Optional[MatchingResult]]:
"""
intro
:param capture_image:
:return:
"""
return self._get_action('png', self.ON_NEW_STAGE_INTRO2, capture_image)
def has_on_new_stage_intro2(self, capture_image: Tuple[Img, Img]) -> bool:
ret, _ = self._has_template('png', self.ON_NEW_STAGE_INTRO2, capture_image)
return ret
def get_actions_on_new_stage_intro(self, capture_image: Tuple[Img, Img]) -> Tuple[List[Action], Optional[MatchingResult]]:
"""
intro
:param capture_image:
:return:
"""
return self._get_action('png', self.ON_NEW_STAGE_INTRO, capture_image)
def has_on_new_stage_intro(self, capture_image: Tuple[Img, Img]) -> bool:
ret, _ = self._has_template('png', self.ON_NEW_STAGE_INTRO, capture_image)
return ret
def get_actions_google_ad_timer(self, capture_image: Tuple[Img, Img]) -> Tuple[List[Action], Optional[MatchingResult]]:
"""
intro
:param capture_image:
:return:
"""
return self._get_action('gray', self.GOOGLE_AD_TIMER, capture_image)
def get_actions_google_ad_skip(self, capture_image: Tuple[Img, Img]) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('gray', self.GOOGLE_AD_SKIP, capture_image)
def has_google_ad_skip(self, capture_image: Tuple[Img, Img]) -> bool:
ret, _ = self._has_template('gray', self.GOOGLE_AD_SKIP, capture_image)
return ret
def get_actions_google_ad_exit(self, capture_image: Tuple[Img, Img]) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('gray', self.GOOGLE_AD_EXIT, capture_image)
def has_google_ad_exit(self, capture_image: Tuple[Img, Img]) -> bool:
ret, _ = self._has_template('gray', self.GOOGLE_AD_EXIT, capture_image)
return ret
def has_google_ad_miss_click(self, capture_image: Tuple[Img, Img]) -> bool:
ret, _ = self._has_template('gray', self.GOOGLE_AD_MISS_CLICK, capture_image)
return ret
def has_maximum_level_25(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.MAX_LEVEL_25, capture_image)
return ret
def has_maximum_level_50(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.MAX_LEVEL_50, capture_image)
return ret
def has_maximum_level_75(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.MAX_LEVEL_75, capture_image)
return ret
def has_maximum_level_150(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.MAX_LEVEL_150, capture_image)
return ret
def has_maximum_level_250(self, capture_image: Tuple[Img, Img] ) -> bool:
ret, _ = self._has_template('png', self.MAX_LEVEL_250, capture_image)
return ret
def get_actions_active_skill_select_button(self, capture_image: Tuple[Img, Img]) -> Tuple[List[Action], Optional[MatchingResult]]:
return self._get_action('png', self.ACTIVE_SKILL_SELECT_BUTTON, capture_image)
def has_active_skill_select_button(self, capture_image: Tuple[Img, Img]) -> bool:
ret, _ = self._has_template('png', self.ACTIVE_SKILL_SELECT_BUTTON, capture_image)
return ret