Repository navigation
Expand file tree
/
Copy pathtutorialState.py
More file actions
149 lines (109 loc) · 3.98 KB
/
Copy pathtutorialState.py
File metadata and controls
149 lines (109 loc) · 3.98 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
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
142
143
144
145
146
147
from playsound import playsound
from utils.protocol import ProtocolGenerator
from utils.speak import Speak
from utils.utils import speakSentence
class TutoState:
stateName : str
# ! tuto : TutorialState --> pas possible d'importer ou de setup
# ! l'IDE dectect un import circulair + class declarer avant son initialisation
# !!!!!!!!!!!!!!!!!!!!!!!!! vvvvvvvv Suprimer pour eviter les inport circulaire
def __init__(self, tuto):
self.tuto = tuto
def process(self):
pass
def handleDelay(self):
pass
def handleSwitch(self):
pass
def handleButton(self):
pass
class TutoSetupState(TutoState):
stateName = "setup-state"
def process(self):
losts = self.getConnectionLost()
isBroken = self.checkConnectionLost(losts)
if isBroken:
print("Lost : ", losts)
self.speakError(losts)
self.tuto.setState(TutoReturnState(self.tuto))
else :
self.tuto.setState(TutoStartState(self.tuto))
print("Pas de bug detecter")
def getConnectionLost(self) -> list[str]:
return self.tuto.plant.connectionManager.discClients
def checkConnectionLost(self, cl : list[str]) -> bool:
if len(cl) > 0:
return True
else:
return False
def speakError(self, losts : list[str]):
str = ""
for lost in losts:
str = str + f"{lost}, "
str = f"Oups j’ai un petit soucis technique, les capteurs : {str}sont déconnectés. Je te conseille de me redemarer."
Speak.speak(str)
class TutoStartState(TutoState):
stateName = "start-state"
def process(self):
self.speakStart()
self.tuto.setState(TutoTestButtonState(self.tuto))
def speakStart(self):
sentences = self.tuto.plant.sentence["tutorial"]["start"]
print("sentences", sentences)
speakSentence(sentences)
class TutoTestButtonState(TutoState):
stateName = "button-test-state"
delay = 7
def process(self):
self.speakButton()
self.delayRepeat()
def handleDelay(self):
self.process()
def handleButton(self):
self.tuto.setState(TutoTestSwitchState(self.tuto))
def delayRepeat(self):
cls = self.tuto.plant.connectionManager.clients
res = dict((v,k) for k,v in cls.items())
cl = res["eureka"]
data = ProtocolGenerator(self.stateName,str(self.delay))
cl.send_message(data.create())
def speakButton(self):
sentences = self.tuto.plant.sentence["tutorial"]["button"]
speakSentence(sentences)
class TutoTestSwitchState(TutoState):
stateName = "switch-test-state"
delay = 7
switchSound = "./db/sound/switch.mp3"
xrpSound = "./db/sound/xrp.mp3"
def process(self):
self.speakSwitch()
self.delayRepeat()
def handleDelay(self):
self.process()
def handleSwitch(self):
playsound(self.switchSound)
self.tuto.setState(TutoEndState(self.tuto))
def delayRepeat(self):
cls = self.tuto.plant.connectionManager.clients
res = dict((v,k) for k,v in cls.items())
cl = res["eureka"]
data = ProtocolGenerator(self.stateName,str(self.delay))
cl.send_message(data.create())
def speakSwitch(self):
sentencesBefore = self.tuto.plant.sentence["tutorial"]["switch"]["before"]
sentencesAfter = self.tuto.plant.sentence["tutorial"]["switch"]["after"]
speakSentence(sentencesBefore)
playsound(self.xrpSound)
speakSentence(sentencesAfter)
class TutoEndState(TutoState):
stateName = "end-state"
def process(self):
self.speakEnd()
self.tuto.setState(TutoReturnState(self.tuto))
def speakEnd(self):
sentences = self.tuto.plant.sentence["tutorial"]["end"]
speakSentence(sentences)
class TutoReturnState(TutoState):
stateName = "return-state"
def process(self):
self.tuto.goToNextState()