<commit_before>from pyglet.image import ImageData, AnimationFrame, Animation

from .raw_adapter import RawAdapter

class PygletAdapter(RawAdapter):
    """
        An extension to the `RawAdapter`: return an `pyglet.image.ImageData` object.
    """
    def __init__(self, frame):
        RawAdapter.__init__(self, frame)
        # Since genie *seems* to specify the hotspot relative to
        # the top left corner and pyglet wants it relative to the
        # bottom left corner, we need to do some calculations here.
        self.anchor_x, self.anchor_y = frame.hotspot_x, frame.height - frame.hotspot_y

    def get_image(self):
        # We need to pass a negative stride here since the image
        # will be upside-down otherwise.
        img = ImageData(self.width, self.height,
                        'RGBA', str(self.array), -self.stride)
        img.anchor_x = self.anchor_x
        img.anchor_y = self.anchor_y
        return img

class MirroredPygletAdapter(PygletAdapter):
    """
        Exactly like the above, it's just mirrored. For simplicity, since
        Age Of Empires doesn't store all the animation directions, you have
        to mirror the existing frames to get the missing images.
    """
    def _get_byte_pos(self, x, y):
        # mirror dat. ehehehehehAHAHAHAHAH
        return y * self.stride + (self.width - x) * self.pixel_size

def load_animation(slp_file, frame_ids, duration=0.1, mirrored=False, player=1):
    """
        Load some frames from the slp fil into an `pyglet.image.Animation` instance.
        *frame_ids* is a tuple ``(first frame, last frame)`` (inclusive).<commit_msg>Mirrored Pyglet Adapter: Flip the x anchor (but it has no effect. meh.)<commit_after>from pyglet.image import ImageData, AnimationFrame, Animation

from .raw_adapter import RawAdapter

class PygletAdapter(RawAdapter):
    """
        An extension to the `RawAdapter`: return an `pyglet.image.ImageData` object.
    """
    def __init__(self, frame):
        RawAdapter.__init__(self, frame)
        # Since genie *seems* to specify the hotspot relative to
        # the top left corner and pyglet wants it relative to the
        # bottom left corner, we need to do some calculations here.
        self.anchor_x, self.anchor_y = frame.hotspot_x, frame.height - frame.hotspot_y

    def get_image(self):
        # We need to pass a negative stride here since the image
        # will be upside-down otherwise.
        img = ImageData(self.width, self.height,
                        'RGBA', str(self.array), -self.stride)
        img.anchor_x = self.anchor_x
        img.anchor_y = self.anchor_y
        return img

class MirroredPygletAdapter(PygletAdapter):
    """
        Exactly like the above, it's just mirrored. For simplicity, since
        Age Of Empires doesn't store all the animation directions, you have
        to mirror the existing frames to get the missing images.

        Also, flip the X anchor if needed.
    """
    def __init__(self, frame):
        PygletAdapter.__init__(self, frame)
        self.anchor_x = frame.width - self.anchor_x

    def _get_byte_pos(self, x, y):
        # mirror dat. ehehehehehAHAHAHAHAH
        return y * self.stride + (self.width - x) * self.pixel_size

def load_animation(slp_file, frame_ids, duration=0.1, mirrored=False, player=1):
    """
        Load some frames from the slp fil into an `pyglet.image.Animation` instance.
        *frame_ids* is a tuple ``(first frame, last frame)`` (inclusive).
{'fraction_non_alphanumeric': 0.0861573808156232, 'fraction_numerical': 0.0017231476163124641, 'mean_word_length': 2.7532327586206895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4709799', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1015, 'n_words': 350}