Skip to content

Commit

Permalink
Merge pull request #164 from sanmusen214/dev
Browse files Browse the repository at this point in the history
Dev 1.8.13
  • Loading branch information
sanmusen214 authored Jan 19, 2025
2 parents 85bc0bc + 748a434 commit 36b4254
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ compact_log.txt
/DATA/update/
/BAAH*_update.zip
notrack_*.py
/DATA/LOGS
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
9 changes: 6 additions & 3 deletions BAAH.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ def BAAH_auto_quit(forcewait = False, key_map_func = None):
if must_auto_quit:
return
if forcewait or not config.userconfigdict["CLOSE_BAAH_FINISH"]:
user_input = input(f"Press Enter to exit/回车退出, [{key_map_func.keys()}]:")
user_input = input(f"Press Enter to exit/回车退出, "+str([f"[{k}]{key_map_func[k]['desc']}" for k in key_map_func]) + ": ")
for k in key_map_func:
if user_input.upper() == k.upper():
key_map_func[k]()
key_map_func[k]["func"]()
break
else:
logging.info({"zh_CN": "10秒后自动关闭", "en_US": "Auto close in 10 seconds"})
Expand Down Expand Up @@ -428,7 +428,10 @@ def BAAH_main(run_precommand = True):

print_BAAH_config_info()
BAAH_auto_quit(forcewait=True, key_map_func={
"R": lambda: [config.parse_user_config(config.nowuserconfigname), BAAH_main()]
"R": {
"desc":"estart", # [R]estart
"func":lambda: [config.parse_user_config(config.nowuserconfigname), BAAH_main()]
}
})


Expand Down
7 changes: 5 additions & 2 deletions BAAH_CONFIGS/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"CLOSE_GAME_FINISH": true,
"GAME_LOGIN_TIMEOUT": 600,
"MAX_RESTART_EMULATOR_TIMES": 0,
"SCREENSHOT_METHOD": "png",
"SCREENSHOT_METHOD": "pipe",
"OPEN_GAME_APP_TASK": true,
"DO_POST_ALL_TASK": true,
"TEAM_SET_STRENGTH": [
Expand Down Expand Up @@ -298,5 +298,8 @@
"yellow": 0,
"purple": 0
}
]
],
"CAFE1_INVITE_SEQ": 1,
"CAFE2_INVITE_SEQ": 2,
"SAVE_LOG_TO_FILE": false
}
Binary file added DATA/assets/BUTTON/BUTTON_LOGIN_BILI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion DATA/assets/ButtonName.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ class ButtonName:
BUTTON_EVENT_FIRST = "BUTTON_EVENT_FIRST"

# 部分活动只有关卡和挑战,关卡在左侧第一个而不是中间
BUTTON_EVENT_QUEST_SELLECTED_LEFT = "BUTTON_EVENT_QUEST_SELLECTED_LEFT"
BUTTON_EVENT_QUEST_SELLECTED_LEFT = "BUTTON_EVENT_QUEST_SELLECTED_LEFT"

BUTTON_LOGIN_BILI = "BUTTON_LOGIN_BILI"
Binary file added DATA/assets_cn/BUTTON/BUTTON_LOGIN_BILI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DATA/assets_jp/BUTTON/BUTTON_LOGIN_BILI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion DATA/grid_solution/quest/H22-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
{
"team": "B",
"action": "move",
"target": "right-up"
"target": "right-up",
"click":[560, 283]
}
],
[
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 @@ -154,6 +154,8 @@
"team_yellow":"Yellow Type Attack",
"team_blue":"Blue Type Attack",
"team_purple":"Purple Type Attack",
"config_output_log":"Whether output log to /DATA/LOGS/ directory",
"config_screenshot_mode":"Screenshot Mode",

"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 @@ -154,6 +154,8 @@
"team_yellow":"黄の攻撃",
"team_blue":"青い攻撃",
"team_purple":"紫の攻撃",
"config_output_log":"ログを/DATA/LOGS/ディレクトリに出力するかどうか",
"config_screenshot_mode":"スクリーンショットモード",

"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 @@ -154,6 +154,8 @@
"team_yellow":"黄攻",
"team_blue":"蓝攻",
"team_purple":"紫攻",
"config_output_log":"是否输出日志到/DATA/LOGS/目录下",
"config_screenshot_mode":"截图模式",

"config_server_jp":"日服",
"config_server_cn":"国服官服",
Expand Down
8 changes: 8 additions & 0 deletions gui/pages/Setting_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def set_other(config, load_jsonname):

ui.label(config.get_text("config_warn_change")).style('color: red')

with ui.row():
# 日志保存
ui.checkbox(config.get_text("config_output_log")).bind_value(config.userconfigdict, 'SAVE_LOG_TO_FILE')

with ui.row():
ui.number(config.get_text("config_run_until_try_times"),
step=1,
Expand Down Expand Up @@ -53,6 +57,10 @@ def set_other(config, load_jsonname):
with ui.row():
ui.input(config.get_text("config_adb_path")).bind_value(config.userconfigdict, 'ADB_PATH',forward=lambda v: v.replace("\\", "/")).style('width: 400px')

with ui.row():
# 截图模式
ui.select(options=["png", "pipe"], label=config.get_text("config_screenshot_mode")).bind_value(config.userconfigdict, 'SCREENSHOT_METHOD').style('width: 400px')

with ui.row():
ui.input(config.get_text("config_screenshot_name")).bind_value(config.userconfigdict, 'SCREENSHOT_NAME',forward=lambda v: v.replace("\\", "/")).style('width: 400px').set_enabled(False)

Expand Down
16 changes: 15 additions & 1 deletion modules/AllTask/EnterGame/Loginin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

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, EmulatorBlockError, istr, CN, EN
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, match_pixel

# =====

class Loginin(Task):
def __init__(self, name="Loginin", pre_times = 3, post_times = 10) -> None:
super().__init__(name, pre_times, post_times)
# B站登录横幅,几个白色采样点
self.BILI_LOGIN_BANNER_WHITE_POINTS = [[115, 20], [115, 73], [526, 76], [885, 18], [1093, 78], [1161, 22]]
self.has_bili_login_banner = lambda: all([match_pixel(point, Page.COLOR_WHITE) for point in self.BILI_LOGIN_BANNER_WHITE_POINTS])


def pre_condition(self) -> bool:
Expand Down Expand Up @@ -55,6 +58,17 @@ def try_jump_useless_pages(self):
elif match(button_pic(ButtonName.BUTTON_QUIT_LAST)):
# 点掉放弃上次战斗进度按钮
click(button_pic(ButtonName.BUTTON_QUIT_LAST))
elif match(button_pic(ButtonName.BUTTON_LOGIN_BILI)):
# 点掉B站登录按钮
# 防止点到上方横幅右侧切换账号按钮,这里睡4s等待横幅消失
click(button_pic(ButtonName.BUTTON_LOGIN_BILI), sleeptime=4)
elif self.has_bili_login_banner():
# 如果出现B站登录横幅,睡2s等待横幅消失
logging.info(istr({
CN: "等待B站登录横幅消失",
EN: "Waiting for the Bilibili login banner to disappear"
}))
sleep(2)
else:
# 活动弹窗
click((1250, 40))
Expand Down
26 changes: 23 additions & 3 deletions modules/AllTask/InQuest/InQuest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from modules.AllPage.Page import Page
from modules.AllTask.Task import Task

from modules.utils import click, swipe, match, page_pic, button_pic, popup_pic, sleep, ocr_area
from modules.utils import click, swipe, match, page_pic, button_pic, popup_pic, sleep, ocr_area, istr, CN, EN
from .HardQuest import HardQuest
from .NormalQuest import NormalQuest
from .PushQuest import PushQuest
Expand Down Expand Up @@ -44,20 +44,30 @@ def on_run(self) -> None:
if config.userconfigdict['PUSH_NORMAL_QUEST'] != 0:
# do PUSH NORMAL QUEST
logging.info({"zh_CN": "设置了推普通图任务,开始推图",
"en_US": "Set up the task of pushing the normal diagram to start the thumbnail"})
"en_US": "Set up the task of pushing the normal quest to start the thumbnail"})
# 序号转下标 章节号
push_normal_ind = config.userconfigdict['PUSH_NORMAL_QUEST'] - 1
PushQuest("normal", push_normal_ind,
level_ind=config.userconfigdict["PUSH_NORMAL_QUEST_LEVEL"] - 1).run()
else:
logging.warn(istr({
CN: "未设置推普通图起始的章节关卡!跳过",
EN: "The chapter level that starts the normal quest is not set! Skip"
}))
if "push-hard" in self.types:
# 判断配置里的PUSH_HARD_QUEST长度是否为0
if config.userconfigdict['PUSH_HARD_QUEST'] != 0:
# do PUSH HARD QUEST
logging.info({"zh_CN": "设置了推困难图任务,开始推图",
"en_US": "Set up the Push Difficulty Diagram task to start pushing the diagram"})
"en_US": "Set up the Push Hard Quest task to start pushing the diagram"})
# 序号转下标,章节号
push_hard_ind = config.userconfigdict['PUSH_HARD_QUEST'] - 1
PushQuest("hard", push_hard_ind, level_ind=config.userconfigdict["PUSH_HARD_QUEST_LEVEL"] - 1).run()
else:
logging.warn(istr({
CN: "未设置推困难图起始的章节关卡!跳过",
EN: "The chapter level that starts the hard quest is not set! Skip"
}))
# 当天日期
today = time.localtime().tm_mday
if "hard" in self.types:
Expand All @@ -72,6 +82,11 @@ def on_run(self) -> None:
hard_list_2 = [[x[0]-1, x[1]-1, *x[2:]] for x in hard_list]
# do HARD QUEST
HardQuest(hard_list_2).run()
else:
logging.warn(istr({
CN: "困难任务队列为空!跳过",
EN: "The hard task queue is empty! Skip"
}))
if "normal" in self.types:
# 选择一个NORMAL QUEST List的下标
if len(config.userconfigdict['NORMAL']) != 0:
Expand All @@ -84,6 +99,11 @@ def on_run(self) -> None:
# 序号转下标
normal_list_2 = [[x[0]-1, x[1]-1, *x[2:]] for x in normal_list]
NormalQuest(normal_list_2).run()
else:
logging.warn(istr({
CN: "普通任务队列为空!跳过",
EN: "The normal task queue is empty! Skip"
}))
self.back_to_home()

def post_condition(self) -> bool:
Expand Down
7 changes: 5 additions & 2 deletions modules/AllTask/SubTask/GridQuest.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def wait_end(self, possible_fight=False):
# 清弹窗
self.run_until(
lambda: click(Page.MAGICPOINT),
lambda: match_pixel(Page.MAGICPOINT, Page.COLOR_WHITE)
lambda: match_pixel(Page.MAGICPOINT, Page.COLOR_WHITE),
times=12
)
logging.info({"zh_CN": "尝试呼出弹窗", "en_US": "Try Callout Popup"})
# 出弹窗
Expand All @@ -191,7 +192,8 @@ def wait_end(self, possible_fight=False):
# 清弹窗
self.run_until(
lambda: click(Page.MAGICPOINT),
lambda: match_pixel(Page.MAGICPOINT, Page.COLOR_WHITE)
lambda: match_pixel(Page.MAGICPOINT, Page.COLOR_WHITE),
times=12
)

def get_now_focus_on_team(self):
Expand Down Expand Up @@ -289,6 +291,7 @@ def on_run(self) -> None:
config.sessiondict["LAST_TEAM_SET"] = now_need_team_set_list
logging.info({"zh_CN": "配队信息已更新", "en_US": "Dispatch information has been updated"})
else:
self.print_team_config(now_need_team_set_list)
# 不需要用户配队的话就继续用上次的队伍
display_str = " ".join([self.TEAM_TYPE_NAME.get(item) for item in last_team_set_list])
logging.info({"zh_CN": f"使用上次的队伍配置: {display_str}",
Expand Down
12 changes: 11 additions & 1 deletion modules/configs/MyConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ class MyConfigger:
"""
维护config字典,包含软件config,用户任务config,语言包
"""
NOWVERSION="1.8.12"
NOWVERSION="1.8.13"
USER_CONFIG_FOLDER="./BAAH_CONFIGS"
SOFTWARE_CONFIG_FOLDER="./DATA/CONFIGS"
LANGUAGE_PACKAGE_FOLDER="./DATA/i18n"
LOG_FOLDER="./DATA/LOGS"
SOFTWARE_CONFIG_NAME="software_config.json"
# 读取config这个py里面的配置
def __init__(self):
self.current_dir = os.getcwd()
self.create_required_folders()
# 软件的config
self.softwareconfigdict = {}
# 软件的语言包
Expand All @@ -33,6 +35,14 @@ def __init__(self):
# 读取软件的config
self.parse_software_config(self.SOFTWARE_CONFIG_NAME)

def create_required_folders(self):
"""创建需要的文件夹"""
required_folders = [self.LOG_FOLDER]
for folder in required_folders:
folder_path = os.path.join(self.current_dir, folder)
if not os.path.exists(folder_path):
os.makedirs(folder_path)

def parse_user_config(self, file_name, clear_sessiondict = True):
"""
读取config文件并解析
Expand Down
4 changes: 3 additions & 1 deletion modules/configs/defaultSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@

# 截图模式, png:保存/读取png图片,pipe读取/单例化管道内数据
"SCREENSHOT_METHOD":{
"d":"png",
"d":"pipe",
"s":["png", "pipe"]
},

Expand All @@ -232,6 +232,8 @@
# 要邀请的学生在momotalk中的序号,从1开始
"CAFE1_INVITE_SEQ":{"d":1},
"CAFE2_INVITE_SEQ":{"d":2},

"SAVE_LOG_TO_FILE":{"d":False},
}

# 软件的config里的默认值
Expand Down
77 changes: 37 additions & 40 deletions modules/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,48 +214,45 @@ def screenshot(output_png = False):

def check_connect():
# 检查当前python目录下是否有screenshot.png文件,如果有就删除
if os.path.exists(f"./{get_config_screenshot_name()}"):
logging.info({"zh_CN": f"删除{get_config_screenshot_name()}", "en_US":f"Detele {get_config_screenshot_name()}"})
os.remove(f"./{get_config_screenshot_name()}")
if os.path.exists(get_config_screenshot_name()):
logging.info({"zh_CN": f"删除{get_config_screenshot_name()}", "en_US":f"Delete {get_config_screenshot_name()}"})
os.remove(get_config_screenshot_name())
connect_to_device()
# 尝试截图
screenshot(output_png=True)
time.sleep(2)
if os.path.exists(f"./{get_config_screenshot_name()}"):
logging.info({"zh_CN": f"截图文件大小为{os.path.getsize(f'./{get_config_screenshot_name()}')//1024}KB", "en_US":f"The size of the screenshot file is {os.path.getsize(f'./{get_config_screenshot_name()}')//1024}KB"})
# 检查文件大小
if os.path.getsize(f"./{get_config_screenshot_name()}") !=0: # 不为0
logging.info({"zh_CN":"adb与模拟器连接正常" , "en_US":"The connection between adb and the emulator is normal"})
# 检查图片长和宽
img = cv2.imread(f"./{get_config_screenshot_name()}")
if img is None:
logging.error({"zh_CN": "图片读取失败,多次出现请尝试重启模拟器", "en_US":"Image read failed, try restart emulator if encountered multiple times"})
# 第一维度是高,第二维度是宽
elif img.shape[0] == 720 and img.shape[1] == 1280:
logging.info({"zh_CN": "图片分辨率为1280*720", "en_US":"The resolution is 1280*720"})
dpi_res = get_dpi()
logging.info(f"DPI: {dpi_res}")
if "240" not in dpi_res:
logging.warn(istr({
CN: "请设置模拟器dpi为240",
EN: "Please set the emulator dpi to 240"
}))
# auto fix
set_dpi(240)
return False
return True
elif img.shape[0] == 1280 and img.shape[1] == 720:
logging.warn({"zh_CN": "图片分辨率为720*1280,可能是模拟器设置错误,也可能是模拟器bug", "en_US":"The resolution is 720*1280, it may be the wrong setting of the emulator, or it may be a bug of the emulator"})
logging.warn({"zh_CN": "继续运行,但是可能会出现问题,请确保模拟器分辨率为1280*720", "en_US":"Continue to run, but there may be problems, please make sure the emulator resolution is 1280*720"})
if "240" not in get_dpi():
raise Exception(istr({
CN: "请设置模拟器dpi为240",
EN: "Please set the emulator dpi to 240"
}))
return True
else:
logging.error({"zh_CN": "图片分辨率不为1280*720,请设置模拟器分辨率为1280*720(当前{}*{})".format(img.shape[1], img.shape[0]), "en_US":"The resolution is not 1280*720, please set the resolution to 1280*720 (current {}*{})".format(img.shape[1], img.shape[0])})
raise Exception("图片分辨率不为1280*720,请设置模拟器分辨率为1280*720(当前{}*{})".format(img.shape[1], img.shape[0]))
screenshot()
time.sleep(1)
sc_data = get_screenshot_cv_data()
if sc_data is not None:
logging.info({"zh_CN":"adb与模拟器连接正常" , "en_US":"The connection between adb and the emulator is normal"})
# 检查图片长和宽
wm_height = sc_data.shape[0]
wm_width = sc_data.shape[1]
# 第一维度是高,第二维度是宽
if wm_height == 720 and wm_width == 1280:
logging.info({"zh_CN": "图片分辨率为1280*720", "en_US":"The resolution is 1280*720"})
dpi_res = get_dpi()
logging.info(f"DPI: {dpi_res}")
if "240" not in dpi_res:
logging.warn(istr({
CN: "请设置模拟器dpi为240",
EN: "Please set the emulator dpi to 240"
}))
# auto fix
set_dpi(240)
return False
return True
elif wm_height == 1280 and wm_width == 720:
logging.warn({"zh_CN": "图片分辨率为720*1280,可能是模拟器设置错误,也可能是模拟器bug", "en_US":"The resolution is 720*1280, it may be the wrong setting of the emulator, or it may be a bug of the emulator"})
logging.warn({"zh_CN": "继续运行,但是可能会出现问题,请确保模拟器分辨率为1280*720", "en_US":"Continue to run, but there may be problems, please make sure the emulator resolution is 1280*720"})
if "240" not in get_dpi():
raise Exception(istr({
CN: "请设置模拟器dpi为240",
EN: "Please set the emulator dpi to 240"
}))
return True
else:
logging.error({"zh_CN": "图片分辨率不为1280*720,请设置模拟器分辨率为1280*720(当前{}*{})".format(wm_width, wm_height), "en_US":"The resolution is not 1280*720, please set the resolution to 1280*720 (current {}*{})".format(wm_width, wm_height)})
raise Exception("图片分辨率不为1280*720,请设置模拟器分辨率为1280*720(当前{}*{})".format(wm_width, wm_height))
logging.error({"zh_CN": "adb与模拟器连接失败", "en_US":"Failed to connect to the emulator"})
logging.info({"zh_CN": "请检查adb与模拟器连接端口号是否正确", "en_US":"Please check if the adb and emulator connection port number is correct"})
return False
Loading

0 comments on commit 36b4254

Please sign in to comment.