示例#1
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_has_correct_triggers(data_files):
    act = open_act(data_files['agav.act'])
    triggers = (
        "vanberk_move.wav",
        "vanberk_attack.wav",
        "vanberk_damage.wav",
        "vanberk_die.wav",
        "atk",
    )
    for idx, trigger in enumerate(triggers):
        assert act.triggers[idx] == trigger
示例#2
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_layer_is_correctly_flipped(data_files, name, flipped):
    act = open_act(data_files[name])
    assert act.animations[0].frames[0].layers[0].flipped == flipped
示例#3
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_layer_has_correct_index(data_files):
    act = open_act(data_files['cursors.act'])
    assert act.animations[0].frames[0].layers[0].index == 0
    assert act.animations[1].frames[1].layers[0].index == 16
示例#4
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_layer_has_correct_position(data_files):
    act = open_act(data_files['cursors.act'])
    assert act.animations[0].frames[0].layers[0].offset == (11, 15)
    assert act.animations[1].frames[1].layers[0].offset == (0, -1)
示例#5
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_frame_has_correct_trigger_id(data_files):
    act = open_act(data_files['agav.act'])
    assert act.animations[0].frames[0].trigger == -1
    assert act.animations[8].frames[7].trigger == 0
示例#6
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_frame_has_correct_layer_count(data_files):
    act = open_act(data_files['cursors.act'])
    assert len(act.animations[0].frames[0].layers) == 1
    assert len(act.animations[1].frames[8].layers) == 4
示例#7
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_animation_has_correct_frame_count(data_files, name, counts):
    act = open_act(data_files[name])
    assert len(act.animations[0].frames) == counts[0]
    assert len(act.animations[1].frames) == counts[1]
    assert len(act.animations[2].frames) == counts[2]
示例#8
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_animation_has_correct_interval(data_files, name, interval):
    act = open_act(data_files[name])
    assert act.animations[0].interval == interval
示例#9
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_has_correct_trigger_count(data_files, name, count):
    act = open_act(data_files[name])
    assert len(act.triggers) == count
示例#10
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_layer_has_correct_angle(data_files):
    act = open_act(data_files['agav.act'])
    assert act.animations[0].frames[0].layers[0].angle == 0.0
    angle = act.animations[24].frames[3].layers[0].angle
    assert isclose(angle, 2.8026e-45, rel_tol=0.00001)
示例#11
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_has_correct_animation_count(data_files, name, count):
    act = open_act(data_files[name])
    assert len(act.animations) == count
示例#12
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_layer_has_correct_zoom(data_files):
    act = open_act(data_files['cursors.act'])
    assert act.animations[0].frames[0].layers[0].zoom == (1.0, 1.0)
    zoom = act.animations[1].frames[1].layers[0].zoom
    assert isclose(zoom.x, 1.2, abs_tol=0.0001)
    assert isclose(zoom.y, 1.2, abs_tol=0.0001)
示例#13
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_layer_has_correct_color(data_files, name, color):
    act = open_act(data_files[name])
    assert act.animations[0].frames[0].layers[0].color == color
示例#14
0
文件: test_act.py 项目: bmeinka/pygrf
def test_act_has_correct_version(data_files, name, version):
    act = open_act(data_files[name])
    assert act.version == version
示例#15
0
 def test_read_act_file(self):
     act = pygrf.open_act("bin/frus.act")
     assert len(act.animations) == 40
示例#16
0
    def render_char(self, body_path, head_path, out_file_path):
        body_spr_path = body_path[:body_path.rfind(".")] + ".spr"
        body_act_path = body_path[:body_path.rfind(".")] + ".act"
        head_spr_path = head_path[:head_path.rfind(".")] + ".spr"
        head_act_path = head_path[:head_path.rfind(".")] + ".act"

        if not os.path.isfile(body_spr_path):
            raise FileNotFoundError(
                "Body sprite file {} is not found".format(body_spr_path))
        if not os.path.isfile(body_spr_path):
            raise FileNotFoundError(
                "Body act file {} is not found".format(body_act_path))
        if not os.path.isfile(head_spr_path):
            raise FileNotFoundError(
                "Head sprite file {} is not found".format(head_spr_path))
        if not os.path.isfile(head_act_path):
            raise FileNotFoundError(
                "Head act file {} is not found".format(head_act_path))

        # body_spr = pygrf.open_spr(body_spr_path)
        # body_image = body_spr[0]
        # body_pil_image = body_image.to_pil_image()
        # body_pil_image.putalpha(128)

        # head_spr = pygrf.open_spr(head_spr_path)
        # head_image = head_spr[0]
        # head_pil_image = head_image.to_pil_image()
        # head_pil_image.putalpha(128)

        # head_act = pygrf.open_act(head_act_path)

        # char_image = PIL.Image.new("RGBA", (body_image.width, body_image.height + head_image.height), (0, 0, 0, 0))

        # body_offset_x = 0
        # body_offset_y = 23
        # char_image.paste(body_pil_image, (body_offset_x, body_offset_y))

        # # head_offset_x = int((body_image.width - head_image.width) / 2.0) + head_act.animations[0].frames[0].layers[0].offset.x
        # head_offset_x = int((body_image.width - head_image.width) / 2.0)
        # head_offset_y = 0
        # char_image.paste(head_pil_image, (head_offset_x, head_offset_y))

        # char_image.save("char.bmp")

        body_spr = pygrf.open_spr(body_spr_path)
        body_image = body_spr[0]
        head_spr = pygrf.open_spr(head_spr_path)
        head_image = head_spr[0]
        head_act = pygrf.open_act(head_act_path)

        char_image_width = body_image.width
        char_image_height = head_image.height + body_image.height
        body_offset_x = 0
        body_offset_y = head_image.height - 6
        head_offset_x = int(
            (body_image.width - head_image.width) /
            2.0) - head_act.animations[0].frames[0].layers[0].offset.x
        head_offset_y = 0

        char_pixels = []
        for y in range(0, char_image_height):
            for x in range(0, char_image_width):
                char_pixel_color = pygrf.graphics.Color(0, 0, 0, 0)

                # is_this_head = False
                if x >= head_offset_x and x < head_offset_x + head_image.width and y >= head_offset_y and y < head_offset_y + head_image.height:
                    head_x = x - head_offset_x
                    head_y = y - head_offset_y
                    head_pixel_index = head_y * head_image.width + head_x
                    if head_image.data[
                            head_pixel_index] != 0:  # Hack zero palette
                        char_pixels.append(head_image.pixels[head_pixel_index])
                        continue
                    # head_pixel_color = head_image.pixels[head_pixel_index]
                    # char_pixel_color = char_pixel_color.alpha_blend(head_pixel_color)

                if x >= body_offset_x and x < body_offset_x + body_image.width and y >= body_offset_y and y < body_offset_y + body_image.height:
                    body_x = x
                    body_y = y - body_offset_y
                    body_pixel_index = body_y * body_image.width + body_x
                    # body_pixel_color = body_image.pixels[body_pixel_index]
                    # char_pixel_color = char_pixel_color.alpha_blend(body_pixel_color)
                    if body_image.data[
                            body_pixel_index] != 0:  # Hack zero palette
                        char_pixels.append(body_image.pixels[body_pixel_index])
                        continue

                # char_pixels.append(char_pixel_color)
                char_pixels.append(pygrf.graphics.Color(255, 255, 255, 0))

        char_image = pygrf.graphics.Image(char_image_width, char_image_height,
                                          char_pixels, None, None)
        char_image.to_pil_image().save(out_file_path, )