SNES-like engine in JavaScript.
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.

141 lines
3.7 KiB

  1. #!/usr/bin/env python3
  2. import glob
  3. import json
  4. import os
  5. import random
  6. import sys
  7. from PIL import Image
  8. # The guide in tiles/guide.png is quite helpful.
  9. # TODO: sort the stuff in free/ and noncommercial/
  10. # TODO: in future/100/characters there are some doors, conveyor belts, screens
  11. SPRITE_FILES = [
  12. 'animals/sheets/*.png',
  13. 'beasttribes/100/*.png',
  14. 'characters/sheets/*.png',
  15. 'christmas/1x/gnome*.png',
  16. 'christmas/1x/reindeer*.png',
  17. 'christmas/1x/rudolph*.png',
  18. 'christmas/1x/xmas*.png',
  19. 'dwarvesvselves/regularsize/*.png',
  20. 'future/100/characters/cars.png',
  21. 'future/100/characters/future*.png',
  22. 'future/100/characters/military*.png',
  23. 'future/100/characters/modern*.png',
  24. 'halloween/ghost1.png',
  25. 'halloween/horseman/*1.png',
  26. 'halloween/reaper/*1.png',
  27. 'halloween/witch/1x/*.png',
  28. 'lichcrusades/100/*.png',
  29. 'monsters/1x/*.png',
  30. 'mythicalbosses/100/*.png',
  31. 'mythicalbosses/dinosaurs/*.png',
  32. 'npcanimations/rpgmaker/1/*.png',
  33. 'ship/100/char/airship*.png',
  34. 'ship/100/char/boat*.png',
  35. 'ship/100/char/pirates_100.png',
  36. 'ship/100/char/ship*.png',
  37. ]
  38. SPRITE_SIDEVIEW_FILES = [
  39. 'beasttribes/100/sv_battler/*.png',
  40. 'future/100/svbattler/*.png',
  41. # TODO: these need to get scaled down 2x before they can be used.
  42. 'sv_battle/RMMV/sv_actors/*.png',
  43. ]
  44. TILESET_FILES = [
  45. 'ashlands/ashlands_tileset.png',
  46. 'atlantis/tf_atlantis_tiles.png',
  47. 'beach/beach_tileset.png',
  48. 'christmas/1x/addon_igloo_1.png',
  49. 'christmas/1x/christmas*.png',
  50. 'cloud/cloud_tileset.png',
  51. 'darkdimension/tf_darkdimension_sheet.png',
  52. 'farmandfort/ff_master_tile_sheet.png',
  53. 'future/100/tilesets/*.png',
  54. 'gianttree/tf_gianttree_tiles.png',
  55. 'halloween/tiles/*1.png',
  56. 'jungle/tf_jungle_tileset.png',
  57. 'patron/train_sheet_1.png',
  58. 'ruindungeons/ruindungeons_sheet_full.png',
  59. 'ship/ship_big_tileset.png',
  60. 'tiles/TILESETS/*.png',
  61. 'winter/tiles/*.png',
  62. ]
  63. ANIMATION_FILES = [
  64. 'patron/fireworks*_1.png',
  65. 'pixelanimations/animationsheets/*.png',
  66. 'ship/100/char/!$ship_wave*.png',
  67. 'sv_battle/RMMV/system/States.png',
  68. 'tiles/TILESETS/animated/*.png',
  69. ]
  70. ICON_FILES = [
  71. 'farmandfort/IconSet/tf_icon_16.png',
  72. 'halloween/hallowicons_1.png',
  73. ]
  74. BACKGROUND_FILES = [
  75. 'cloud/bg_*.png',
  76. 'future/100/other/spacebg.png',
  77. 'ship/100/parallax/*.png'
  78. ]
  79. def unglob(list_of_globs):
  80. result = []
  81. for file in list_of_globs:
  82. globbed_files = glob.glob(file)
  83. assert len(globbed_files) > 0, 'glob for %s should be non-empty' % file
  84. result.extend(globbed_files)
  85. result.sort()
  86. return result
  87. def input_wh(prompt):
  88. while True:
  89. geometry = input(prompt)
  90. try:
  91. cols, rows = [int(x) for x in geometry.split(' ')]
  92. return cols, rows
  93. except:
  94. pass
  95. def main():
  96. os.chdir(os.path.expanduser('~/time_fantasy'))
  97. metadata = json.load(open('metadata.json'))
  98. sprite_files = unglob(SPRITE_FILES)
  99. tileset_files = unglob(TILESET_FILES)
  100. animation_files = unglob(ANIMATION_FILES)
  101. icon_files = unglob(ICON_FILES)
  102. background_files = unglob(BACKGROUND_FILES)
  103. print('sprites: %d tilesets: %d animations: %d icons: %d backgrounds: %d' %
  104. (len(sprite_files), len(tileset_files), len(animation_files),
  105. len(icon_files), len(background_files)))
  106. for filename in sprite_files:
  107. with Image.open(filename) as image:
  108. x = image.show()
  109. cols, rows = input_wh('%s (%dx%d): ' % (
  110. filename, image.size[0], image.size[1]))
  111. width = image.size[0] / cols
  112. height = image.size[1] / rows
  113. print(width, height)
  114. if rows == 1 and cols == 1:
  115. continue
  116. for i in range(rows):
  117. for j in range(cols):
  118. box = (j * width, i * height, (j + 1) * width, (i + 1) * height)
  119. sprites = image.crop(box)
  120. sprites.show()
  121. if __name__ == '__main__':
  122. main()