-
Notifications
You must be signed in to change notification settings - Fork 0
/
LZutils.py
143 lines (107 loc) · 3.42 KB
/
LZutils.py
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
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 6 10:01:26 2020
@author: Glen
"""
import pyautogui
import time
import ErrorLZ
def swapVariables(a,b):
return b, a
def findAndMove(file, confidence=.9):
pyautogui.moveTo(pyautogui.center(pyautogui.locateOnScreen(file, confidence=confidence)))
def pullMousebox():
"""Return of user generated box.
Uses an alert to allow the user to position it
Returns
-------
4 int tuple of the box in region how pyauto uses
left, top, width, height
"""
Screen_size = pyautogui.size()
pyautogui.alert("start Pos")
x1, y1 = pyautogui.position()
print(x1, ", ", y1)
pyautogui.alert("end Pos")
x2, y2 = pyautogui.position()
print(x2, ', ', y2)
if x1 > x2:
x1, x2 = swapVariables(x1, x2)
if y1 > y2:
y1, y2 = swapVariables(y1, y2)
return x1, y1, x2-x1, y2-y1
def pullImage():
"""Literally pulls a screenshot.
returns the image, also saves it.
"""
region = pullMousebox()
name = pyautogui.prompt(text='What is this?')
test = name
print(name)
print("\'", test, "\'")
print("\'", "\'")
if name is None:
print("cancelled")
raise ErrorLZ.LZException("Pull image aborted.")
name = name + ".png"
if name.startswith('.'):
print("Empty input")
raise ErrorLZ.LZException("No name inputted.")
print(region)
time.sleep(.02)
im = pyautogui.screenshot(imageFilename=name, region=region)
return im
class building():
pass
def FindGoClickAll(image, confidence=0.9, delay=0.1):
thing = pyautogui.locateOnScreen(image, confidence=confidence)
if thing is None:
return False
found = 0
while thing is not None:
goClick(pyautogui.center(thing))
time.sleep(delay)
thing = pyautogui.locateOnScreen(image, confidence=confidence)
found += 1
return True
def FindGoCollectAll(image, confidence=0.8):
thing = pyautogui.locateOnScreen(image, confidence=confidence)
if thing is None:
return False
while thing is not None:
pos = pyautogui.center(thing) + (0,40)
goClick(pos)
pyautogui.move(-100,-100, 0.02)
time.sleep(0.05)
thing = pyautogui.locateOnScreen(image, confidence=confidence)
return True
def RestartProductions():
thing = pyautogui.locateOnScreen("building sleeping.png", confidence=0.6)
if thing is None:
return False
while thing is not None:
pos = pyautogui.center(thing) + (0,40)
goClick(pos)
pyautogui.move(-300,-300)
time.sleep(0.5)
try:
findClick("5 min production.png")
except ErrorLZ.LZException:
print("5 min not there")
time.sleep(1.5)
thing = pyautogui.locateOnScreen("building sleeping.png", confidence=0.5)
return True
def findClick(image, confidence=.9, offset=(0,0)):
rect = pyautogui.locateOnScreen(image, confidence=confidence)
if rect == None:
raise ErrorLZ.LZException("'{}' Not found on screen".format(image))
pos = pyautogui.center(rect)
pos = pos + offset
pyautogui.moveTo(pos, None, 0.3, pyautogui.easeInOutQuad)
pyautogui.click( )
#i really don't think its worth my effort to make a function for 2 lines...
def goClick(pos):
"""takes location tuple"""
pyautogui.moveTo(pos, None, 0.2, pyautogui.easeInOutQuad)
time.sleep(.5)
pyautogui.click( )