#NEWLINE# @ classmethod #NEWLINE# def from_p8_file( cls , instr , filename = None ) : #NEWLINE# #INDENT# 'Loads a game from a .p8 file.\n    \n        Args:\n          instr: The input stream.\n          filename: The filename, if any, for tool messages.\n    \n        Returns:\n          A Game containing the game data.\n    \n        Raises:\n          InvalidP8HeaderError\n        ' #NEWLINE# header_title_str = instr . readline ( ) #NEWLINE# if ( header_title_str != HEADER_TITLE_STR ) : #NEWLINE# #INDENT# raise InvalidP8HeaderError ( ) #NEWLINE# #UNINDENT# header_version_str = instr . readline ( ) #NEWLINE# version_m = HEADER_VERSION_RE . match ( header_version_str ) #NEWLINE# if ( version_m is None ) : #NEWLINE# #INDENT# raise InvalidP8HeaderError ( ) #NEWLINE# #UNINDENT# version = int ( version_m . group ( 1 ) ) #NEWLINE# section = None #NEWLINE# section_lines = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# while True : #NEWLINE# #INDENT# line = instr . readline ( ) #NEWLINE# if ( not line ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# section_delim_m = SECTION_DELIM_RE . match ( line ) #NEWLINE# if section_delim_m : #NEWLINE# #INDENT# section = section_delim_m . group ( 1 ) #NEWLINE# section_lines [ section ] = [ ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if section : #NEWLINE# #INDENT# section_lines [ section ] . append ( line ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# new_game = cls . make_empty_game ( filename = filename ) #NEWLINE# new_game . version = version #NEWLINE# for section in section_lines : #NEWLINE# #INDENT# if ( section == 'lua' ) : #NEWLINE# #INDENT# new_game . lua = Lua . from_lines ( section_lines [ section ] , version = version ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( section == 'gfx' ) : #NEWLINE# #INDENT# new_game . gfx = Gfx . from_lines ( section_lines [ section ] , version = version ) #NEWLINE# my_map = getattr ( new_game , 'map' ) #NEWLINE# if ( my_map is not None ) : #NEWLINE# #INDENT# my_map . _gfx = new_game . gfx #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( section == 'gff' ) : #NEWLINE# #INDENT# new_game . gff = Gff . from_lines ( section_lines [ section ] , version = version ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( section == 'map' ) : #NEWLINE# #INDENT# my_gfx = getattr ( new_game , 'gfx' ) #NEWLINE# new_game . map = Map . from_lines ( section_lines [ section ] , version = version , gfx = my_gfx ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( section == 'sfx' ) : #NEWLINE# #INDENT# new_game . sfx = Sfx . from_lines ( section_lines [ section ] , version = version ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( section == 'music' ) : #NEWLINE# #INDENT# new_game . music = Music . from_lines ( section_lines [ section ] , version = version ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise InvalidP8SectionError ( section ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return new_game