<s> """<STR_LIT>""" <EOL> import time <EOL> from mpf . media_controller . core . display import DisplayElement <EOL> import mpf . media_controller . display_modules . dmd <EOL> from mpf . system . assets import Asset <EOL> dmd_palette = [ ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:6> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:0> ) ] * <NUM_LIT:16> <EOL> class Animation ( Asset ) : <EOL> def _initialize_asset ( self ) : <EOL> if '<STR_LIT>' in self . config : <EOL> self . alpha_color = ( self . config [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . alpha_color = None <EOL> self . surface_list = None <EOL> def do_load ( self , callback ) : <EOL> if self . file_name . endswith ( '<STR_LIT>' ) : <EOL> self . surface_list = mpf . media_controller . display_modules . dmd . load_dmd_file ( <EOL> self . file_name , <EOL> dmd_palette , <EOL> self . alpha_color ) <EOL> else : <EOL> pass <EOL> self . loaded = True <EOL> if callback : <EOL> callback ( ) <EOL> def _unload ( self ) : <EOL> self . surface_list = None <EOL> class AnimationDisplayElement ( DisplayElement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , slide , machine , animation , width = None , height = None , <EOL> start_frame = <NUM_LIT:0> , fps = <NUM_LIT:10> , repeat = False , drop_frames = True , <EOL> play_now = True , x = None , y = None , h_pos = None , <EOL> v_pos = None , layer = <NUM_LIT:0> , ** kwargs ) : <EOL> super ( AnimationDisplayElement , self ) . __init__ ( slide , x , y , h_pos , v_pos , <EOL> layer ) <EOL> self . loadable_asset = True <EOL> self . machine = machine <EOL> if animation not in machine . animations : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . animation = machine . animations [ animation ] <EOL> self . current_frame = start_frame <EOL> self . fps = <NUM_LIT:0> <EOL> self . repeat = repeat <EOL> self . drop_frames = drop_frames <EOL> self . playing = False <EOL> self . secs_per_frame = <NUM_LIT:0> <EOL> self . next_frame_time = <NUM_LIT:0> <EOL> self . last_frame_time = <NUM_LIT:0> <EOL> self . set_fps ( fps ) <EOL> self . layer = layer <EOL> if self . animation . loaded : <EOL> self . _asset_loaded ( ) <EOL> else : <EOL> self . ready = False <EOL> self . animation . load ( callback = self . _asset_loaded ) <EOL> if play_now : <EOL> self . play ( ) <EOL> def _asset_loaded ( self ) : <EOL> self . surface_list = self . animation . surface_list <EOL> self . total_frames = len ( self . surface_list ) <EOL> self . element_surface = self . surface_list [ self . current_frame ] <EOL> self . set_position ( self . x , self . y , self . h_pos , self . v_pos ) <EOL> self . ready = True <EOL> super ( AnimationDisplayElement , self ) . _asset_loaded ( ) <EOL> def set_fps ( self , fps ) : <EOL> """<STR_LIT>""" <EOL> self . fps = fps <EOL> self . secs_per_frame = ( <NUM_LIT:1> / float ( self . fps ) ) <EOL> self . next_frame_time = <NUM_LIT:0> <EOL> def play ( self , fps = None , start_frame = None , repeat = None ) : <EOL> """<STR_LIT>""" <EOL> if fps : <EOL> self . set_fps ( fps ) <EOL> if start_frame : <EOL> self . current_frame = start_frame <EOL> if type ( repeat ) is bool : <EOL> self . repeat = repeat <EOL> self . next_frame_time = <NUM_LIT:0> <EOL> self . playing = True <EOL> self . dirty = True <EOL> def stop ( self , reset = False ) : <EOL> """<STR_LIT>""" <EOL> if reset : <EOL> self . current_frame = <NUM_LIT:0> <EOL> self . playing = False <EOL> self . next_frame_time = <NUM_LIT:0> <EOL> def stop_when_done ( self ) : <EOL> """<STR_LIT>""" <EOL> self . repeat = False <EOL> def jump_to_frame ( self , frame , show_now = False ) : <EOL> """<STR_LIT>""" <EOL> self . current_frame = frame <EOL> if show_now : <EOL> self . show_frame ( ) <EOL> def jump ( self , num_frames , show_now = False ) : <EOL> """<STR_LIT>""" <EOL> current_frame = self . current_frame <EOL> current_frame += num_frames <EOL> while current_frame > ( self . total_frames - <NUM_LIT:1> ) : <EOL> if self . repeat : <EOL> current_frame -= self . total_frames <EOL> else : <EOL> current_frame = self . total_frames - <NUM_LIT:1> <EOL> self . playing = False <EOL> self . current_frame = current_frame <EOL> if show_now : <EOL> self . show_frame ( ) <EOL> def show_frame ( self ) : <EOL> """<STR_LIT>""" <EOL> self . element_surface = self . surface_list [ self . current_frame ] <EOL> self . dirty = True <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . playing : <EOL> return <EOL> current_time = time . time ( ) <EOL> if not self . next_frame_time : <EOL> self . last_frame_time = current_time <EOL> self . next_frame_time = current_time <EOL> if self . next_frame_time <= current_time : <EOL> num_frames = int ( ( current_time - self . last_frame_time ) / <EOL> self . secs_per_frame ) <EOL> self . last_frame_time = self . next_frame_time <EOL> if num_frames > <NUM_LIT:1> : <EOL> if self . drop_frames : <EOL> self . next_frame_time = current_time + self . secs_per_frame <EOL> else : <EOL> self . next_frame_time = current_time <EOL> num_frames = <NUM_LIT:1> <EOL> else : <EOL> self . next_frame_time = current_time + self . secs_per_frame <EOL> self . jump ( num_frames , show_now = True ) <EOL> self . decorate ( ) <EOL> return True <EOL> if self . decorate ( ) : <EOL> return True <EOL> return False <EOL> asset_class = Animation <EOL> asset_attribute = '<STR_LIT>' <EOL> display_element_class = AnimationDisplayElement <EOL> create_asset_manager = True <EOL> path_string = '<STR_LIT>' <EOL> config_section = '<STR_LIT>' <EOL> file_extensions = ( '<STR_LIT>' , ) </s>
