(
            cls, game, outstr, lua_writer_cls=None,
            lua_writer_args=None, filename=None,
            label_fname=None, *args, **kwargs)
Writes a game to a .p8.png 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 output filename, for error messages.
          label_fname: The .p8.png file (or appropriately spec'd .png file)
            to use for the label. If None, uses a PICO-8-generated empty label.
Writes a game to a .p8.png file.
Writes a game to a . p8 . png file .
def to_file(
            cls, game, outstr, lua_writer_cls=None,
            lua_writer_args=None, filename=None,
            label_fname=None, *args, **kwargs):
        """Writes a game to a .p8.png 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 output filename, for error messages.
          label_fname: The .p8.png file (or appropriately spec'd .png file)
            to use for the label. If None, uses a PICO-8-generated empty label.
        """
        # To install: python3 -m pip install pypng
        import png

        # TODO: If game.label, use EMPTY_LABEL_FNAME and substitute the
        # appropriate img_data
        label_fname = label_fname or EMPTY_LABEL_FNAME
        try:
            with open(label_fname, 'rb') as label_fh:
                r = png.Reader(file=label_fh)
                (width, height, img_data, attrs) = r.read()
                img_data = list(img_data)
        except png.Error:
            raise InvalidP8PNGError()

        cart_lua = game.lua.to_lines(writer_cls=lua_writer_cls,
                                     writer_args=lua_writer_args)
        code_bytes = get_bytes_from_code(b''.join(cart_lua))

        picodata = b''.join((game.gfx.to_bytes(),
                             game.map.to_bytes(),
                             game.gff.to_bytes(),
                             game.music.to_bytes(),
                             game.sfx.to_bytes(),
                             code_bytes,
                             bytes((game.version,))))

        new_rows = get_pngdata_from_picodata(picodata, img_data, attrs)

        wr = png.Writer(width, height, **attrs)
        wr.write(outstr, new_rows)
def to_file ( cls , game , outstr , lua_writer_cls = None , lua_writer_args = None , filename = None , label_fname = None , * args , * * kwargs ) : # To install: python3 -m pip install pypng import png # TODO: If game.label, use EMPTY_LABEL_FNAME and substitute the # appropriate img_data label_fname = label_fname or EMPTY_LABEL_FNAME try : with open ( label_fname , 'rb' ) as label_fh : r = png . Reader ( file = label_fh ) ( width , height , img_data , attrs ) = r . read ( ) img_data = list ( img_data ) except png . Error : raise InvalidP8PNGError ( ) cart_lua = game . lua . to_lines ( writer_cls = lua_writer_cls , writer_args = lua_writer_args ) code_bytes = get_bytes_from_code ( b'' . join ( cart_lua ) ) picodata = b'' . join ( ( game . gfx . to_bytes ( ) , game . map . to_bytes ( ) , game . gff . to_bytes ( ) , game . music . to_bytes ( ) , game . sfx . to_bytes ( ) , code_bytes , bytes ( ( game . version , ) ) ) ) new_rows = get_pngdata_from_picodata ( picodata , img_data , attrs ) wr = png . Writer ( width , height , * * attrs ) wr . write ( outstr , new_rows )