-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.py
More file actions
41 lines (28 loc) · 1.05 KB
/
State.py
File metadata and controls
41 lines (28 loc) · 1.05 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
from Transition import Transition
class State:
def __init__(self, stateName, StateFn):
self._stateName = stateName
self.StateFn = StateFn
self._transitions = []
def __del__(self):
ClearTransitions()
def ClearTransitions(self):
for i in range(len(self._transitions)):
del self._transitions[i]
def AddTransition(self, to, TransitionFn):
self._transitions.append(Transition(to, TransitionFn))
def Is(self, stateName):
return self._stateName == stateName
def Name(self):
return self._stateName
def RunState(self):
if(self.StateFn != None):
self.StateFn()
def GetNextState(self):
for i in range(len(self._transitions)):
t = self._transitions[i]
if(t.ShouldTransition()):
#print("GetNextState() is returning a new state")
return t.To()
#If no transitions, next state is the current state
return self._stateName