Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import glob
- from PIL import Image, ImageFont, ImageDraw, ImageEnhance
- map_dimensions = {}
- for line in open('pokered/constants/map_constants.asm'):
- if 'map_const ' in line:
- _, enum, x, y, _ = line.strip().split(None,4)
- map_dimensions[enum[:-1]] = (int(x[:-1]),int(y))
- tileset_map = {
- 'OVERWORLD': ('overworld', {0x00, 0x10, 0x1b, 0x20, 0x21, 0x23, 0x2c, 0x2d, 0x2e, 0x30, 0x31, 0x33, 0x39, 0x3c, 0x3e, 0x52, 0x54, 0x58, 0x5b}, {}),
- 'REDS_HOUSE_1': ('reds_house', {0x01, 0x02, 0x03, 0x11, 0x12, 0x13, 0x14, 0x1c, 0x1a}, {}),
- 'MART': ('pokecenter', {0x11, 0x1a, 0x1c, 0x3c, 0x5e}, {}),
- 'FOREST': ('forest', {0x1e, 0x20, 0x2e, 0x30, 0x34, 0x37, 0x39, 0x3a, 0x40, 0x51, 0x52, 0x5a, 0x5c, 0x5e, 0x5f}, {(0x30, 0x2E), (0x52, 0x2E), (0x55, 0x2E), (0x56, 0x2E), (0x20, 0x2E), (0x5E, 0x2E), (0x5F, 0x2E), (0x14, 0x2E), (0x48, 0x2E)}),
- #'FOREST': ('forest', {0x1e, 0x20, 0x2e, 0x30, 0x34, 0x37, 0x39, 0x3a, 0x40, 0x51, 0x52, 0x5a, 0x5c, 0x5e, 0x5f}, {(0x30, 0x2E), (0x52, 0x2E), (0x55, 0x2E), (0x56, 0x2E), (0x20, 0x2E), (0x5E, 0x2E), (0x5F, 0x2E)}),
- 'REDS_HOUSE_2': ('reds_house', {0x01, 0x02, 0x03, 0x11, 0x12, 0x13, 0x14, 0x1c, 0x1a}, {}),
- 'DOJO': ('gym', {0x11, 0x16, 0x19, 0x2b, 0x3c, 0x3d, 0x3f, 0x4a, 0x4c, 0x4d, 0x03}, {}),
- 'POKECENTER': ('pokecenter', {0x11, 0x1a, 0x1c, 0x3c, 0x5e}, {}),
- 'GYM': ('gym', {0x11, 0x16, 0x19, 0x2b, 0x3c, 0x3d, 0x3f, 0x4a, 0x4c, 0x4d, 0x03}, {}),
- 'HOUSE': ('house', {0x01, 0x12, 0x14, 0x28, 0x32, 0x37, 0x44, 0x54, 0x5c}, {}),
- 'FOREST_GATE': ('gate', {0x01, 0x12, 0x14, 0x1a, 0x1c, 0x37, 0x38, 0x3b, 0x3c, 0x5e}, {}),
- 'MUSEUM': ('gate', {0x01, 0x12, 0x14, 0x1a, 0x1c, 0x37, 0x38, 0x3b, 0x3c, 0x5e}, {}),
- 'UNDERGROUND': ('underground', {0x0b, 0x0c, 0x13, 0x15, 0x18}, {}),
- 'GATE': ('gate', {0x01, 0x12, 0x14, 0x1a, 0x1c, 0x37, 0x38, 0x3b, 0x3c, 0x5e}, {}),
- 'SHIP': ('ship', {0x04, 0x0d, 0x17, 0x1d, 0x1e, 0x23, 0x34, 0x37, 0x39, 0x4a}, {}),
- 'SHIP_PORT': ('ship_port', {0x0a, 0x1a, 0x32, 0x3b}, {}),
- 'CEMETERY': ('cemetery', {0x01, 0x10, 0x13, 0x1b, 0x22, 0x42, 0x52}, {}),
- 'INTERIOR': ('interior', {0x04, 0x0f, 0x15, 0x1f, 0x3b, 0x45, 0x47, 0x55, 0x56}, {}),
- 'CAVERN': ('cavern', {0x05, 0x15, 0x18, 0x1a, 0x20, 0x21, 0x22, 0x2a, 0x2d, 0x30}, {(0x20, 0x05), (0x41, 0x05), (0x2A, 0x05), (0x05, 0x21), (0x14, 0x05)}),
- #'CAVERN': ('cavern', {0x05, 0x15, 0x18, 0x1a, 0x20, 0x21, 0x22, 0x2a, 0x2d, 0x30}, {(0x20, 0x05), (0x41, 0x05), (0x2A, 0x05), (0x05, 0x21)}),
- 'LOBBY': ('lobby', {0x14, 0x17, 0x1a, 0x1c, 0x20, 0x38, 0x45}, {}),
- 'MANSION': ('mansion', {0x01, 0x05, 0x11, 0x12, 0x14, 0x1a, 0x1c, 0x2c, 0x53}, {}),
- 'LAB': ('lab', {0x0c, 0x26, 0x16, 0x1e, 0x34, 0x37}, {}),
- 'CLUB': ('club', {0x0f, 0x1a, 0x1f, 0x26, 0x28, 0x29, 0x2c, 0x2d, 0x2e, 0x2f, 0x41}, {}),
- 'FACILITY': ('facility', {0x01, 0x10, 0x11, 0x13, 0x1b, 0x20, 0x21, 0x22, 0x30, 0x31, 0x32, 0x42, 0x43, 0x48, 0x52, 0x55, 0x58, 0x5e}, {}),
- 'PLATEAU': ('plateau', {0x1b, 0x23, 0x2c, 0x2d, 0x3b, 0x45}, {}),
- }
- for fname in glob.glob("pokered/data/maps/headers/*"):
- name, enum, tileset, _ = next(open(fname)).strip()[11:].split(', ')
- print(name)
- width, height = map_dimensions[enum]
- if name == 'UndergroundPathRoute7Copy':
- name2 = 'UndergroundPathRoute7'
- #elif name.startswith('CeruleanCave'):
- # name2 = 'green/'+name
- else:
- name2 = name
- blocks = open(f'pokered/maps/{name2}.blk','rb').read()
- tileset2, coll_tiles, coll_pairs = tileset_map[tileset]
- tileset_gfx = Image.open(f'pokered/gfx/tilesets/{tileset2}.png')
- tiles = open(f'pokered/gfx/blocksets/{tileset2}.bst','rb').read()
- graphics = []
- for y in range(0,tileset_gfx.height,8):
- for x in range(0,tileset_gfx.width,8):
- graphics.append(tileset_gfx.crop((x,y,x+8,y+8)))
- im = Image.new(mode='RGB',size=(width*32,height*32))
- draw = ImageDraw.Draw(im, 'RGBA')
- subtiles = []
- for y in range(height*4):
- subtiles.append([None] * (width*4))
- for y in range(len(blocks)//width):
- for x in range(width):
- block = blocks[y*width+x]
- tile = tiles[block*0x10:(block+1)*0x10]
- for i in range(0x10):
- y_coord = y*4 + (i // 4)
- x_coord = x*4 + (i % 4)
- subtiles[y_coord][x_coord] = tile[i]
- for y in range(len(subtiles)):
- for x,subtile in enumerate(subtiles[y]):
- if subtile is not None:
- im.paste(graphics[subtile], (x*8, y*8))
- for y in range(len(subtiles)):
- for x,subtile in enumerate(subtiles[y]):
- if y%2==1 and x%2==0:
- if subtile not in coll_tiles:
- if subtile in {0x14,0x32,0x48} and tileset in {'OVERWORLD','FOREST','DOJO','GYM','SHIP','CAVERN','FACILITY','PLATEAU'}:
- draw.rectangle((x*8, y*8-8, x*8+16, y*8+8), fill=(0,0,255,128))
- elif subtile == 0x14 and tileset == 'SHIP_PORT':
- draw.rectangle((x*8, y*8-8, x*8+16, y*8+8), fill=(0,0,255,128))
- else:
- draw.rectangle((x*8, y*8-8, x*8+16, y*8+8), fill=(255,0,0,128))
- if (y-2) >= 0 and (subtile, subtiles[y-2][x]) in coll_pairs:
- draw.rectangle((x*8, y*8-12, x*8+16, y*8-4), fill=(255,0,0,128))
- if (x-2) >= 0 and (subtile, subtiles[y][x-2]) in coll_pairs:
- draw.rectangle((x*8-4, y*8-8, x*8+4, y*8+8), fill=(255,0,0,128))
- if (y+2) < len(subtiles) and (subtile, subtiles[y+2][x]) in coll_pairs:
- draw.rectangle((x*8, y*8+4, x*8+16, y*8+12), fill=(255,0,0,128))
- if (x+2) < len(subtiles[y]) and (subtile, subtiles[y][x+2]) in coll_pairs:
- draw.rectangle((x*8+12, y*8-8, x*8+20, y*8+8), fill=(255,0,0,128))
- im.save(f'output/{name2}.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement