mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-15 22:19:18 +00:00
Fix: Handle slow game startup and game died during startup (#61)
This commit is contained in:
parent
d3eef2cd24
commit
b29e95c1ea
BIN
assets/share/base/popup/POPUP_SINGLE.BUTTON.png
Normal file
BIN
assets/share/base/popup/POPUP_SINGLE.BUTTON.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.0 KiB |
BIN
assets/share/base/popup/POPUP_SINGLE.SEARCH.png
Normal file
BIN
assets/share/base/popup/POPUP_SINGLE.SEARCH.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
BIN
assets/share/base/popup/POPUP_SINGLE.png
Normal file
BIN
assets/share/base/popup/POPUP_SINGLE.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
BIN
assets/share/login/LOGIN_LOADING.png
Normal file
BIN
assets/share/login/LOGIN_LOADING.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
@ -65,3 +65,13 @@ MONTHLY_CARD_REWARD = ButtonWrapper(
|
||||
button=(741, 495, 1071, 644),
|
||||
),
|
||||
)
|
||||
POPUP_SINGLE = ButtonWrapper(
|
||||
name='POPUP_SINGLE',
|
||||
share=Button(
|
||||
file='./assets/share/base/popup/POPUP_SINGLE.png',
|
||||
area=(602, 458, 626, 482),
|
||||
search=(511, 365, 771, 575),
|
||||
color=(95, 90, 77),
|
||||
button=(578, 451, 705, 489),
|
||||
),
|
||||
)
|
||||
|
@ -47,3 +47,18 @@ class PopupHandler(ModuleBase):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def handle_popup_single(self, interval=2) -> bool:
|
||||
"""
|
||||
Popup with one single confirm button in the middle.
|
||||
|
||||
Args:
|
||||
interval:
|
||||
|
||||
Returns:
|
||||
If handled.
|
||||
"""
|
||||
if self.appear_then_click(POPUP_SINGLE, interval=interval):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
@ -13,6 +13,16 @@ LOGIN_CONFIRM = ButtonWrapper(
|
||||
button=(683, 327, 1143, 620),
|
||||
),
|
||||
)
|
||||
LOGIN_LOADING = ButtonWrapper(
|
||||
name='LOGIN_LOADING',
|
||||
share=Button(
|
||||
file='./assets/share/login/LOGIN_LOADING.png',
|
||||
area=(1103, 599, 1119, 616),
|
||||
search=(1083, 579, 1139, 636),
|
||||
color=(98, 98, 106),
|
||||
button=(1103, 599, 1119, 616),
|
||||
),
|
||||
)
|
||||
USER_AGREEMENT_ACCEPT = ButtonWrapper(
|
||||
name='USER_AGREEMENT_ACCEPT',
|
||||
cn=Button(
|
||||
|
@ -1,8 +1,9 @@
|
||||
from module.base.timer import Timer
|
||||
from module.exception import GameNotRunningError
|
||||
from module.logger import logger
|
||||
from tasks.base.page import page_main
|
||||
from tasks.base.ui import UI
|
||||
from tasks.login.assets.assets_login import LOGIN_CONFIRM, USER_AGREEMENT_ACCEPT
|
||||
from tasks.login.assets.assets_login import LOGIN_CONFIRM, USER_AGREEMENT_ACCEPT, LOGIN_LOADING
|
||||
|
||||
|
||||
class Login(UI):
|
||||
@ -15,13 +16,21 @@ class Login(UI):
|
||||
Raises:
|
||||
GameStuckError:
|
||||
GameTooManyClickError:
|
||||
GameNotRunningError:
|
||||
"""
|
||||
logger.hr('App login')
|
||||
|
||||
orientation_timer = Timer(5)
|
||||
startup_timer = Timer(5).start()
|
||||
app_timer = Timer(5).start()
|
||||
login_success = False
|
||||
|
||||
while 1:
|
||||
# Watch if game alive
|
||||
if app_timer.reached():
|
||||
if not self.device.app_is_running():
|
||||
logger.error('Game died during launch')
|
||||
raise GameNotRunningError('Game not running')
|
||||
app_timer.reset()
|
||||
# Watch device rotation
|
||||
if not login_success and orientation_timer.reached():
|
||||
# Screen may rotate after starting an app
|
||||
@ -31,27 +40,41 @@ class Login(UI):
|
||||
self.device.screenshot()
|
||||
|
||||
# End
|
||||
if self.ui_page_appear(page_main):
|
||||
logger.info('Login to main confirm')
|
||||
break
|
||||
# Game client requires at least 5s to start
|
||||
# The first few frames might be captured before app_stop(), ignore them
|
||||
if startup_timer.reached():
|
||||
if self.ui_page_appear(page_main):
|
||||
logger.info('Login to main confirm')
|
||||
break
|
||||
|
||||
# Watch resource downloading and loading
|
||||
if self.appear(LOGIN_LOADING, interval=5):
|
||||
logger.info('Game resources downloading or loading')
|
||||
self.device.stuck_record_clear()
|
||||
|
||||
# Login
|
||||
if self.appear_then_click(LOGIN_CONFIRM):
|
||||
login_success = True
|
||||
continue
|
||||
if self.appear_then_click(USER_AGREEMENT_ACCEPT):
|
||||
continue
|
||||
# Additional
|
||||
if self.handle_popup_single():
|
||||
continue
|
||||
if self.ui_additional():
|
||||
continue
|
||||
|
||||
return True
|
||||
|
||||
def handle_app_login(self):
|
||||
logger.info('handle_app_login')
|
||||
self.device.screenshot_interval_set(1.0)
|
||||
self.device.stuck_timer = Timer(300, count=300).start()
|
||||
try:
|
||||
self._handle_app_login()
|
||||
finally:
|
||||
self.device.screenshot_interval_set()
|
||||
self.device.stuck_timer = Timer(60, count=60).start()
|
||||
|
||||
def app_stop(self):
|
||||
logger.hr('App stop')
|
||||
|
Loading…
Reference in New Issue
Block a user