Skip to content

Commit

Permalink
Merge pull request #130 from sanmusen214/dev
Browse files Browse the repository at this point in the history
1.7.4
  • Loading branch information
sanmusen214 authored Nov 24, 2024
2 parents 30256d9 + 1026bcc commit 2714246
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 15 deletions.
25 changes: 23 additions & 2 deletions BAAH.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,16 @@ def BAAH_send_err_mail(e):
logging.error({"zh_CN": "发送邮件失败", "en_US": "Failed to send email"})
logging.error(eagain)

def BAAH_main():
def BAAH_main(run_precommand = True):
"""
执行BAAH主程序,在此之前config应该已经被单独import然后解析为用户指定的配置文件->随后再导入my_AllTask以及其他依赖config的模块
"""
try:
config.sessiondict["BAAH_START_TIME"] = time.strftime("%Y-%m-%d %H:%M:%S")
print_BAAH_info()
print_BAAH_config_info()
BAAH_run_pre_command()
if run_precommand:
BAAH_run_pre_command()
BAAH_release_adb_port()
BAAH_start_emulator()
BAAH_check_adb_connect()
Expand All @@ -329,6 +330,26 @@ def BAAH_main():
print_BAAH_config_info()
BAAH_auto_quit()

except EmulatorBlockError as ebe:
logging.info(istr({
CN: "模拟器卡顿,重启模拟器",
EN: "Emulator Blocked, Restart Emulator"
}))
if config.sessiondict["EMULATOR_PROCESS_PID"] is None:
raise Exception(istr({
CN: "无模拟器pid,无法重启模拟器,请确保模拟器由BAAH启动",
EN: "Cannot identify emulator's pid, fail to restart emulator, please make sure it is started by BAAH"
}))
# sessionstorage里重启次数加1
store_restart_times = config.sessiondict["RESTART_EMULATOR_TIMES"] + 1
BAAH_kill_emulator()
time.sleep(5)
# 重新加载其他config值,覆盖模拟器重启次数到sessiondict
config.parse_user_config(config.nowuserconfigname)
config.sessiondict["RESTART_EMULATOR_TIMES"] = store_restart_times
# 防止重复调用precommand
BAAH_main(run_precommand=False)


except Exception as e:
logging.error({"zh_CN": "运行出错", "en_US": "Error occurred"})
Expand Down
2 changes: 2 additions & 0 deletions DATA/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@
"config_craft_desc":"Currently, the craft task only supports one node and does not support the priority of specified items. After the Chinese server implements one-click manufacturing, it will be supported through one-click manufacturing",
"config_craft_max_times":"Maximum times of craft",
"desc_note":"Note",
"config_login_timeout":"Set timeout for logining the game (seconds)",
"config_max_emulator_restart_times": "Max emulator restart times when login timeout",

"config_server_jp": "Japanese Server",
"config_server_cn": "Chinese Official Server",
Expand Down
2 changes: 2 additions & 0 deletions DATA/i18n/jp_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@
"config_craft_desc":"現在、クラフトタスクは1つのノードのみをサポートし、指定されたアイテムの優先順位をサポートしていません。国内サーバーがワンクリック製造を実装した後、ワンクリック製造を使用してサポートする予定です",
"config_craft_max_times":"最大製造回数",
"desc_note":"備考",
"config_login_timeout": "ゲームにログインするためのタイムアウト時間(秒)",
"config_max_emulator_restart_times": "ログインタイムアウト後のエミュレータ再起動の最大数",

"config_server_jp": "日本サーバー",
"config_server_cn": "中国公式サーバー",
Expand Down
2 changes: 2 additions & 0 deletions DATA/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@
"config_craft_desc":"制造任务目前只能一个节点,且不支持指定物品的优先级,等国服实装一键制造后会通过一键制造来支持",
"config_craft_max_times":"尝试制造次数",
"desc_note":"备注",
"config_login_timeout":"登录游戏超时时间(秒)",
"config_max_emulator_restart_times": "登录超时后模拟器最多重启次数,0为不重启",

"config_server_jp":"日服",
"config_server_cn":"国服官服",
Expand Down
4 changes: 4 additions & 0 deletions gui/pages/Setting_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ def set_emulator(config):

ui.checkbox(config.get_text("config_close_emulator_when_finish")).bind_value(config.userconfigdict, 'CLOSE_EMULATOR_FINISH')
ui.checkbox(config.get_text("config_close_BAAH_when_finish")).bind_value(config.userconfigdict, 'CLOSE_BAAH_FINISH')

# 登录超时重启模拟器
ui.number(config.get_text("config_login_timeout"), min=180, precision=0, step=1).bind_value(config.userconfigdict, "GAME_LOGIN_TIMEOUT", forward= lambda x: int(x)).style("width: 200px")
ui.number(config.get_text("config_max_emulator_restart_times"), min=0, max=10, precision=0, step=1).bind_value(config.userconfigdict, "MAX_RESTART_EMULATOR_TIMES", forward= lambda x: int(x)).style("width: 400px")
22 changes: 18 additions & 4 deletions modules/AllTask/EnterGame/Loginin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import time

from DATA.assets.PageName import PageName
from DATA.assets.ButtonName import ButtonName
Expand All @@ -9,7 +9,7 @@

from modules.utils.log_utils import logging

from modules.utils import click, swipe, match, page_pic, button_pic, popup_pic, sleep, check_app_running, open_app, config, screenshot
from modules.utils import click, swipe, match, page_pic, button_pic, popup_pic, sleep, check_app_running, open_app, config, screenshot, EmulatorBlockError, istr, CN, EN

# =====

Expand All @@ -24,8 +24,21 @@ def pre_condition(self) -> bool:
return True


@staticmethod
def try_jump_useless_pages():
def try_jump_useless_pages(self):
# 判断超时
if time.time() - self.task_start_time > config.userconfigdict["GAME_LOGIN_TIMEOUT"]:
if config.sessiondict["RESTART_EMULATOR_TIMES"] >= config.userconfigdict["MAX_RESTART_EMULATOR_TIMES"]:
# 无重启次数剩余
raise Exception(istr({
CN: "超时:无法进入游戏主页,无剩余重启次数",
EN: "Timeout: Fail to login to the game homepage, no restart chances left"
}))
else:
# 有重启次数剩余,尝试重启
raise EmulatorBlockError(istr({
CN: "模拟器卡顿,重启模拟器",
EN: "Emulator blocked, try to restart emulator"
}))
# 确认处在游戏界面
if not check_app_running(config.userconfigdict['ACTIVITY_PATH']):
open_app(config.userconfigdict['ACTIVITY_PATH'])
Expand All @@ -48,6 +61,7 @@ def try_jump_useless_pages():


def on_run(self) -> None:
self.task_start_time = time.time()
# 因为涉及到签到页面什么的,所以这里点多次魔法点
self.run_until(self.try_jump_useless_pages,
lambda: match(popup_pic(PopupName.POPUP_LOGIN_FORM)) or Page.is_page(PageName.PAGE_HOME),
Expand Down
13 changes: 7 additions & 6 deletions modules/configs/MyConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MyConfigger:
"""
维护config字典,包含软件config,用户任务config,语言包
"""
NOWVERSION="1.7.3"
NOWVERSION="1.7.4"
USER_CONFIG_FOLDER="./BAAH_CONFIGS"
SOFTWARE_CONFIG_FOLDER="./DATA/CONFIGS"
LANGUAGE_PACKAGE_FOLDER="./DATA/i18n"
Expand All @@ -32,17 +32,18 @@ def __init__(self):
# 读取软件的config
self.parse_software_config(self.SOFTWARE_CONFIG_NAME)

def parse_user_config(self, file_name):
def parse_user_config(self, file_name, clear_sessiondict = True):
"""
读取config文件并解析
同时会清空sessiondict
同时会按需清空sessiondict
"""
file_path = os.path.join(self.current_dir, self.USER_CONFIG_FOLDER, file_name)
# 字典新值
self.userconfigdict = self._read_config_file(file_path)
# 清空sessiondict
self.sessiondict = {}
self._check_session_config()
if clear_sessiondict:
# 清空sessiondict
self.sessiondict = {}
self._check_session_config()
# 检查缺失的配置
self._check_user_config()
self.nowuserconfigname = file_name
Expand Down
9 changes: 8 additions & 1 deletion modules/configs/defaultSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
# 竞技场优先级、
"CONTEST_LEVEL_PRIORITY":{"d":10},
"CONTEST_RANK_PRIORITY":{"d":10},

# 游戏启动超时时间,秒。防止意料之外的错误判断(超时会触发error),默认超时时间设长点
"GAME_LOGIN_TIMEOUT":{"d":600},
# 游戏卡启动时的重新启动模拟器最多尝试次数
"MAX_RESTART_EMULATOR_TIMES":{"d":0},
}

# 软件的config里的默认值
Expand Down Expand Up @@ -227,5 +232,7 @@
"INFO_DICT":{"d":{}},
"INFO_LIST":{"d":[]},
# 截图文件读取失败的次数
"SCREENSHOT_READ_FAIL_TIMES":{"d":0}
"SCREENSHOT_READ_FAIL_TIMES":{"d":0},
# 当前尝试重启模拟器次数
"RESTART_EMULATOR_TIMES":{"d":0},
}
1 change: 1 addition & 0 deletions modules/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .notification import *
from .data_utils import *
from .I18nstr import *
from .baah_exceptions import *

from modules.utils.log_utils import logging
import time
Expand Down
4 changes: 2 additions & 2 deletions modules/utils/adb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def check_app_running(activity_path: str) -> bool:
return False
# 获取当前运行的app
output = get_now_running_app()
logging.info({"zh_CN": "当前运行的app是:{}".format(output),
"en_US": "The currently running app is: {}".format(output)})
logging.info({"zh_CN": "运行中...当前运行的app是:{}".format(output),
"en_US": "Running...The currently running app is: {}".format(output)})
if app_name in output:
return True
else:
Expand Down
10 changes: 10 additions & 0 deletions modules/utils/baah_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class EmulatorBlockError(Exception):
"""
模拟器卡顿错误,通常发生在游戏启动阶段
"""
def __init__(self, ErrorInfo):
super().__init__(self)
self.errorinfo = ErrorInfo

def __str__(self):
return self.errorinfo

0 comments on commit 2714246

Please sign in to comment.