mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 15:01:32 +00:00
Add step_next trigger to LinearFSM allowing stateless stepping
This commit is contained in:
parent
06e17a6591
commit
d1305bc879
@ -5,14 +5,18 @@ from .fsm_base import FSMBase
|
|||||||
|
|
||||||
|
|
||||||
class LinearFSM(FSMBase):
|
class LinearFSM(FSMBase):
|
||||||
|
# pylint: disable=anomalous-backslash-in-string
|
||||||
"""
|
"""
|
||||||
This is a state machine for challenges with linear progression, consisting of
|
This is a state machine for challenges with linear progression, consisting of
|
||||||
a number of steps specified in the constructor. It automatically sets up a single
|
a number of steps specified in the constructor. It automatically sets up 2
|
||||||
action between states as such:
|
actions (triggers) between states as such:
|
||||||
0 ==step_1==> 1 ==step_2==> 2 ==step_3==> 3 ... and so on
|
(0) -- step_1 --> (1) -- step_2 --> (2) -- step_3 --> (3) ... and so on
|
||||||
|
\-step_next-/ \-step_next-/ \-step_next-/
|
||||||
"""
|
"""
|
||||||
def __init__(self, number_of_steps):
|
def __init__(self, number_of_steps):
|
||||||
self.states = list(map(str, range(number_of_steps)))
|
self.states = list(map(str, range(number_of_steps)))
|
||||||
self.transitions = [{'trigger': f'step_{int(index)+1}', 'source': index, 'dest': str(int(index)+1)}
|
self.transitions = []
|
||||||
for index in self.states[:-1]]
|
for index in self.states[:-1]:
|
||||||
|
self.transitions.append({'trigger': f'step_{int(index)+1}', 'source': index, 'dest': str(int(index)+1)})
|
||||||
|
self.transitions.append({'trigger': 'step_next', 'source': index, 'dest': str(int(index)+1)})
|
||||||
super(LinearFSM, self).__init__()
|
super(LinearFSM, self).__init__()
|
||||||
|
Loading…
Reference in New Issue
Block a user