-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
82 lines (69 loc) · 2.2 KB
/
main.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
from multiprocessing import Process
import PySimpleGUI as sg
from PIL import Image
from src.config import edit_config, load_config
from src.core import main_create_new_route, main_process
from src.utils import (
RectangleSelection,
make_window,
set_process_state,
take_screenshot,
)
def terminate_p(p):
if p:
p.terminate()
def main():
run_key = "F9"
config = load_config()
window = make_window("New World - Ressource Bot", run_key)
down_run_key = False
p = None
p_route = None
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
terminate_p(p)
terminate_p(p_route)
break
if event == "-POS-":
terminate_p(p)
terminate_p(p_route)
down_run_key = set_process_state(False, window, run_key)
img = Image.fromarray(take_screenshot(True))
selector = RectangleSelection(img)
while not selector.done:
pass
selector.close()
edit_config("screenshot_rectangle", selector.rectangle, config)
if event == run_key:
down_run_key = set_process_state(not down_run_key, window, run_key)
if event == "-RECORD_ROUTE-":
print("test")
route_name = values["-NEW_ROUTE_NAME-"]
print(route_name)
if route_name.isalnum():
terminate_p(p)
terminate_p(p_route)
down_run_key = set_process_state(False, window, run_key)
p_route = Process(
target=main_create_new_route,
args=(
config["screenshot_rectangle"],
route_name,
),
)
p_route.start()
print("started")
if down_run_key:
terminate_p(p)
terminate_p(p_route)
print("Starting process")
p = Process(
target=main_process,
args=(config["screenshot_rectangle"],),
)
p.start()
else:
terminate_p(p)
if __name__ == "__main__":
main()