2022-01-17 19:39:36 +00:00
|
|
|
import logging
|
2021-10-19 10:10:04 +00:00
|
|
|
from enum import Enum, auto
|
2022-01-17 19:39:36 +00:00
|
|
|
from threading import active_count
|
|
|
|
from typing import List, Any
|
2021-10-19 10:10:04 +00:00
|
|
|
|
2022-01-20 23:11:35 +00:00
|
|
|
from pizzactrl.hal_serial import Lights, Scrolls, \
|
2022-01-17 19:39:36 +00:00
|
|
|
do_it, play_sound, take_photo, record_video, \
|
2022-01-20 23:11:35 +00:00
|
|
|
record_sound, wait_for_input, \
|
2022-01-17 19:39:36 +00:00
|
|
|
set_light, set_movement, rewind
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class ConfigurationException(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Language(Enum):
|
2022-01-20 23:11:35 +00:00
|
|
|
NOT_SET = 'sound'
|
2022-01-17 19:39:36 +00:00
|
|
|
DE = 'DE'
|
|
|
|
EN = 'EN'
|
2022-01-16 14:30:30 +00:00
|
|
|
|
2021-10-19 10:10:04 +00:00
|
|
|
|
2022-01-14 21:47:19 +00:00
|
|
|
class Option(Enum):
|
|
|
|
"""
|
|
|
|
Options can be chosen by the user in WAIT_FOR_INPUT
|
|
|
|
"""
|
2022-01-24 19:12:59 +00:00
|
|
|
CONTINUE = {'skip_flag': None} # Continue with chapter. Set `skip_flag=True` to skip all chapters marked with `skip_flag`
|
|
|
|
REPEAT = {'rewind': True} # Repeat chapter from beginning. `rewind=True`: reset scrolls to starting position
|
|
|
|
GOTO = {'chapter': 0,
|
|
|
|
'skip_flag': None} # Jump to chapter number
|
|
|
|
QUIT = {} # End playback. Will cause restart if `statemachine.loop=True`
|
2022-01-14 21:47:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Select:
|
|
|
|
"""
|
|
|
|
An option instance. Can override the default settings from `Option`s
|
|
|
|
"""
|
|
|
|
def __init__(self, option: Option, **kwargs):
|
|
|
|
self.option = option
|
|
|
|
self.values = {}
|
|
|
|
if option is not None:
|
|
|
|
for key, value in self.option.value.items():
|
|
|
|
self.values[key] = kwargs.get(key, value)
|
|
|
|
|
|
|
|
|
2021-10-19 10:10:04 +00:00
|
|
|
class Activity(Enum):
|
2022-01-14 21:47:19 +00:00
|
|
|
"""
|
|
|
|
Things the box can do
|
|
|
|
"""
|
2022-01-20 23:11:35 +00:00
|
|
|
WAIT_FOR_INPUT = {'on_blue': Select(None),
|
|
|
|
'on_red': Select(None),
|
2022-01-14 21:47:19 +00:00
|
|
|
'on_yellow': Select(None),
|
|
|
|
'on_green': Select(None),
|
2022-01-20 23:11:35 +00:00
|
|
|
'on_timeout': Select(None),
|
2022-01-17 19:39:36 +00:00
|
|
|
Language.NOT_SET.value: None,
|
|
|
|
Language.DE.value: None,
|
|
|
|
Language.EN.value: None,
|
2022-01-14 21:47:19 +00:00
|
|
|
'timeout': 0}
|
2022-01-17 19:39:36 +00:00
|
|
|
PLAY_SOUND = {Language.NOT_SET.value: None,
|
|
|
|
Language.DE.value: None,
|
|
|
|
Language.EN.value: None}
|
2022-01-14 21:47:19 +00:00
|
|
|
RECORD_SOUND = {'duration': 10.0,
|
|
|
|
'filename': '',
|
|
|
|
'cache': False}
|
|
|
|
RECORD_VIDEO = {'duration': 60.0,
|
|
|
|
'filename': ''}
|
|
|
|
TAKE_PHOTO = {'filename': ''}
|
2022-01-24 19:12:59 +00:00
|
|
|
ADVANCE_UP = {'steps': 48,
|
2022-01-18 19:41:46 +00:00
|
|
|
'scroll': Scrolls.VERTICAL,
|
2022-01-24 13:50:32 +00:00
|
|
|
'speed': 3}
|
2022-01-24 19:12:59 +00:00
|
|
|
ADVANCE_LEFT = {'steps': 92,
|
2022-01-18 19:41:46 +00:00
|
|
|
'scroll': Scrolls.HORIZONTAL,
|
2022-01-24 13:50:32 +00:00
|
|
|
'speed': 3}
|
2022-01-17 19:39:36 +00:00
|
|
|
LIGHT_FRONT = {'r': 0,
|
2022-01-14 21:47:19 +00:00
|
|
|
'g': 0,
|
|
|
|
'b': 0,
|
2022-01-17 19:39:36 +00:00
|
|
|
'w': 0,
|
2022-01-14 21:47:19 +00:00
|
|
|
'fade': 1.0,
|
2022-01-17 19:39:36 +00:00
|
|
|
'light': Lights.FRONTLIGHT}
|
2022-01-14 21:47:19 +00:00
|
|
|
LIGHT_BACK = {'r': 0,
|
|
|
|
'g': 0,
|
|
|
|
'b': 0,
|
2022-01-17 19:39:36 +00:00
|
|
|
'w': 0,
|
2022-01-14 21:47:19 +00:00
|
|
|
'fade': 1.0,
|
2022-01-17 19:39:36 +00:00
|
|
|
'light': Lights.BACKLIGHT}
|
|
|
|
PARALLEL = {'activities': []}
|
|
|
|
GOTO = {'index': 0}
|
2021-10-19 10:10:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Do:
|
2022-01-14 21:47:19 +00:00
|
|
|
"""
|
|
|
|
An activity instance. Can override the default settings from `Activity`s
|
|
|
|
"""
|
2021-10-19 10:10:04 +00:00
|
|
|
def __init__(self, activity: Activity, **kwargs):
|
|
|
|
self.activity = activity
|
|
|
|
self.values = {}
|
|
|
|
for key, value in self.activity.value.items():
|
|
|
|
self.values[key] = kwargs.get(key, value)
|
|
|
|
|
2022-01-17 19:39:36 +00:00
|
|
|
def __repr__(self) -> str:
|
|
|
|
return f'{self.activity.name}({self.values})'
|
2022-01-16 21:10:13 +00:00
|
|
|
|
2022-01-17 19:39:36 +00:00
|
|
|
def __str__(self) -> str:
|
|
|
|
return f'{self.activity.name}({self.values})'
|
2022-01-16 21:10:13 +00:00
|
|
|
|
2022-01-17 19:39:36 +00:00
|
|
|
def get_steps(self):
|
|
|
|
"""
|
|
|
|
Returns the number of steps this activity makes.
|
|
|
|
returns: h_steps, v_steps
|
|
|
|
"""
|
|
|
|
h_steps = 0
|
|
|
|
v_steps = 0
|
|
|
|
if self.activity is Activity.ADVANCE_UP:
|
|
|
|
v_steps += self.values['steps']
|
|
|
|
elif self.activity is Activity.ADVANCE_LEFT:
|
|
|
|
h_steps += self.values['steps']
|
|
|
|
elif self.activity is Activity.PARALLEL:
|
|
|
|
for act in self.values['activities']:
|
|
|
|
h, v = act.get_steps()
|
|
|
|
h_steps += h
|
|
|
|
v_steps += v
|
|
|
|
return h_steps, v_steps
|
2022-01-16 21:10:13 +00:00
|
|
|
|
2021-10-19 10:10:04 +00:00
|
|
|
|
|
|
|
class Chapter:
|
|
|
|
"""
|
2022-01-14 21:47:19 +00:00
|
|
|
A logical storyboard entity, which can be replayed (rewind to start)
|
|
|
|
or skipped (do all movements at once).
|
2021-10-19 10:10:04 +00:00
|
|
|
|
|
|
|
Keeps track of advanced steps on the scrolls.
|
|
|
|
"""
|
2022-01-20 23:11:35 +00:00
|
|
|
def __init__(self, *activities, skip_flag: bool=False):
|
2021-10-19 10:10:04 +00:00
|
|
|
self.activities = activities
|
2022-01-20 23:11:35 +00:00
|
|
|
self.skip_flag = skip_flag
|
2022-01-14 21:47:19 +00:00
|
|
|
self.index = 0
|
|
|
|
self.h_pos = 0
|
|
|
|
self.v_pos = 0
|
|
|
|
|
2021-10-19 10:10:04 +00:00
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __next__(self):
|
2022-01-14 21:47:19 +00:00
|
|
|
if self.index >= len(self.activities):
|
2021-10-19 10:10:04 +00:00
|
|
|
raise StopIteration
|
2022-01-14 21:47:19 +00:00
|
|
|
|
|
|
|
act = self.activities[self.index]
|
|
|
|
self._update_pos(act)
|
2021-10-19 10:10:04 +00:00
|
|
|
return act
|
|
|
|
|
2022-01-17 19:39:36 +00:00
|
|
|
def _update_pos(self, act: Do):
|
2022-01-14 21:47:19 +00:00
|
|
|
"""
|
|
|
|
Update the positions from the activity.
|
|
|
|
Implicitly increments the index.
|
|
|
|
"""
|
|
|
|
self.index += 1
|
2022-01-17 19:39:36 +00:00
|
|
|
h, v = act.get_steps()
|
|
|
|
self.h_pos += h
|
|
|
|
self.v_pos += v
|
2022-01-14 21:47:19 +00:00
|
|
|
|
2021-10-19 10:10:04 +00:00
|
|
|
def hasnext(self):
|
2022-01-14 21:47:19 +00:00
|
|
|
"""
|
|
|
|
Returns True if the chapter has more activities
|
|
|
|
"""
|
|
|
|
return self.index < len(self.activities)
|
2021-10-19 10:10:04 +00:00
|
|
|
|
|
|
|
def rewind(self, **kwargs):
|
2022-01-14 21:47:19 +00:00
|
|
|
"""
|
|
|
|
Reset the position to zero. Return how many steps are needed to rewind the scrolls
|
|
|
|
"""
|
|
|
|
self.index = 0
|
|
|
|
h_pos = self.h_pos
|
|
|
|
v_pos = self.v_pos
|
|
|
|
self.h_pos = 0
|
|
|
|
self.v_pos = 0
|
|
|
|
return {'h_steps': -h_pos, 'v_steps': -v_pos}
|
2021-10-19 10:10:04 +00:00
|
|
|
|
2022-01-14 21:47:19 +00:00
|
|
|
def skip(self, **kwargs):
|
|
|
|
"""
|
|
|
|
Skip chapter. Returns all movements necessary to advance scrolls.
|
|
|
|
"""
|
|
|
|
h_pos = self.h_pos
|
|
|
|
v_pos = self.v_pos
|
|
|
|
for act in self.activities[self.index:]:
|
|
|
|
self._update_pos(act)
|
|
|
|
return {'h_steps': self.h_pos - h_pos, 'v_steps': self.v_pos - v_pos}
|
2021-10-19 10:10:04 +00:00
|
|
|
|
2022-01-17 19:39:36 +00:00
|
|
|
|
2022-01-20 23:11:35 +00:00
|
|
|
def _get_sound(language: Language, **kwargs):
|
2022-01-17 19:39:36 +00:00
|
|
|
"""
|
|
|
|
Select the right sound depending on the language
|
|
|
|
"""
|
2022-01-20 23:11:35 +00:00
|
|
|
sound = kwargs.get(language.value, None)
|
|
|
|
|
2022-01-17 19:39:36 +00:00
|
|
|
if sound is None:
|
2022-01-20 23:11:35 +00:00
|
|
|
# internationalized language may be None, so check this twice
|
|
|
|
sound = kwargs.get(Language.NOT_SET.value, None)
|
|
|
|
|
|
|
|
logger.debug(f'_get_sound(language={language})={sound}')
|
2022-01-17 19:39:36 +00:00
|
|
|
|
|
|
|
return sound
|
|
|
|
|
|
|
|
|
|
|
|
class Storyboard:
|
|
|
|
def __init__(self, *story: List[Do]) -> None:
|
|
|
|
self.story = story
|
|
|
|
self.hal = None
|
|
|
|
|
|
|
|
self._index = 0 # The storyboard index of the current chapter to play
|
|
|
|
self._next_chapter = 0 # The storyboard index of the next chapter to play
|
|
|
|
self._chapter_set = False # `True` if the next chapter has been set
|
|
|
|
|
2022-01-24 13:50:32 +00:00
|
|
|
self.skip_flag = False # Set `True` to skip chapters marked with skip_flag
|
2022-01-20 23:11:35 +00:00
|
|
|
|
2022-01-24 19:12:59 +00:00
|
|
|
self.MOVE = True # self.move is reset to this value
|
2022-01-17 19:39:36 +00:00
|
|
|
self._move = self.MOVE
|
|
|
|
|
|
|
|
self._lang = Language.NOT_SET
|
|
|
|
|
|
|
|
self.ACTIVITY_SELECTOR = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def move(self) -> bool:
|
|
|
|
return self._move
|
|
|
|
|
|
|
|
@move.setter
|
|
|
|
def move(self, move: bool):
|
|
|
|
if move is None:
|
|
|
|
self._move = self.MOVE
|
|
|
|
else:
|
|
|
|
self._move = move
|
|
|
|
|
|
|
|
@property
|
|
|
|
def language(self) -> Language:
|
|
|
|
return self._lang
|
|
|
|
|
|
|
|
@language.setter
|
|
|
|
def language(self, language: Language):
|
|
|
|
self._lang = language
|
|
|
|
|
|
|
|
@property
|
|
|
|
def next_chapter(self):
|
|
|
|
return self._next_chapter
|
|
|
|
|
|
|
|
@next_chapter.setter
|
|
|
|
def next_chapter(self, next_chapter):
|
|
|
|
self._chapter_set = True
|
|
|
|
self.move = None # Reset to default value
|
|
|
|
self._next_chapter = next_chapter
|
|
|
|
|
|
|
|
def hasnext(self):
|
|
|
|
return self._index is not None
|
|
|
|
|
|
|
|
def _option_callback(self, selection: Select):
|
|
|
|
"""
|
|
|
|
Return a callback for the appropriate option and parameters.
|
|
|
|
Callbacks set the properties of `Statemachine` to determine it's behaviour.
|
|
|
|
"""
|
2022-01-24 19:12:59 +00:00
|
|
|
_rewind = selection.values.get('rewind', None)
|
|
|
|
_next_chapter = selection.values.get('chapter', None)
|
2022-01-24 13:50:32 +00:00
|
|
|
_skip_flag = selection.values.get('skip_flag', None)
|
2022-01-17 19:39:36 +00:00
|
|
|
|
2022-01-24 19:12:59 +00:00
|
|
|
def _continue():
|
2022-01-17 19:39:36 +00:00
|
|
|
"""
|
|
|
|
Continue in the Storyboard. Prepare advancing to the next chapter.
|
|
|
|
"""
|
|
|
|
logger.debug('User selected continue')
|
|
|
|
if len(self.story) > (self._index + 1):
|
|
|
|
self.next_chapter = self._index + 1
|
2022-01-24 19:12:59 +00:00
|
|
|
if _skip_flag is not None:
|
|
|
|
self.skip_flag = _skip_flag
|
2022-01-17 19:39:36 +00:00
|
|
|
else:
|
|
|
|
self.next_chapter = None
|
|
|
|
|
2022-01-24 19:12:59 +00:00
|
|
|
def _repeat():
|
2022-01-17 19:39:36 +00:00
|
|
|
"""
|
|
|
|
Repeat the current chapter. Do not rewind if the selection says so.
|
|
|
|
"""
|
|
|
|
logger.debug('User selected repeat')
|
|
|
|
self.next_chapter = self._index
|
2022-01-24 19:12:59 +00:00
|
|
|
self.move = _rewind
|
2022-01-17 19:39:36 +00:00
|
|
|
|
2022-01-24 19:12:59 +00:00
|
|
|
def _goto():
|
2022-01-17 19:39:36 +00:00
|
|
|
"""
|
|
|
|
Jump to a specified chapter.
|
|
|
|
"""
|
2022-01-24 19:12:59 +00:00
|
|
|
logger.debug(f'User selected goto {_next_chapter}')
|
|
|
|
self.next_chapter = _next_chapter
|
|
|
|
if _skip_flag is not None:
|
|
|
|
self.skip_flag = _skip_flag
|
2022-01-17 19:39:36 +00:00
|
|
|
|
2022-01-24 19:12:59 +00:00
|
|
|
def _quit():
|
2022-01-17 19:39:36 +00:00
|
|
|
logger.debug('User selected quit')
|
|
|
|
self.next_chapter = None
|
|
|
|
|
|
|
|
return {
|
|
|
|
Option.CONTINUE: _continue,
|
|
|
|
Option.REPEAT: _repeat,
|
|
|
|
Option.GOTO: _goto,
|
|
|
|
Option.QUIT: _quit,
|
|
|
|
None: None
|
|
|
|
}[selection.option]
|
|
|
|
|
|
|
|
def play_chapter(self):
|
|
|
|
"""
|
|
|
|
Play the chapter specified by self.chapter
|
|
|
|
"""
|
|
|
|
logger.debug(f'playing chapter {self._index}')
|
|
|
|
|
|
|
|
if self.hal is None:
|
|
|
|
raise ConfigurationException('Set Storyboard.hal before calling Storyboard.play_chapter()')
|
|
|
|
|
|
|
|
if self._index is None:
|
|
|
|
# Reached end of story
|
|
|
|
return
|
|
|
|
|
|
|
|
def _play_sound(hal, **kwargs):
|
|
|
|
"""
|
|
|
|
Handle Activity.PLAY_SOUND
|
|
|
|
"""
|
|
|
|
logger.debug(f'Storyboard._play_sound({kwargs})')
|
2022-01-20 23:11:35 +00:00
|
|
|
play_sound(hal, sound=_get_sound(language=self.language, **kwargs))
|
2022-01-17 19:39:36 +00:00
|
|
|
|
|
|
|
def _wait_for_input(hal, sound=None, **kwargs):
|
|
|
|
"""
|
|
|
|
Handle Activity.WAIT_FOR_INPUT
|
|
|
|
"""
|
|
|
|
logger.debug(f'Storyboard._wait_for_input({kwargs})')
|
2022-01-20 23:11:35 +00:00
|
|
|
|
|
|
|
kwargs['sound'] = _get_sound(language=self.language, **kwargs)
|
|
|
|
|
2022-01-17 19:39:36 +00:00
|
|
|
wait_for_input(hal=hal,
|
|
|
|
blue_cb = self._option_callback(kwargs['on_blue']),
|
|
|
|
red_cb = self._option_callback(kwargs['on_red']),
|
|
|
|
yellow_cb = self._option_callback(kwargs['on_yellow']),
|
|
|
|
green_cb = self._option_callback(kwargs['on_green']),
|
|
|
|
timeout_cb = self._option_callback(kwargs['on_timeout']),
|
|
|
|
**kwargs)
|
|
|
|
|
|
|
|
def _parallel(hal, activities: List[Do], **kwargs):
|
|
|
|
"""
|
|
|
|
Handle Activity.PARALLEL
|
|
|
|
"""
|
|
|
|
logger.debug(f'Storyboard._parallel({activities})')
|
|
|
|
for paract in activities:
|
2022-01-20 23:11:35 +00:00
|
|
|
self.ACTIVITY_SELECTOR[paract.activity](hal, do_now=False, **paract.values)
|
2022-01-17 19:39:36 +00:00
|
|
|
do_it(self.hal)
|
|
|
|
|
|
|
|
def _move(hal, do_now=True, **kwargs):
|
|
|
|
logger.debug(f'Storyboard._move({kwargs})')
|
2022-01-24 19:12:59 +00:00
|
|
|
if not self.move:
|
|
|
|
return
|
2022-01-17 19:39:36 +00:00
|
|
|
set_movement(hal, **kwargs)
|
|
|
|
if do_now:
|
|
|
|
do_it(hal)
|
|
|
|
|
|
|
|
def _light(hal, do_now=True, **kwargs):
|
|
|
|
logger.debug(f'Storyboard._light({kwargs})')
|
|
|
|
set_light(hal, **kwargs)
|
|
|
|
if do_now:
|
|
|
|
do_it(hal)
|
|
|
|
|
|
|
|
def _goto(hal, index:int, **kwargs):
|
|
|
|
"""
|
|
|
|
Set the next chapter
|
|
|
|
"""
|
|
|
|
logger.debug(f'Storyboard._goto({kwargs})')
|
|
|
|
self.next_chapter = index
|
|
|
|
|
|
|
|
self.ACTIVITY_SELECTOR = {
|
|
|
|
Activity.PLAY_SOUND: _play_sound,
|
|
|
|
Activity.WAIT_FOR_INPUT: _wait_for_input,
|
|
|
|
Activity.PARALLEL: _parallel,
|
|
|
|
Activity.GOTO: _goto,
|
|
|
|
Activity.RECORD_SOUND: record_sound,
|
|
|
|
Activity.RECORD_VIDEO: record_video,
|
|
|
|
Activity.TAKE_PHOTO: take_photo,
|
|
|
|
Activity.LIGHT_FRONT: _light,
|
|
|
|
Activity.LIGHT_BACK: _light,
|
|
|
|
Activity.ADVANCE_UP: _move,
|
|
|
|
Activity.ADVANCE_LEFT: _move,
|
|
|
|
}
|
|
|
|
|
|
|
|
if self._index < len(self.story):
|
|
|
|
chapter = self.story[self._index]
|
2022-01-24 13:50:32 +00:00
|
|
|
if self.skip_flag and chapter.skip_flag:
|
2022-01-20 23:11:35 +00:00
|
|
|
# Skip all chapters marked with skip_flag
|
|
|
|
self.next_chapter = self._index + 1
|
|
|
|
self._chapter_set = True
|
|
|
|
return
|
2022-01-17 19:39:36 +00:00
|
|
|
|
2022-01-24 13:50:32 +00:00
|
|
|
while chapter.hasnext() and self.hal.lid_open:
|
2022-01-17 19:39:36 +00:00
|
|
|
act = next(chapter)
|
|
|
|
logger.debug(f'next activity {act.activity}')
|
|
|
|
try:
|
|
|
|
self.ACTIVITY_SELECTOR[act.activity](self.hal, **act.values)
|
|
|
|
except KeyError as e:
|
2022-01-20 23:11:35 +00:00
|
|
|
raise ConfigurationException(f'Missing handler for {act.activity}', e)
|
2022-01-17 19:39:36 +00:00
|
|
|
|
|
|
|
if not self._chapter_set:
|
|
|
|
self._chapter_set = True
|
|
|
|
self._next_chapter = self._index + 1
|
|
|
|
|
|
|
|
else:
|
|
|
|
self._next_chapter = None
|
|
|
|
|
|
|
|
def advance_chapter(self):
|
|
|
|
"""
|
|
|
|
Update chapters and move the scrolls.
|
|
|
|
Update self.chapter to self.next_chapter
|
|
|
|
"""
|
|
|
|
if not self._chapter_set:
|
|
|
|
return
|
|
|
|
elif self._index is None:
|
|
|
|
return
|
|
|
|
elif self._next_chapter is not None:
|
|
|
|
diff = self._next_chapter - self._index
|
|
|
|
h_steps = 0
|
|
|
|
v_steps = 0
|
|
|
|
if diff < 0:
|
|
|
|
"""
|
|
|
|
Rewind all chapters up to target
|
|
|
|
"""
|
|
|
|
for ch in self.story[self._next_chapter:self._index]:
|
|
|
|
steps = ch.rewind()
|
|
|
|
h_steps += steps['h_steps']
|
|
|
|
v_steps += steps['v_steps']
|
|
|
|
elif diff > 0:
|
|
|
|
"""
|
|
|
|
Skip all chapters up to target
|
|
|
|
"""
|
|
|
|
for ch in self.story[self._index:self._next_chapter]:
|
2022-01-24 19:12:59 +00:00
|
|
|
logger.debug(f'Queueing chapter {ch} for skipping')
|
2022-01-17 19:39:36 +00:00
|
|
|
steps = ch.skip()
|
|
|
|
h_steps += steps['h_steps']
|
|
|
|
v_steps += steps['v_steps']
|
|
|
|
else:
|
|
|
|
"""
|
|
|
|
Rewind current chapter
|
|
|
|
"""
|
|
|
|
steps = self.story[self._index].rewind()
|
|
|
|
h_steps = steps['h_steps']
|
|
|
|
v_steps = steps['v_steps']
|
|
|
|
|
2022-01-24 19:12:59 +00:00
|
|
|
logger.debug(f'storyboard.move={self.move} and h_steps={h_steps}, v_steps={v_steps}.')
|
2022-01-24 13:50:32 +00:00
|
|
|
if self.move and ((h_steps != 0) or (v_steps != 0)):
|
2022-01-20 23:11:35 +00:00
|
|
|
set_movement(self.hal, scroll=Scrolls.HORIZONTAL, steps=h_steps, speed=4)
|
|
|
|
set_movement(self.hal, scroll=Scrolls.VERTICAL, steps=v_steps, speed=4)
|
2022-01-17 19:39:36 +00:00
|
|
|
do_it(self.hal)
|
|
|
|
|
|
|
|
logger.debug(f'Setting chapter (cur: {self._index}) to {self._next_chapter}.')
|
|
|
|
self._index = self._next_chapter
|
|
|
|
self._chapter_set = False
|
|
|
|
|
|
|
|
def rewind(self):
|
|
|
|
if self.hal is None:
|
|
|
|
raise ConfigurationException('Set Storyboard.hal before calling Storyboard.rewind()')
|
|
|
|
|
|
|
|
if self.move:
|
|
|
|
rewind(self.hal)
|
|
|
|
|
|
|
|
for chapter in self.story:
|
|
|
|
chapter.rewind()
|
|
|
|
|
|
|
|
self._index = self._next_chapter = 0
|