slice-level-redesign-assets.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from pathlib import Path
  2. from PIL import Image
  3. ROOT = Path(__file__).resolve().parents[1]
  4. SRC = ROOT / "assets" / "resources" / "sprites" / "imagegen" / "level_redesign"
  5. OUT = SRC / "ui"
  6. def alpha_crop(tile, padding=8):
  7. bbox = tile.getchannel("A").getbbox()
  8. if not bbox:
  9. return tile
  10. left, top, right, bottom = bbox
  11. return tile.crop((
  12. max(0, left - padding),
  13. max(0, top - padding),
  14. min(tile.width, right + padding),
  15. min(tile.height, bottom + padding),
  16. ))
  17. image = Image.open(SRC / "hp_hud.png").convert("RGBA")
  18. OUT.mkdir(parents=True, exist_ok=True)
  19. names = [
  20. "hp_bar_frame",
  21. "hp_segments",
  22. "hp_empty_segment",
  23. "hp_numeric_plaque",
  24. "damage_badge",
  25. "shield_icon",
  26. "low_health_marker",
  27. "hp_panel_alt",
  28. ]
  29. cols = 4
  30. rows = 2
  31. tile_w = image.width / cols
  32. tile_h = image.height / rows
  33. for index, name in enumerate(names):
  34. col = index % cols
  35. row = index // cols
  36. left = round(col * tile_w)
  37. top = round(row * tile_h)
  38. right = round((col + 1) * tile_w)
  39. bottom = round((row + 1) * tile_h)
  40. tile = image.crop((left, top, right, bottom))
  41. alpha_crop(tile).save(OUT / f"{name}.png")
  42. for path in sorted(OUT.glob("*.png")):
  43. with Image.open(path) as item:
  44. print(f"{path.name}: {item.width}x{item.height}")