#!/usr/bin/python3 import pygame from dataclasses import dataclass from wobbl_tools import pg from wobbl_tools import data_file class Object: def __init__(self, sprite_path: str="sprites/coffee_cup.png", sprite_spacing: int=1, rotation: int=45, size_multiplier: int=16): self.sprite_path = sprite_path self.sprite_spacing = sprite_spacing self.rotation = rotation self.size_multiplier = size_multiplier self.sprite_size = tuple(get_json(get_dir(sprite_path) + "/sprite_properties.json")[get_filename(sprite_path)]["size"]) self.original_sprites = self.get_sprites() self.sprites = self.rotate_sprites() self.surface = self.generate_surface() print(self.sprite_size) def get_sprites(self): model = pygame.image.load(self.sprite_path) sw, sh = self.sprite_size mw, mh = model.get_size() sprites = [] for x in range(0, mw, sw): sprite = pg.crop_surface(model, (x, 0), (sw, sh)) sprites.append(sprite) return sprites def rotate_sprites(self): sprites = [] for sprite in self.original_sprites: sprite = pygame.transform.rotate(sprite, self.rotation) sprites.append(sprite) return sprites def generate_surface(self): sw, sh = self.sprites[0].get_size() surface = pygame.Surface((sw, sh + self.sprite_spacing * len(self.sprites)), flags=pygame.SRCALPHA) y = surface.get_height() - sh for sprite in self.sprites: surface.blit(sprite, (0, y)) y -= self.sprite_spacing surface = pygame.transform.scale(surface, (surface.get_width() * self.size_multiplier, surface.get_height() * self.size_multiplier)) return surface def get_dir(path: str): return path.rsplit("/", 1)[0] def get_filename(path: str): return path.rsplit("/", 1)[1] def get_json(path: str): file = open(path, "r") data = eval(file.read()) file.close() return data if __name__ == "__main__": bla = Object()