FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
commonLib/commonLib.lua at master · AnkuLua/commonLib · GitHub
AnkuLua
/
commonLib
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
commonLib
/
commonLib.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
200 lines (182 loc) · 5.44 KB
Breadcrumbs
commonLib
/
commonLib.lua
Copy path
File metadata and controls
200 lines (182 loc) · 5.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
--
============= dimension related =============
function
autoResize
(
target
,
defaultDimension
,
immersive
,
region
)
local
oldROI
=
Settings
:
getROI
();
local
max
=
0
local
localX
=
defaultDimension
if
(
region
~=
nil
)
then
Settings
:
setROI
(
region
)
end
if
(
exists
(
target
,
0
))
then
resumeROI
(
oldROI
)
return
defaultDimension
end
usePreviousSnap
(
true
)
setImmersiveMode
(
not
immersive
)
if
(
exists
(
target
,
0
))
then
resumeROI
(
oldROI
)
usePreviousSnap
(
false
)
return
defaultDimension
end
setImmersiveMode
(
immersive
)
target
:
similar
(
0.8
)
local
range
=
defaultDimension
*
0.15
for
x
=
defaultDimension
-
range
,
defaultDimension
+
range
,
10
do
Settings
:
setCompareDimension
(
true
,
x
)
if
(
exists
(
target
,
0
))
then
if
(
getLastMatch
():
getScore
()
<
max
)
then
localX
=
x
-
10
break
end
max
=
getLastMatch
():
getScore
()
end
end
max
=
0
for
x
=
(
localX
-
9
), (
localX
+
9
)
do
Settings
:
setCompareDimension
(
true
,
x
)
if
(
exists
(
target
,
0
))
then
if
(
getLastMatch
():
getScore
()
<
max
)
then
Settings
:
setCompareDimension
(
true
,
x
-
1
)
resumeROI
(
oldROI
)
usePreviousSnap
(
false
)
return
(
x
-
1
)
end
max
=
getLastMatch
():
getScore
()
end
end
if
(
max
==
0
)
then
Settings
:
setCompareDimension
(
true
,
defaultDimension
)
resumeROI
(
oldROI
)
usePreviousSnap
(
false
)
return
-
1
end
resumeROI
(
oldROI
)
usePreviousSnap
(
false
)
return
(
localX
+
9
)
end
--
============= Image recognition related =============
function
regionWaitMulti
(
target
,
seconds
,
debug
,
skipLocation
)
local
timer
=
Timer
()
local
match
while
(
true
)
do
for
i
,
t
in
ipairs
(
target
)
do
if
(
debug
)
then
t
.
region
:
highlight
(
0.5
)
end
if
(
i
==
1
)
then
usePreviousSnap
(
false
)
else
usePreviousSnap
(
true
)
end
if
((
t
.
region
and
(
t
.
region
):
exists
(
t
.
target
,
0
))
or
(
not
t
.
region
and
exists
(
t
.
target
,
0
)))
then
--
check once
usePreviousSnap
(
false
)
if
(
t
.
region
)
then
match
=
(
t
.
region
):
getLastMatch
()
else
match
=
getLastMatch
end
if
(
debug
)
then
match
:
highlight
(
0.5
)
end
return
i
,
t
.
id
,
match
end
end
if
(
skipLocation
~=
nil
)
then
click
(
skipLocation
)
end
if
(
timer
:
check
()
>
seconds
)
then
usePreviousSnap
(
false
)
return
-
1
,
"
__none__
"
end
end
end
function
waitMulti
(
target
,
seconds
,
skipLocation
)
local
timer
=
Timer
()
while
(
true
)
do
for
i
,
t
in
ipairs
(
target
)
do
if
(
i
==
1
)
then
usePreviousSnap
(
false
)
else
usePreviousSnap
(
true
)
end
if
(
exists
(
t
,
0
))
then
--
check once
usePreviousSnap
(
false
)
return
i
,
getLastMatch
()
end
end
if
(
skipLocation
~=
nil
)
then
click
(
skipLocation
)
end
if
(
timer
:
check
()
>
seconds
)
then
usePreviousSnap
(
false
)
return
-
1
end
end
end
function
existsMultiMax
(
target
,
region
)
local
oldROI
=
Settings
:
getROI
()
local
maxScore
=
0
local
maxIndex
=
0
local
match
if
(
region
~=
nil
)
then
Settings
:
setROI
(
region
)
end
for
i
,
t
in
ipairs
(
target
)
do
if
(
i
==
1
)
then
usePreviousSnap
(
false
)
else
usePreviousSnap
(
true
)
end
if
(
exists
(
t
,
0
))
then
--
check once
local
score
=
getLastMatch
():
getScore
()
if
(
score
>
maxScore
)
then
maxScore
=
score
maxIndex
=
i
match
=
getLastMatch
()
end
end
end
resumeROI
(
oldROI
)
usePreviousSnap
(
false
)
if
(
maxScore
==
0
)
then
return
-
1
end
return
maxIndex
,
match
end
function
resumeROI
(
oldROI
)
if
(
oldROI
)
then
Settings
:
setROI
(
oldROI
)
else
Settings
:
setROI
()
end
end
--
============= UI related ================
function
simpleDialog
(
title
,
message
)
dialogInit
()
addTextView
(
message
)
dialogShow
(
title
)
end
function
detectLanguage
(
target
,
list
,
region
)
local
oldROI
=
Settings
:
getROI
();
if
(
region
~=
nil
)
then
Settings
:
setROI
(
region
)
end
local
langList
=
"
"
for
i
,
l
in
ipairs
(
list
)
do
if
(
exists
(
target
..
l
..
"
.png
"
,
0
))
then
resumeROI
(
oldROI
)
return
l
end
langList
=
langList
..
l
..
"
\n
"
end
return
"
none
"
,
langList
end
function
offOnScreen
(
second
,
pinLock
,
pin
)
keyevent
(
26
)
--
power
wait
(
second
)
keyevent
(
82
)
--
unlock
if
(
pinLock
)
then
type
(
pin
)
--
passcode
keyevent
(
66
)
--
enter
end
end
--
============= strings related ================
function
fileExists
(
name
)
local
f
=
io.open
(
name
,
"
r
"
)
if
f
~=
nil
then
io.close
(
f
)
return
true
else
return
false
end
end
function
loadStrings
(
path
)
local
language
=
getLanguage
()
local
file
=
path
..
"
strings.
"
..
getLanguage
()
..
"
.lua
"
;
if
(
fileExists
(
file
))
then
dofile
(
file
)
else
if
(
fileExists
(
path
..
"
strings.lua
"
))
then
dofile
(
path
..
"
strings.lua
"
)
end
end
end
--
============= Lua language related =============
function
tableLookup
(
table
,
item
)
for
i
,
t
in
ipairs
(
table
)
do
if
(
t
==
item
)
then
return
i
end
end
return
-
1
end
function
randomNumer
(
value
)
return
(
math.floor
((
math.random
()
-
0.5
)
*
2
*
value
))
end
Back
|
FazBrowse Home
|
New Git URL