from common import dataclass, scale_image

@dataclass
class Object:    
    id: str
    name: str 
    sprite_name: str
    sprite_state: int = 0
    sprite_scale: int = 1
    sprite_cache: None = None

    def draw(self, draw_data):
        if draw_data["spr_up"] == 0:
            if self.sprite_state == len(draw_data["sprites"][self.sprite_name]) - 1:
                self.sprite_state = 0
            else:
                self.sprite_state += 1  

        if self.sprite_cache is None:
            self.sprite_cache = draw_data["sprites"][self.sprite_name][self.sprite_state]
            
        if self.sprite_scale != draw_data["scale"]:            
            self.sprite_scale = draw_data["scale"]
            self.sprite_cache = scale_image(draw_data["sprites"][self.sprite_name][self.sprite_state], draw_data["scale"])
            rect = self.sprite_cache.get_rect(center = (draw_data["x"] + draw_data["w"] /2, draw_data["y"] + draw_data["h"]/ 2))
        else:
            rect = self.sprite_cache.get_rect(center = (draw_data["x"] + draw_data["w"] /2, draw_data["y"] + draw_data["h"]/ 2))

        draw_data["screen"].blit(self.sprite_cache, rect)

    
@dataclass
class Terrain(Object):
    pass

@dataclass
class Creature(Object):
    pass
    #status
    #actions
    #tasks
    #items

@dataclass
class Item(Object):
    pass

@dataclass
class Building(Object):
    pass