Skip to content

Commit 4f23638

Browse files
Bug fixes and scroll improvment
1. Fixed crash when not using advanced settings 2. Add a new method for detecting page scroll
1 parent 1ed016e commit 4f23638

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

ArtScanner/art_scanner_logic.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import win32gui
44
import mouse, math
5+
from PIL import ImageChops
56
from utils import captureWindow
67

78
class GameInfo:
@@ -55,15 +56,15 @@ def interrupt(self):
5556
self.stopped = True
5657

5758

58-
def waitSwitched(self, art_center_x, art_center_y, min_wait=0.1, max_wait=3):
59+
def waitSwitched(self, art_center_x, art_center_y, min_wait=0.1, max_wait=3, condition=lambda pix:sum(pix)/3>200):
5960
total_wait = 0
6061
while True:
6162
pix = captureWindow(self.game_info.hwnd, (
6263
art_center_x-self.game_info.art_width/2-self.game_info.art_expand,
6364
art_center_y,
6465
art_center_x-self.game_info.art_width/2-self.game_info.art_expand+1.5,
6566
art_center_y+1.5))
66-
if sum(pix.getpixel((0,0)))/3>200:
67+
if condition(pix.getpixel((0,0))):
6768
return True
6869
else:
6970
time.sleep(min_wait)
@@ -149,8 +150,21 @@ def scrollToRow(self, target_row, max_scrolls=20, extra_scroll=0, interval=0.05)
149150
return rows_scrolled
150151
if lines_scrolled > max_scrolls:
151152
return rows_scrolled
153+
get_first_art = lambda : captureWindow(self.game_info.hwnd, (
154+
self.game_info.first_art_x+self.game_info.art_width/2-1,
155+
self.game_info.first_art_y+self.game_info.art_height/2,
156+
self.game_info.first_art_x+self.game_info.art_width/2+1,
157+
self.game_info.first_art_y+self.game_info.art_height))
158+
first_art = get_first_art()
152159
for _ in range(7 if lines_scrolled==0 and target_row>0 else 1):
153160
mouse.wheel(-1)
154161
lines_scrolled += 1
155162
# print('翻一下')
156-
time.sleep(interval)
163+
total_waited = 0
164+
while True:
165+
time.sleep(interval)
166+
total_waited += interval
167+
if total_waited>5:
168+
break
169+
if ImageChops.difference(get_first_art(), first_art).getbbox():
170+
break

ArtScanner/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def is_admin():
9797
input('运行期间请保持原神在前台,请勿遮挡窗口或操作鼠标,按鼠标中键停止。按回车继续')
9898
input('开始后将尝试自动对齐第一行以方便识别,若对齐结果有误,请立刻按中键停止。按回车继续')
9999
print('---------------------------------')
100-
if input('是否进行高级设置,例如等级过滤,稀有度过滤,翻页速度,确认请输入y:').strip().lower()=='y':
100+
if input('是否进行高级设置,例如等级过滤,稀有度过滤,翻页延迟,确认请输入y:').strip().lower()=='y':
101101
level_threshold = input('请输入圣遗物等级阈值(0-20)(比如:16,则仅将保存16级及以上的圣遗物信息)。直接按回车则默认保存所有圣遗物信息。')
102102
rarity_threshold = input('请输入圣遗物星级阈值(1-5)(比如:5,则仅将保存5星的圣遗物信息)。直接按回车则默认保存所有圣遗物信息。')
103103
scroll_interval = input('请输入翻页时的检测延迟(秒),数值越小翻页速度越快,但越可能造成跳行提前结束等问题,直接回车则为默认值0.05。')
@@ -106,15 +106,15 @@ def is_admin():
106106

107107
try:
108108
level_threshold = int(level_threshold)
109-
except ValueError:
109+
except:
110110
level_threshold = 0
111111
try:
112112
rarity_threshold = int(rarity_threshold)
113-
except ValueError:
113+
except:
114114
rarity_threshold = 0
115115
try:
116116
scroll_interval = float(scroll_interval)
117-
except ValueError:
117+
except:
118118
scroll_interval = 0.05
119119

120120
keyboard.press('alt')

0 commit comments

Comments
 (0)