fieryhenry / tbcml

A python library designed to make modding The Battle Cats easier, more automated, and more powerful
GNU General Public License v3.0
13 stars 3 forks source link

ValueError: bad transparency mask #9

Closed enderelijas closed 9 months ago

enderelijas commented 11 months ago

Calling the format_deploy_icon() method as shown below, throws a ValueError: bad transparency mask.

Code causing error

enemy = Enemies.from_game_data(self.game_data).get_enemy(8)
enemy_model = enemy.get_anim().model
enemy_icon = enemy.get_enemy_icon()

cat_model = CatModel.create_empty(self.id, CatFormType.FIRST)
cat_model.model = enemy_model.copy()
cat_model.model.flip_x()
cat_model.model.set_unit_form(cat_model.form.value)
cat_model.set_cat_id(self.id)

form = CatForm(self.id, CatFormType.FIRST, anim=cat_model)
form.import_enemy(enemy)

form.stats.cost = 0
form.deploy_icon = enemy_icon
form.format_deploy_icon()

Method error chain

# cats.py line 835
def format_deploy_icon(self):
        deploy_icon = self.get_deploy_icon()
        if deploy_icon.width == 128 and deploy_icon.height == 128:
            return
        base_image = core.BCImage.from_size(128, 128)
        base_image.paste(deploy_icon, 9, 21)
        self.deploy_icon = base_image
# bc_image.py line 130
def paste(self, image: "BCImage", x: int, y: int):
        self.image.paste(image.image, (x, y), image.image)
fieryhenry commented 11 months ago

format_deploy_icon is normally from a bcu icon iirc. This is now fixed, but i've added another function

form.import_enemy_deploy_icon(enemy, offset)

where offset is a tuple of (x_offset, y_offset) when pasting the enemy icon. It defaults to (-20, -20) which works for your image pretty well. form.import_enemy(enemy, deploy_icon_offset) does this as well now and you can again pass in an offset. So you don't need to call form.import_enemy_deploy_icon(enemy, offset) yourself