A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

  1. #!/usr/bin/env python3
  2. import glob
  3. import os
  4. import pprint # pylint: disable=unused-import
  5. import sys
  6. from PIL import Image
  7. TRANSPARENT_RGBA = (255, 255, 255, 0)
  8. def main(args):
  9. if len(args) < 2:
  10. print('usage: python3 import_ccg.py CCG_ROOT Sprite_Name\n')
  11. print('Add an additional OUTPUT_ROOT argument to actually write output.')
  12. print('(Otherwise, this script just will perform a dry run.)')
  13. return
  14. ccg_root, sprite_name = args[:2]
  15. os.chdir(ccg_root)
  16. output_root = None
  17. if len(args) > 2:
  18. output_root = os.path.join(os.path.expanduser(args[2]), sprite_name)
  19. os.makedirs(output_root, exist_ok=True)
  20. sprite_files = sorted(glob.glob(sprite_name + '/*.png'))
  21. print('sprites: %d' % (len(sprite_files)))
  22. if not sprite_files:
  23. print('no sprite files found!')
  24. return
  25. # Collect sizes.
  26. max_width = 0
  27. max_height = 0
  28. for sprite in sprite_files:
  29. with Image.open(sprite) as image:
  30. max_width = max(max_width, image.width)
  31. max_height = max(max_height, image.height)
  32. new_size = (max_width, max_height)
  33. print('new size: %dx%d' % new_size)
  34. # Now frob them.
  35. for i, sprite in enumerate(sprite_files):
  36. with Image.open(sprite) as image:
  37. top_pad = max_height - image.height
  38. left_pad = (max_width - image.width) // 2
  39. right_pad = max_width - image.width - left_pad
  40. out_filename = '%s_%03d.png' % (sprite_name, i)
  41. print('%03d: %3dx%-3d top: %2d left: %2d right: %2d %s -> %s' % (
  42. i, image.width, image.height, top_pad, left_pad, right_pad, sprite,
  43. out_filename))
  44. if output_root:
  45. new_image = Image.new('RGBA', new_size, TRANSPARENT_RGBA)
  46. new_image.paste(image, (left_pad, top_pad))
  47. new_image.save(os.path.join(output_root, out_filename))
  48. if __name__ == '__main__':
  49. main(sys.argv[1:])