Fix: Handle popup before choosing games

This commit is contained in:
LmeSzinc 2023-09-28 16:04:27 +08:00
parent 0dcdab461e
commit c14976951f
2 changed files with 12 additions and 9 deletions

View File

@ -4,13 +4,14 @@ from module.minigame.assets import *
from module.ocr.ocr import Digit
from module.ui.assets import GAME_ROOM_CHECK
from module.ui.page import page_game_room
from module.ui.scroll import Scroll
from module.ui.ui import UI
OCR_COIN = Digit(COIN_HOLDER,
name='OCR_COIN',
letter=(255, 235, 115),
threshold=128)
MINIGAME_SCROLL = Scroll(MINIGAME_SCROLL_AREA, color=(247, 247, 247), name='MINIGAME_SCROLL')
class MinigameRun(UI):
@ -22,6 +23,9 @@ class MinigameRun(UI):
Return:
False if unable or unnecessary to play
"""
logger.hr('Minigame run', level=1)
logger.info("Enter minigame")
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
@ -30,19 +34,17 @@ class MinigameRun(UI):
# unable to get more ticket popup
if self.deal_popup():
continue
if self.appear(GOTO_CHOOSE_GAME, offset=(5, 5), interval=3):
logger.info("Enter minigame")
self.device.click(GOTO_CHOOSE_GAME)
if self.appear_then_click(GOTO_CHOOSE_GAME, offset=(5, 5), interval=3):
continue
if self.appear(GAME_ROOM_CHECK, offset=(5, 5)) \
and not self.appear(GOTO_CHOOSE_GAME, offset=(5, 5)):
and MINIGAME_SCROLL.appear(main=self):
break
logger.info("Choose minigame")
self.choose_game()
# try to add coins, if failed, skip play
add_coin_result = self.use_coin()
if add_coin_result:
logger.info("Play minigame")
logger.hr("Play minigame", level=2)
self.play_game()
logger.info("Exit minigame")
self.exit_game()

View File

@ -1,10 +1,9 @@
from module.base.timer import Timer
from module.logger import logger
from module.minigame.assets import *
from module.minigame.minigame import MinigameRun
from module.minigame.minigame import MINIGAME_SCROLL, MinigameRun
from module.ocr.ocr import Digit
from module.ui.page import page_game_room
from module.ui.scroll import Scroll
OCR_GAME_NEW_YEAR_COIN_COST = Digit(NEW_YEAR_CHALLENGE_COIN_COST_HOLDER,
name='OCR_GAME_NEW_YEAR_COIN_COST',
@ -14,7 +13,6 @@ OCR_NEW_YEAR_BATTLE_SCORE = Digit(NEW_YEAR_CHALLENGE_SCORE_HOLDER,
name='OCR_NEW_YEAR_BATTLE_SCORE',
letter=(231, 215, 82),
threshold=128)
MINIGAME_SCROLL = Scroll(MINIGAME_SCROLL_AREA, color=(247, 247, 247), name='MINIGAME_SCROLL')
class NewYearChallenge(MinigameRun):
@ -48,6 +46,9 @@ class NewYearChallenge(MinigameRun):
# entrance
if self.appear(NEW_YEAR_CHALLENGE_START, offset=(5, 5), interval=3):
break
# GOTO_CHOOSE_GAME -> choose game
if self.appear_then_click(GOTO_CHOOSE_GAME, offset=(5, 5), interval=3):
continue
# choose game
if self.appear(NEW_YEAR_CHALLENGE_ENTRANCE, offset=(5, 5), interval=3):
self.device.click(NEW_YEAR_CHALLENGE_ENTRANCE)