(
            cls, game, outstr, lua_writer_cls=None, lua_writer_args=None,
            filename=None, *args, **kwargs)
Writes a game to a file.

        Args:
          game: The Game to write.
          outstr: The output stream.
          lua_writer_cls: The Lua writer class to use. If None, defaults to
            LuaEchoWriter.
          lua_writer_args: Args to pass to the Lua writer.
          filename: The filename, if any, for tool messages.
Writes a game to a file.
Writes a game to a file .
def to_file(
            cls, game, outstr, lua_writer_cls=None, lua_writer_args=None,
            filename=None, *args, **kwargs):
        """Writes a game to a file.

        Args:
          game: The Game to write.
          outstr: The output stream.
          lua_writer_cls: The Lua writer class to use. If None, defaults to
            LuaEchoWriter.
          lua_writer_args: Args to pass to the Lua writer.
          filename: The filename, if any, for tool messages.
        """
        outstr.write(HEADER_TITLE_STR)

        outstr.write(bytes('version %s\n' % game.version, 'utf-8'))

        # Sanity-check the Lua written by the writer.
        transformed_lua = lua.Lua.from_lines(
            game.lua.to_lines(writer_cls=lua_writer_cls,
                              writer_args=lua_writer_args),
            version=(game.version or 0))
        if transformed_lua.get_char_count() > lua.PICO8_LUA_CHAR_LIMIT:
            if filename is not None:
                util.error('{}: '.format(filename))
            util.error('warning: character count {} exceeds the PICO-8 '
                       'limit of {}\n'.format(
                           transformed_lua.get_char_count(),
                           lua.PICO8_LUA_CHAR_LIMIT))
        if transformed_lua.get_token_count() > lua.PICO8_LUA_TOKEN_LIMIT:
            if filename is not None:
                util.error('{}: '.format(filename))
            util.error('warning: token count {} exceeds the PICO-8 '
                       'limit of {}\n'.format(
                           transformed_lua.get_token_count(),
                           lua.PICO8_LUA_TOKEN_LIMIT))

        outstr.write(b'__lua__\n')
        ended_in_newline = None
        for line in game.lua.to_lines(
                writer_cls=lua_writer_cls,
                writer_args=lua_writer_args):
            outstr.write(bytes(lua.p8scii_to_unicode(line), 'utf-8'))
            ended_in_newline = line.endswith(b'\n')
        if not ended_in_newline:
            outstr.write(b'\n')

        outstr.write(b'__gfx__\n')
        for line in game.gfx.to_lines():
            outstr.write(line)

        if game.label:
            outstr.write(b'__label__\n')
            for line in game.label.to_lines():
                outstr.write(line)

        # PICO-8 emits an extra newline before __gff__ for no good reason, as
        # of 0.1.10c. PICO-8 doesn't care whether we do, but our tests want to
        # match the test cart data exactly.
        outstr.write(b'\n')
        outstr.write(b'__gff__\n')
        for line in game.gff.to_lines():
            outstr.write(line)

        outstr.write(b'__map__\n')
        for line in game.map.to_lines():
            outstr.write(line)

        outstr.write(b'__sfx__\n')
        for line in game.sfx.to_lines():
            outstr.write(line)

        outstr.write(b'__music__\n')
        for line in game.music.to_lines():
            outstr.write(line)

        outstr.write(b'\n')
def to_file ( cls , game , outstr , lua_writer_cls = None , lua_writer_args = None , filename = None , * args , * * kwargs ) : outstr . write ( HEADER_TITLE_STR ) outstr . write ( bytes ( 'version %s\n' % game . version , 'utf-8' ) ) # Sanity-check the Lua written by the writer. transformed_lua = lua . Lua . from_lines ( game . lua . to_lines ( writer_cls = lua_writer_cls , writer_args = lua_writer_args ) , version = ( game . version or 0 ) ) if transformed_lua . get_char_count ( ) > lua . PICO8_LUA_CHAR_LIMIT : if filename is not None : util . error ( '{}: ' . format ( filename ) ) util . error ( 'warning: character count {} exceeds the PICO-8 ' 'limit of {}\n' . format ( transformed_lua . get_char_count ( ) , lua . PICO8_LUA_CHAR_LIMIT ) ) if transformed_lua . get_token_count ( ) > lua . PICO8_LUA_TOKEN_LIMIT : if filename is not None : util . error ( '{}: ' . format ( filename ) ) util . error ( 'warning: token count {} exceeds the PICO-8 ' 'limit of {}\n' . format ( transformed_lua . get_token_count ( ) , lua . PICO8_LUA_TOKEN_LIMIT ) ) outstr . write ( b'__lua__\n' ) ended_in_newline = None for line in game . lua . to_lines ( writer_cls = lua_writer_cls , writer_args = lua_writer_args ) : outstr . write ( bytes ( lua . p8scii_to_unicode ( line ) , 'utf-8' ) ) ended_in_newline = line . endswith ( b'\n' ) if not ended_in_newline : outstr . write ( b'\n' ) outstr . write ( b'__gfx__\n' ) for line in game . gfx . to_lines ( ) : outstr . write ( line ) if game . label : outstr . write ( b'__label__\n' ) for line in game . label . to_lines ( ) : outstr . write ( line ) # PICO-8 emits an extra newline before __gff__ for no good reason, as # of 0.1.10c. PICO-8 doesn't care whether we do, but our tests want to # match the test cart data exactly. outstr . write ( b'\n' ) outstr . write ( b'__gff__\n' ) for line in game . gff . to_lines ( ) : outstr . write ( line ) outstr . write ( b'__map__\n' ) for line in game . map . to_lines ( ) : outstr . write ( line ) outstr . write ( b'__sfx__\n' ) for line in game . sfx . to_lines ( ) : outstr . write ( line ) outstr . write ( b'__music__\n' ) for line in game . music . to_lines ( ) : outstr . write ( line ) outstr . write ( b'\n' )