from global_stuff import base, colors


class Entity:
    def __init__(self, tile, color):
        self.model = base.loader.load_model('model/'+self.model_name)
        self._color = ''
        self.color = color
        self.tile = tile
        self.model.reparent_to(self.tile.model)

    @property
    def color(self):
        return self._color

    @color.setter
    def color(self, val: str):
        self._color = val
        if self.model:
            for m in self.model.findAllMatches("=color"):
                m.set_color_scale(colors[val])

    def __del__(self):
        if self.model:
            self.model.remove_node()
            self.model = None