import json
    
class SpriteManager:
    def __init__(self, path, surface, texture, cell_size):
        self.spritesheet_texture = texture
        self.spritesheet_surface = surface
        self.cell_size = cell_size
        self.frames_rect = []
        self.load_spritemap(path)
        
    def load_spritemap(self, json_path):
        with open(json_path) as f:
            for frame in json.load(f).get("frames"):
                x = frame["frame"]["x"]
                y = frame["frame"]["y"]
                w = frame["frame"]["w"]
                h = frame["frame"]["h"]

                # Calcola le coordinate per un quadrato centrato
                quad_x = x + (w - self.cell_size) // 2
                quad_y = y + (h - self.cell_size) // 2

                # Aggiungi il rettangolo del quadrato al centro
                self.frames_rect.append((quad_x, quad_y, self.cell_size, self.cell_size))
    
    def get_frame_rect(self, frame):
        return self.frames_rect[frame % len(self.frames_rect)], len(self.frames_rect)