Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 141 additions & 13 deletions assets/config/screens.json
Original file line number Diff line number Diff line change
Expand Up @@ -942,24 +942,22 @@
]
},
{
"name": "忘却之庭-准备战斗",
"id": "prepare_fight",
"image_path": "./assets/images/forgottenhall/prepare_fight.png",
"name": "虚构叙事",
"id": "purefiction",
"image_path": "./assets/images/screen/purefiction/purefiction.png",
"actions": [
{
"target_screen": "memory_of_chaos",
"target_screen": "main",
"actions_list": [
"auto.press_key('esc')",
"time.sleep(1)",
"auto.click_element('./assets/images/zh_CN/base/confirm.png', 'image', 0.9, 2)"
"auto.press_key('esc')"
]
}
]
},
{
"name": "虚构叙事",
"id": "purefiction",
"image_path": "./assets/images/screen/purefiction/purefiction.png",
"name": "末日幻影",
"id": "apocalyptic",
"image_path": "./assets/images/screen/apocalyptic/apocalyptic.png",
"actions": [
{
"target_screen": "main",
Expand All @@ -970,9 +968,9 @@
]
},
{
"name": "末日幻影",
"id": "apocalyptic",
"image_path": "./assets/images/screen/apocalyptic/apocalyptic.png",
"name": "异相仲裁",
"id": "anomaly_arbitration",
"image_path": "./assets/images/screen/anomaly_arbitration/anomaly_arbitration.png",
"actions": [
{
"target_screen": "main",
Expand All @@ -982,6 +980,27 @@
}
]
},
{
"name": "逐光捡金-准备战斗",
"id": "prepare_fight",
"image_path": [
"./assets/images/screen/treasures_lightward/exit.png",
"./assets/images/screen/treasures_lightward/view_details.png"
],
"match_all": true,
"actions": [
{
"target_screen": "main",
"actions_list": [
"auto.press_key('esc')",
"time.sleep(1)",
"auto.click_element('./assets/images/zh_CN/base/confirm.png', 'image', 0.9, 2)",
"time.sleep(3)",
"auto.press_key('esc')"
]
}
]
},
{
"name": "队伍",
"id": "configure_team",
Expand Down Expand Up @@ -1140,5 +1159,114 @@
]
}
]
},
{
"name": "二次元JUMP",
"id": "interplanar_jump",
"image_path": "./assets/images/screen/planarcadia/interplanar_jump.png",
"actions": [
{
"target_screen": "main",
"actions_list": [
"auto.press_key('esc')",
"time.sleep(1)",
"auto.click_element('离开二次元', 'text', None, 10)",
"time.sleep(3)"
]
}
]
},
{
"name": "浮脂记事",
"id": "floating_grease_chronicles",
"image_path": "./assets/images/screen/planarcadia/floating_grease_chronicles.png",
"actions": [
{
"target_screen": "main",
"actions_list": [
"auto.press_key('esc')",
"time.sleep(1)",
"auto.click_element('./assets/images/zh_CN/base/confirm.png', 'image', 0.9, 10)",
"time.sleep(3)"
]
}
]
},
{
"name": "星轨之兔",
"id": "star_rabbit",
"image_path": "./assets/images/screen/planarcadia/star_rabbit.png",
"actions": [
{
"target_screen": "main",
"actions_list": [
"auto.press_key('esc')",
"time.sleep(1)",
"auto.click_element('./assets/images/screen/planarcadia/exit.png', 'image', 0.9, 10)",
"time.sleep(3)",
"auto.click_element('./assets/images/screen/planarcadia/quit_stage.png', 'image', 0.9, 10)",
"time.sleep(6)",
"auto.press_key('esc')",
"time.sleep(0.5)",
"auto.click_element('./assets/images/zh_CN/base/confirm.png', 'image', 0.9, 10)"
]
}
]
},
{
"name": "机巧鸟",
"id": "cycane",
"image_path": "./assets/images/screen/xianzhou_luofu/cycane.png",
"actions": [
{
"target_screen": "main",
"actions_list": [
"auto.press_key('i')",
"time.sleep(1)",
"auto.click_element('./assets/images/zh_CN/base/confirm.png', 'image', 0.9, 10)",
"time.sleep(0.5)"
]
}
]
},
{
"name": "檞寄生",
"id": "mistletoe",
"image_path": "./assets/images/screen/amphoreus/mistletoe.png",
"actions": [
{
"target_screen": "main",
"actions_list": [
"auto.press_key('esc')",
"time.sleep(1)",
"auto.click_element('./assets/images/zh_CN/base/confirm.png', 'image', 0.9, 10)"
]
}
]
},
{
"name": "哈努兄弟",
"id": "brother_hanu",
"image_path": "./assets/images/screen/penacony/brother_hanu.png",
"actions": [
{
"target_screen": "main",
"actions_list": [
"auto.press_key(cfg.get_value('hotkey_map', 'm'))",
"time.sleep(1.5)",
"auto.click_element((1700.0 / 1920, 500.0 / 1080, 10.0 / 1920, 10.0 / 1080), 'crop', action='move')",
"auto.mouse_scroll(25, 1)",
"time.sleep(0.5)",
"auto.click_element('./assets/images/share/map/astral_express.png', 'image', 0.9, 10)",
"time.sleep(0.5)",
"auto.click_element('./assets/images/share/map/party_car.png', 'image', 0.8, 5)",
"time.sleep(0.5)",
"auto.click_element('./assets/images/share/map/space_anchor.png', 'image', 0.9, 10)",
"time.sleep(0.5)",
"auto.click_element('./assets/images/share/map/teleport.png', 'image', 0.9, 10)",
"time.sleep(2)"
]
}
]
}
]
Binary file removed assets/images/purefiction/prepare_fight.png
Binary file not shown.
Binary file added assets/images/screen/amphoreus/mistletoe.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 assets/images/screen/penacony/brother_hanu.png
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 assets/images/screen/planarcadia/exit.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.
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 assets/images/screen/planarcadia/quit_stage.png
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 assets/images/screen/planarcadia/star_rabbit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/screen/purefiction/purefiction.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.
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 assets/images/screen/xianzhou_luofu/cycane.png
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 assets/images/share/map/astral_express.png
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 assets/images/share/map/party_car.png
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 assets/images/share/map/space_anchor.png
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 assets/images/share/map/teleport.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 27 additions & 12 deletions module/screen/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def _setup_screens_from_config(self, config_path):
with open(config_path, 'r', encoding='utf-8') as file:
configs = json.load(file)
for config in configs:
self._add_screen(config["id"], config["name"], config["image_path"], config["actions"])
self._add_screen(config['id'], config['name'], config['image_path'], config['actions'])
if config.get('match_all'):
self.screen_map[config['id']]['match_all'] = True
except FileNotFoundError:
self.logger.error(f"配置文件不存在:{config_path}")
raise
Expand Down Expand Up @@ -125,6 +127,12 @@ def _handle_autotry(self):
time.sleep(2) # 等待屏幕变化

auto.take_screenshot()

# 通用兜底:ESC后检测是否有确认按钮
if auto.click_element("./assets/images/zh_CN/base/confirm.png", "image", 0.9, take_screenshot=False):
self.logger.info("检测到确认按钮,已点击")
time.sleep(2)

# 处理与服务器断开连接的异常情况
if auto.find_element("./assets/images/zh_CN/exception/relogin.png", "image", 0.9, take_screenshot=False):
auto.click_element("./assets/images/zh_CN/base/confirm.png", "image", 0.9, take_screenshot=False)
Expand Down Expand Up @@ -156,6 +164,7 @@ def find_screen(screen_name, screen):
"image_threshold",
self.SCREEN_MATCH_THRESHOLD,
take_screenshot=False,
match_all=screen.get('match_all', False),
)
if result and not found_event.is_set():
with self.lock:
Expand All @@ -172,6 +181,8 @@ def find_screen(screen_name, screen):
self.screen_map[self.current_screen]['image_path'],
"image_threshold",
self.SCREEN_MATCH_THRESHOLD,
match_all=self.screen_map[self.current_screen].get('match_all', False),
take_screenshot=False,
):
return True

Expand Down Expand Up @@ -290,16 +301,17 @@ def check_screen(self, target_screen):
:param target_screen: 目标界面的标识符。
:return: 如果当前界面是目标界面,则返回True;否则返回False。
"""
if self._find_image(self.screen_map[target_screen]['image_path'], "image", self.SCREEN_MATCH_THRESHOLD):
auto.take_screenshot()
if self._find_image(self.screen_map[target_screen]['image_path'], "image", self.SCREEN_MATCH_THRESHOLD, match_all=self.screen_map[target_screen].get('match_all', False), take_screenshot=False):
# 如果找到了目标界面的图像,则更新当前界面状态为目标界面
self.current_screen = target_screen
return True
return False

def _find_image(self, image_path, find_type, threshold=None, **kwargs):
def _find_image(self, image_path, find_type, threshold=None, match_all=False, **kwargs):
"""
支持 image_path 为字符串或字符串列表(或元组)。
当 image_path 为列表时,对列表内的图片进行“或”匹配:
当 image_path 为列表时,默认进行"或"匹配;若 match_all=True 则进行"与"匹配。
- 对于 'image_threshold' 类型,返回最高的匹配阈值(float)或 None。
- 对于其他类型,返回第一个被匹配到的结果(与 auto.find_element 的返回值一致)或 None。
其他参数会透传给 auto.find_element。
Expand All @@ -311,17 +323,20 @@ def _find_image(self, image_path, find_type, threshold=None, **kwargs):
try:
r = auto.find_element(p, find_type, threshold, **kwargs)
except Exception as e:
if match_all:
return None
self.logger.debug(f"查找图片 {p} 出错: {e}")
r = None
if r:
if find_type == 'image_threshold':
if best is None or r > best:
best = r
else:
return r
if not r:
if match_all:
return None
continue
if find_type != 'image_threshold' and not match_all:
return r
if best is None or (match_all and r < best) or (not match_all and r > best):
best = r
return best
else:
return auto.find_element(image_path, find_type, threshold, **kwargs)
return auto.find_element(image_path, find_type, threshold, **kwargs)
except Exception as e:
self.logger.debug(f"_find_image 出错: {e}")
return None
Expand Down