/
autoScheduler.py
54 lines (48 loc) · 1.86 KB
/
autoScheduler.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
import seamonsters as sea
class Action(sea.State):
def __init__(self, name, function, key, coord=None):
self.name = name
self.function = function
# key is the action type as a string
self.key = key
self.coord = coord
class AutoScheduler:
def __init__(self):
self.actionList = []
self.runningAction = None
self.updateCallback = lambda: None
self.idleFunction = lambda: None
def runSchedule(self):
try:
while True:
if len(self.actionList) == 0:
self.runningAction = None
self.updateCallback()
while len(self.actionList) == 0:
self.idleFunction()
yield
continue
self.runningAction = self.actionList[0]
self.updateCallback()
yield from self.runningAction.function()
if self.runningAction in self.actionList:
self.actionList.remove(self.runningAction)
finally:
self.runningAction = None
# converts the schedule into something that can be saved in a json file
def saveSchedule(self):
schedulePresets = []
for action in self.actionList:
newAction = {
"key" : action.key,
"coord" : []
}
if action.key == "bezier":
coordsList = []
for coord in action.coord:
coordsList.append([action.name, coord.x, coord.y, coord.angle])
newAction["coord"] = coordsList
elif action.coord is not None:
newAction["coord"] = [action.name, action.coord.x, action.coord.y, action.coord.angle]
schedulePresets.append(newAction)
return schedulePresets