Merge pull request #22 from Driver-C/update/synthesize_optimization

Upd: synthesize optimization
This commit is contained in:
LmeSzinc 2023-06-21 01:07:16 +08:00 committed by GitHub
commit 812088d522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 104 additions and 29 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -233,6 +233,16 @@ MENU_GOTO_SYNTHESIZE = ButtonWrapper(
button=(994, 389, 1035, 424),
),
)
MENU_SCROLL = ButtonWrapper(
name='MENU_SCROLL',
share=Button(
file='./assets/share/base/page/MENU_SCROLL.png',
area=(1178, 261, 1184, 681),
search=(1158, 241, 1204, 701),
color=(100, 100, 105),
button=(1178, 261, 1184, 681),
),
)
MESSAGE_CLOSE = ButtonWrapper(
name='MESSAGE_CLOSE',
share=Button(

View File

@ -15,8 +15,8 @@ ITEM_CONSUMABLE_CHECK = ButtonWrapper(
)
ITEM_CONSUMABLE_SCROLL = ButtonWrapper(
name='ITEM_CONSUMABLE_SCROLL',
cn=Button(
file='./assets/cn/daily/consumable_usage/ITEM_CONSUMABLE_SCROLL.png',
share=Button(
file='./assets/share/daily/consumable_usage/ITEM_CONSUMABLE_SCROLL.png',
area=(837, 89, 843, 615),
search=(817, 69, 863, 635),
color=(118, 117, 121),

View File

@ -73,6 +73,26 @@ RECIPE_UNLOCK = ButtonWrapper(
button=(836, 647, 913, 668),
),
)
SIMPLE_PROTECTIVE_GEAR = ButtonWrapper(
name='SIMPLE_PROTECTIVE_GEAR',
share=Button(
file='./assets/share/daily/synthesize_consumable/SIMPLE_PROTECTIVE_GEAR.png',
area=(244, 356, 316, 409),
search=(119, 84, 437, 573),
color=(94, 110, 115),
button=(244, 356, 316, 409),
),
)
SIMPLE_PROTECTIVE_GEAR_CHECK = ButtonWrapper(
name='SIMPLE_PROTECTIVE_GEAR_CHECK',
share=Button(
file='./assets/share/daily/synthesize_consumable/SIMPLE_PROTECTIVE_GEAR_CHECK.png',
area=(578, 196, 692, 256),
search=(558, 176, 712, 276),
color=(107, 106, 108),
button=(578, 196, 692, 256),
),
)
SYNTHESIZE_CONFIRM = ButtonWrapper(
name='SYNTHESIZE_CONFIRM',
cn=Button(
@ -83,16 +103,6 @@ SYNTHESIZE_CONFIRM = ButtonWrapper(
button=(847, 645, 895, 672),
),
)
SYNTHESIZE_CONFIRM_POPUP = ButtonWrapper(
name='SYNTHESIZE_CONFIRM_POPUP',
cn=Button(
file='./assets/cn/daily/synthesize_consumable/SYNTHESIZE_CONFIRM_POPUP.png',
area=(770, 476, 857, 506),
search=(750, 456, 877, 526),
color=(176, 175, 172),
button=(770, 476, 857, 506),
),
)
SYNTHESIZE_CONSUMABLES_CHECK = ButtonWrapper(
name='SYNTHESIZE_CONSUMABLES_CHECK',
share=Button(
@ -113,3 +123,13 @@ SYNTHESIZE_GOTO_CONSUMABLES = ButtonWrapper(
button=(38, 120, 78, 141),
),
)
SYNTHESIZE_SCROLL = ButtonWrapper(
name='SYNTHESIZE_SCROLL',
share=Button(
file='./assets/share/daily/synthesize_consumable/SYNTHESIZE_SCROLL.png',
area=(458, 80, 464, 628),
search=(438, 60, 484, 648),
color=(134, 130, 144),
button=(458, 80, 464, 628),
),
)

View File

@ -2,13 +2,20 @@ from module.ocr.ocr import *
from module.ui.scroll import Scroll
from tasks.base.page import page_item
from tasks.base.ui import UI
from tasks.daily.synthesize import SynthesizeConsumablesUI
from tasks.base.assets.assets_base_popup import CONFIRM_POPUP
from tasks.daily.assets.assets_daily_consumable_usage import *
from tasks.daily.assets.assets_daily_synthesize_consumable import \
SIMPLE_PROTECTIVE_GEAR as SYNTHESIZE_SIMPLE_PROTECTIVE_GEAR, \
SIMPLE_PROTECTIVE_GEAR_CHECK as SYNTHESIZE_SIMPLE_PROTECTIVE_GEAR_CHECK
class ConsumableUsageUI(UI):
def use_consumable(self) -> bool:
def use_consumable(self, synthesize_or_not: bool = True) -> bool:
"""
Args:
synthesize_or_not(bool):
Returns:
bool: If success
@ -25,7 +32,15 @@ class ConsumableUsageUI(UI):
self._confirm_use()
return True
else:
return False
# Prevent matching errors from causing continuous synthesis of consumables
if not synthesize_or_not:
return False
if SynthesizeConsumablesUI(self.config, self.device).synthesize_consumables(
SYNTHESIZE_SIMPLE_PROTECTIVE_GEAR, SYNTHESIZE_SIMPLE_PROTECTIVE_GEAR_CHECK
):
return self.use_consumable(synthesize_or_not=False)
else:
return False
def _switch_tag_to_consumables(self, skip_first_screenshot=True):
while 1:

View File

@ -4,6 +4,8 @@ from tasks.base.assets.assets_base_page import MENU_CHECK, SYNTHESIZE_CHECK
from tasks.base.assets.assets_base_popup import GET_REWARD
from tasks.base.page import Page, page_menu, page_synthesize
from tasks.base.ui import UI
from tasks.base.assets.assets_base_page import MENU_SCROLL
from tasks.base.assets.assets_base_popup import CONFIRM_POPUP
from tasks.daily.assets.assets_daily_synthesize_consumable import *
@ -25,10 +27,10 @@ class SynthesizeUI(UI):
match page:
case page_menu.name:
check_image = MENU_CHECK
scroll = Scroll((1177, 261, 1183, 682), color=(191, 191, 191), name='MENU_SCROLL')
scroll = Scroll(MENU_SCROLL.button, color=(191, 191, 191), name=MENU_SCROLL.name)
case page_synthesize.name:
check_image = SYNTHESIZE_CHECK
scroll = Scroll((458, 80, 463, 662), color=(210, 210, 210), name='SYNTHESIZE_SCROLL')
scroll = Scroll(SYNTHESIZE_SCROLL.button, color=(210, 210, 210), name=SYNTHESIZE_SCROLL.name)
case _:
logger.info(f'No page matched, just skip')
return
@ -57,8 +59,13 @@ class SynthesizeUI(UI):
class SynthesizeConsumablesUI(SynthesizeUI):
def synthesize_consumables(self) -> bool:
def synthesize_consumables(self, target_button: ButtonWrapper = None,
target_button_check: ButtonWrapper = None) -> bool:
"""
Args:
target_button(ButtonWrapper):
target_button_check(ButtonWrapper):
Returns:
bool:
@ -67,6 +74,7 @@ class SynthesizeConsumablesUI(SynthesizeUI):
self.device.screenshot()
result = self.synthesize_consumables()
"""
logger.hr('Synthesize consumables', level=2)
# If the current page is not the menu page,
# the menu scroll bar must be at the top when opening the menu page from other page,
@ -76,7 +84,7 @@ class SynthesizeConsumablesUI(SynthesizeUI):
self.ui_ensure(page_synthesize)
self._switch_tag_to_consumables()
self.ensure_scroll_top(page=page_synthesize)
if self._select_items():
if self._search_and_select_items(target_button, target_button_check):
self._open_synthesize_popup()
self._synthesize_confirm()
self._back_to_synthesize_page()
@ -99,15 +107,10 @@ class SynthesizeConsumablesUI(SynthesizeUI):
logger.info('Switch to consumables subpage')
continue
def _select_items(self) -> bool:
candidate_items = {
CONSUMABLES_TRICK_SNACK: CONSUMABLES_TRICK_SNACK_CHECK,
CONSUMABLES_COMFORT_FOOD: CONSUMABLES_COMFORT_FOOD_CHECK,
CONSUMABLES_SIMPLE_AED: CONSUMABLES_SIMPLE_AED_CHECK
}
def _select_items(self, candidate_items: dict[ButtonWrapper, ButtonWrapper]) -> bool:
for item, item_check in candidate_items.items():
# Determine if the "item" can be found and synthesized in the left item column
if item.match_template_color(self.device.image):
if item.match_template_color(self.device.image, similarity=0.7):
logger.info('Find an item that can be synthesized')
# Ensure that item is selected
skip_first_screenshot = True
@ -119,12 +122,39 @@ class SynthesizeConsumablesUI(SynthesizeUI):
if self.appear(item_check):
logger.info('Consumables that can be synthesized have been selected')
return True
if self.appear_then_click(item):
if self.appear_then_click(item, similarity=0.7):
continue
else:
logger.info('There are no suitable items to synthesize')
return False
def _search_and_select_items(self, target_button: ButtonWrapper = None,
target_button_check: ButtonWrapper = None) -> bool:
candidate_items = {target_button: target_button_check} if target_button and target_button_check else {
CONSUMABLES_TRICK_SNACK: CONSUMABLES_TRICK_SNACK_CHECK,
CONSUMABLES_COMFORT_FOOD: CONSUMABLES_COMFORT_FOOD_CHECK,
CONSUMABLES_SIMPLE_AED: CONSUMABLES_SIMPLE_AED_CHECK
}
# Search target button from top to bottom
scroll = Scroll(SYNTHESIZE_SCROLL.button, color=(210, 210, 210), name=SYNTHESIZE_SCROLL.name)
if scroll.appear(main=self):
skip_first_screenshot = True
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if self._select_items(candidate_items):
return True
if scroll.at_bottom(main=self):
logger.info('There are no suitable items to synthesize')
return False
if not scroll.at_bottom(main=self):
scroll.next_page(main=self)
continue
else:
return self._select_items(candidate_items)
def _open_synthesize_popup(self, skip_first_screenshot=True):
while 1:
if skip_first_screenshot:
@ -132,7 +162,7 @@ class SynthesizeConsumablesUI(SynthesizeUI):
else:
self.device.screenshot()
if self.appear(SYNTHESIZE_CONFIRM_POPUP):
if self.appear(CONFIRM_POPUP):
logger.info('Synthesize confirm popup window appear')
break
# The recipe of the item has not been unlocked yet, but it can be unlocked now
@ -156,7 +186,7 @@ class SynthesizeConsumablesUI(SynthesizeUI):
logger.info('Synthesize consumable completed')
break
# Synthesize confirm
if self.appear_then_click(SYNTHESIZE_CONFIRM_POPUP):
if self.appear_then_click(CONFIRM_POPUP):
logger.info('Click the confirm button')
continue