-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainRewrite.py
More file actions
98 lines (84 loc) · 3.61 KB
/
mainRewrite.py
File metadata and controls
98 lines (84 loc) · 3.61 KB
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
import pyautogui
import time
import logging
import os
from collections import namedtuple
import Exceptions
import bigBoiStart
import animation
import constants
import multipleChoice
import nextLesson
import backupButtonDetection
try:
os.remove(constants.SCROLLBAR_SCREENSHOT_NAME)
os.remove(constants.BUTTON_DETECTION_SCREENSHOT_NAME)
except Exception:
pass
time.sleep(2)
im = pyautogui.screenshot(constants.SCROLLBAR_SCREENSHOT_NAME, region=(1346, 71, 1359, 726))
logging.basicConfig(level=logging.DEBUG)
numSinceLastEvent = 0
checkScrollBar = 0
lastY = 0
class BackupButtonDetectionData:
def __init__(self, active: bool, offsetX: int, offsetY: int):
self.active = active
self.offsetX = offsetX
self.offsetY = offsetY
backupButtonDetectionData = BackupButtonDetectionData(False, constants.BUTTON_DETECTION_SCREENSHOT_AREA[0], 0)
while True:
pyautogui.moveTo(100, 100)
if animation.hasAnimation():
numSinceLastEvent = 0
animation.clickSpeedTextbox()
animation.clickStart()
animation.runAnimation()
pyautogui.scroll(-10, x=1000, y=1000)
elif backupButtonDetectionData.active and backupButtonDetection.hasButton(backupButtonDetectionData):
backupButtonDetection.clickButton(backupButtonDetectionData)
backupButtonDetection.shiftScreenshot(backupButtonDetectionData)
elif multipleChoice.hasBubble() and not backupButtonDetectionData.active:
numSinceLastEvent = 0
bubbleLocation = multipleChoice.getBubbleLoc()
multipleChoice.clickBubble()
multipleChoice.scrollToNextBubble(bubbleLocation)
elif bigBoiStart.hasBigBoiButton():
loc = bigBoiStart.getBigBoiButton()
bigBoiStart.clickBigBoiButton()
bigBoiStart.scrollToNextBubble(loc)
elif nextLesson.hasEnding():
backupButtonDetectionData = BackupButtonDetectionData(False, constants.BUTTON_DETECTION_SCREENSHOT_AREA[0], 0)
numSinceLastEvent = 0
nextLesson.endLesson()
nextLesson.waitForNewLesson()
elif nextLesson.hasEndingFeedback():
backupButtonDetectionData = BackupButtonDetectionData(False, constants.BUTTON_DETECTION_SCREENSHOT_AREA[0], 0)
logging.info("Scrolling down")
pyautogui.scroll(-200, x=1000, y=1000)
logging.info("Clicked (hopefully) where hyperlink is. Since we couldn't find it")
pyautogui.moveTo(x=1132, y=700)
pyautogui.click()
nextLesson.waitForNewLesson()
else:
logging.info("Nothing found")
pyautogui.scroll(-200, x=1000, y=1000)
numSinceLastEvent += 1
if numSinceLastEvent == constants.NUM_ATTEMPTS_TIL_ERROR:
logging.warning('may have become stuck?')
checkScrollBar += 1
if checkScrollBar == constants.NUM_ATTEMPTS_TIL_ERROR:
checkScrollBar = 0
scrollBar = pyautogui.locateOnScreen(constants.SCROLLBAR_SCREENSHOT_NAME, confidence=0.95)
logging.info("Checking scrollbar")
if scrollBar and not backupButtonDetectionData.active:
backupButtonDetectionData.active = True
logging.warning("No meaningful scrollbar progress detected, activating backup button detection")
highestButton = multipleChoice.getBubbleLoc()
if not highestButton:
raise Exceptions.BackupButtonDetectionNoButton()
backupButtonDetectionData.offsetY = highestButton.top
else:
os.remove(constants.SCROLLBAR_SCREENSHOT_NAME)
im = pyautogui.screenshot(constants.SCROLLBAR_SCREENSHOT_NAME, region=(1346, 71, 1359 - 1346, 726 - 71))
logging.info("Scrollbar progress detected")