Last active
October 31, 2022 03:52
-
-
Save xAiluros/af24798a86a2dcd668bd8f7fd0b4390d to your computer and use it in GitHub Desktop.
rpgmaker autotiles to Tiled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Script to convert autotile from rpgmaker form to Tiled. | |
# Based on post: https://forums.rpgmakerweb.com/index.php?threads/auto-tiles-in-tiled-parallax-mapping-made-easier.97739/ | |
# | |
from PIL import Image | |
import sys | |
TILE_SIZE=16 | |
REGION_WIDTH = TILE_SIZE * 4 | |
REGION_HEIGHT = TILE_SIZE * 6 | |
if len(sys.argv) < 3: | |
print("You must provide source and destination file name!") | |
print("Usage: %s input_file output_file" % sys.argv[0]) | |
exit(1) | |
def convert(source): | |
num_x = source.width / REGION_WIDTH | |
num_y = source.height / REGION_HEIGHT | |
if num_x % 1 != 0 or num_y %1 !=0: | |
print("Error, cannot divide in regions!") | |
exit(1) | |
dst = Image.new('RGBA', (int(num_x * TILE_SIZE * 8), int(num_y * TILE_SIZE * 4))) | |
row = 0 | |
while row < num_y: | |
print("Processing row: %i" % row) | |
column = 0 | |
while column < num_x: | |
print("Processing column: %i" % column) | |
offset_x = column * REGION_WIDTH | |
offset_y = row * REGION_HEIGHT | |
region_large = source.crop((0+offset_x, 2*TILE_SIZE+offset_y, 4*TILE_SIZE+offset_x, 6*TILE_SIZE+offset_y)) | |
region_green = source.crop((2*TILE_SIZE+offset_x, 0+offset_y, 3*TILE_SIZE+offset_x, 1*TILE_SIZE+offset_y)) | |
region_yellow = source.crop((3*TILE_SIZE+offset_x, 0+offset_y, 4*TILE_SIZE+offset_x, 1*TILE_SIZE+offset_y)) | |
region_purple = source.crop((2*TILE_SIZE+offset_x, 1*TILE_SIZE+offset_y, 3*TILE_SIZE+offset_x, 2*TILE_SIZE+offset_y)) | |
region_pink = source.crop((3*TILE_SIZE+offset_x, 1*TILE_SIZE+offset_y, 4*TILE_SIZE+offset_x, 2*TILE_SIZE+offset_y)) | |
region_brown = source.crop((1*TILE_SIZE+offset_x, 2*TILE_SIZE+offset_y, 3*TILE_SIZE+offset_x, 3*TILE_SIZE+offset_y)) | |
region_orange = source.crop((0+offset_x, 3*TILE_SIZE+offset_y, 1*TILE_SIZE+offset_x, 5*TILE_SIZE+offset_y)) | |
region_teal = source.crop((3*TILE_SIZE+offset_x, 3*TILE_SIZE+offset_y, 4*TILE_SIZE+offset_x, 5*TILE_SIZE+offset_y)) | |
region_drk_green = source.crop((1*TILE_SIZE+offset_x, 5*TILE_SIZE+offset_y, 3*TILE_SIZE+offset_x, 6*TILE_SIZE+offset_y)) | |
offset_x = column*TILE_SIZE*8 | |
offset_y = row*TILE_SIZE*4 | |
dst.paste(region_large, (4*TILE_SIZE+offset_x, 0+offset_y)) | |
dst.paste(region_green, (3*TILE_SIZE+offset_x, 3*TILE_SIZE+offset_y)) | |
dst.paste(region_yellow, (0+offset_x, 3*TILE_SIZE+offset_y)) | |
dst.paste(region_purple, (3*TILE_SIZE+offset_x, 0+offset_y)) | |
dst.paste(region_pink, (0+offset_x, 0+offset_y)) | |
dst.paste(region_brown, (1*TILE_SIZE+offset_x, 3*TILE_SIZE+offset_y)) | |
dst.paste(region_orange, (3*TILE_SIZE+offset_x, 1*TILE_SIZE+offset_y)) | |
dst.paste(region_teal, (0+offset_x, 1*TILE_SIZE+offset_y)) | |
dst.paste(region_drk_green, (1*TILE_SIZE+offset_x, 0+offset_y)) | |
column += 1 | |
row += 1 | |
return dst | |
try: | |
source = Image.open(sys.argv[1]) | |
dst = convert(source) | |
dst.save(sys.argv[2]) | |
except IOError: | |
print("File not accessible") | |
exit(1) | |
finally: | |
source.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment