예제 #1
0
    def read_from_project(self, resource_open):
        with resource_open("sprite_group_palettes", "yml") as f:
            self.palette_table.from_yml_file(f)

        with resource_open("sprite_groups", "yml") as f:
            input = yml_load(f)
            num_groups = len(input)
            self.groups = []
            for i in range(num_groups):
                group = SpriteGroup(16)
                group.from_yml_rep(input[i])

                palette = EbPalette(1, 16)

                with resource_open("SpriteGroups/" + str(i).zfill(3),
                                   "png") as f2:
                    image = open_indexed_image(f2)
                    group.from_image(image)
                    palette.from_image(image)
                    del image

                self.groups.append(group)

                # Assign the palette number to the sprite
                for j in range(8):
                    if palette.list()[3:] == self.palette_table[j][0].list(
                    )[3:]:
                        group.palette = j
                        break
                else:
                    raise CoilSnakeError("Sprite Group #" + str(i).zfill(3) +
                                         " uses an invalid palette")
예제 #2
0
    def test_calculate_unique_sprites_2(self):
        sg = SpriteGroup(16)
        sg.from_image(self.spritegroup_2_img)

        unique_sprites, unique_sprite_usages = sg.calculate_unique_sprites()

        hashes = dict()

        # Two unused sprites which are identical
        sprite_4_hash, sprite_4_flip = unique_sprite_usages[4]
        assert_equal(unique_sprite_usages[5], (sprite_4_hash, sprite_4_flip))
        hashes[sprite_4_hash] = True

        # One used sprite and one unused sprite
        assert_equal(unique_sprite_usages[0], (sprite_4_hash, sprite_4_flip))
        sprite_1_hash, sprite_1_flip = unique_sprite_usages[1]
        assert_not_equal(sprite_4_hash, sprite_1_hash)
        hashes[sprite_1_hash] = True

        # One used-as-flipped sprite and one unused sprite
        assert_equal(unique_sprite_usages[6],
                     (sprite_4_hash, not sprite_4_flip))
        sprite_7_hash, sprite_7_flip = unique_sprite_usages[7]
        assert_not_in(sprite_7_hash, hashes)
        assert_equal(not sprite_4_flip, sprite_7_flip)
        hashes[sprite_7_hash] = True

        # One unused sprite and one used sprite
        sprite_2_hash, sprite_2_flip = unique_sprite_usages[2]
        assert_not_in(sprite_2_hash, hashes)
        assert_equal(unique_sprite_usages[3], unique_sprite_usages[4])
        hashes[sprite_2_hash] = True

        # One unused sprite and one used-as-flipped sprite
        sprite_14_hash, sprite_14_flip = unique_sprite_usages[14]
        assert_not_in(sprite_14_hash, hashes)
        assert_equal(unique_sprite_usages[15],
                     (sprite_4_hash, not sprite_4_flip))
        hashes[sprite_14_hash] = True

        # Two unused sprites
        sprite_12_hash, sprite_12_flip = unique_sprite_usages[12]
        assert_not_in(sprite_12_hash, hashes)
        sprite_13_hash, sprite_13_flip = unique_sprite_usages[13]
        assert_not_equal(sprite_12_hash, sprite_13_hash)
        assert_not_in(sprite_13_hash, hashes)
        assert_equal(sprite_12_flip, sprite_13_flip)
        hashes[sprite_12_hash] = True
        hashes[sprite_13_hash] = True

        # One unused sprite
        sprite_10_hash, sprite_10_flip = unique_sprite_usages[10]
        assert_not_in(sprite_10_hash, hashes)
예제 #3
0
    def test_calculate_unique_sprites_1(self):
        sg = SpriteGroup(16)
        sg.from_image(self.spritegroup_1_img)

        unique_sprites, unique_sprite_usages = sg.calculate_unique_sprites()

        # Two unused sprites which are identical
        sprite_4_hash, sprite_4_flip = unique_sprite_usages[4]
        assert_false(sprite_4_flip)
        assert_equal(unique_sprite_usages[5], (sprite_4_hash, sprite_4_flip))

        # Two used sprites which are identical
        assert_equal(unique_sprite_usages[0], (sprite_4_hash, sprite_4_flip))
        assert_equal(unique_sprite_usages[1], (sprite_4_hash, sprite_4_flip))

        # Two used-as-flipped sprites which are identical
        assert_equal(unique_sprite_usages[6],
                     (sprite_4_hash, not sprite_4_flip))
        assert_equal(unique_sprite_usages[7],
                     (sprite_4_hash, not sprite_4_flip))

        # Two mirrored sprites, the first of which is used
        assert_equal(unique_sprite_usages[2], (sprite_4_hash, sprite_4_flip))
        assert_equal(unique_sprite_usages[3],
                     (sprite_4_hash, not sprite_4_flip))

        # Two mirrored sprites, the second of which is used
        assert_equal(unique_sprite_usages[14],
                     (sprite_4_hash, not sprite_4_flip))
        assert_equal(unique_sprite_usages[15], (sprite_4_hash, sprite_4_flip))

        # Two mirrored sprites, neither of which are used
        sprite_12_hash, sprite_12_flip = unique_sprite_usages[12]
        assert_not_equal(sprite_4_hash, sprite_12_hash)
        assert_equal(unique_sprite_usages[13],
                     (sprite_12_hash, not sprite_12_flip))

        # Two sprites, both of which are used
        assert_equal(unique_sprite_usages[10], (sprite_4_hash, sprite_4_flip))
        assert_equal(unique_sprite_usages[11],
                     (sprite_12_hash, sprite_12_flip))
        assert_equal(unique_sprite_usages[10][1], unique_sprite_usages[11][1])

        # Two flipped sprites, both of which are used
        assert_equal(unique_sprite_usages[8],
                     (sprite_4_hash, not sprite_4_flip))
        assert_equal(unique_sprite_usages[9],
                     (sprite_12_hash, not sprite_12_flip))
        assert_equal(unique_sprite_usages[8][1], unique_sprite_usages[9][1])
예제 #4
0
    def read_from_rom(self, rom):
        self.group_pointer_table.from_block(
            rom, from_snes_address(GROUP_POINTER_TABLE_OFFSET))
        self.palette_table.from_block(rom,
                                      from_snes_address(PALETTE_TABLE_OFFSET))

        # Load the sprite groups
        self.groups = []
        for i in range(self.group_pointer_table.num_rows):
            # Note: this assumes that the SPT is written contiguously
            num_sprites = 8
            # Assume that the last group only has 8 sprites
            if i < self.group_pointer_table.num_rows - 1:
                num_sprites = (self.group_pointer_table[i + 1][0] -
                               self.group_pointer_table[i][0] - 9) / 2

            group = SpriteGroup(num_sprites)
            group.from_block(rom,
                             from_snes_address(self.group_pointer_table[i][0]))
            self.groups.append(group)
예제 #5
0
 def test_from_image(self):
     sg = SpriteGroup(16)
     sg.from_image(self.spritegroup_1_img)