-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
72 lines (60 loc) · 2.31 KB
/
settings.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
from default import presets, pride
class Settings:
def __init__(self):
self.properties = {
"enabled": True
}
self.gameinfo = {
"stage": None,
"alliance": None,
"piece": None,
"matchtype": None,
"time": None,
"estopped": None,
"balanced": None
}
self.active_preset = None
self.update_pattern()
def set_preset(self, preset):
if self.active_preset == None or self.active_preset.preset != preset:
self.active_preset = preset.activate()
def update_pattern(self):
stage = self.gameinfo.get("stage")
piece = self.gameinfo.get("piece")
estopped = self.gameinfo.get("estopped")
alliance = self.gameinfo.get("alliance")
balanced = self.gameinfo.get("balanced")
if stage == None:
self.set_preset(presets.DISCONNECTED)
elif estopped:
self.set_preset(presets.ESTOP)
# elif balanced:
# self.set_preset(presets.BALANCED)
else:
self.set_preset(presets.DEFAULT)
self.active_preset.set_slot("body", presets.HOT_FIRE if alliance == "red" else presets.COLD_FIRE)
self.active_preset.set_slot("panel", pride.RANDOM_PRIDE_FLAG)
if stage == "teleop":
self.active_preset.set_slot("arms", presets.CUBE if piece == "cube" else presets.CONE)
else:
self.active_preset.set_slot("arms", presets.RAINBOW_ARMS)
self.pattern = self.active_preset.layout().pattern()
def get_pattern(self):
return self.pattern
def update(self, lights, gameinfo):
new_props = {}
new_info = {}
for k, v in self.properties.items():
new_props[k] = lights.getValue(k, v)
for k, v in self.gameinfo.items():
new_info[k] = gameinfo.getValue(k, v)
props_updated = new_props != self.properties
info_updated = new_info != self.gameinfo
self.properties = new_props
self.gameinfo = new_info
if info_updated or props_updated:
self.update_pattern()
def push(self, nwtable):
for k, v in self.properties.items():
if v != None:
nwtable.putValue(k, v)