Post tutorial RSS Automaps parsing

Simple way to stitch automaps from parts. Result is big BMP image.

Posted by on - Basic UI/HUD

This code originally was posted by user Vinylon on AccusedFarms (http://accursedfarms.com/forums/viewtopic.php?f=63&t=8128)

His link:

Pastebin.com

His code:

import Image
import os.path

fpx = 64
# max +/- Y coordinate
fy = 40
# max +/- X coordinate
fx = 90
# ~max number of maps.
mn = 60
hasmaps = False

for n in range(0, mn):
hasmaps = False
new_im = Image.new('RGB', (fpx*fx*2, fpx*fy*2))
for y in range(-fy, fy):
for x in range(-fx, fx):
# Look for files one directory up.
fname = "../%d_%d_%d.bmp"%(n, x, y)
if os.path.isfile(fname):
hasmaps = True
im = Image.open(fname)
new_im.paste(im, ((x+fx)*fpx, (y+fy)*fpx))
if hasmaps:
new_im.save("map_%d.bmp"%n, 'BMP')

Comments
Nicord Author
Nicord - - 9 comments

And my fancy version:
# Original code was written by Vinylon
# Accursedfarms.com
# some illustrating tweaks by Nicord
# Moddb.com
from PIL import Image
import os.path

def count_this(given_list, prefix):
number = 0
for point in given_list:
if point[0:3] == (str(prefix) + '_') or point[0:2] == (str(prefix) + '_'):
number += 1

if 0 <= number < 10:
return '00' + str(number)
elif 10 <= number < 100:
return '0' + str(number)
else:
return str(number)

directory = 'automaps6/'

print('----------------------------------------------------------------------------')
print('1. Starting to analyze "%s" directory' % directory)
files = os.listdir(directory)

names = []
for file in files:
pos = file.find('_')
if pos != -1:
names.append(int(file[0:pos]))
result = list(set(names))
result.sort()

counts = []
for current in result:
counts.append(count_this(files, current))

print('Total {} tiles found for {} maps'.format(len(files), len(result)))
print('----------------------------------------------------------------------------')
print('2. Starting to stitch tiles')

fpx = 64
# max +/- Y coordinate
fy = 40
# max +/- X coordinate
fx = 90

hasmaps = False

for n in range(0, len(result)):
hasmaps = False
new_im = Image.new('RGB', (fpx * fx * 2, fpx * fy * 2))

if result[n] < 10:
inp = '0'
else:
inp = ''

print('Processing map [{}{}], it has {} tiles, saved as "revenant_map_{}{}.bmp'.format(inp, result[n], counts[n], inp, result[n]))

for y in range(-fy, fy):
for x in range(-fx, fx):
fname = directory + "%d_%d_%d.bmp" % (result[n], x, y)

if os.path.isfile(fname):
hasmaps = True
im = Image.open(fname)
new_im.paste(im, ((x + fx) * fpx, (y + fy) * fpx))

if hasmaps:
new_im.save("revenant_map_%s%d.bmp" % (inp, result[n]), 'BMP')
result[n] = 0

print('----------------------------------------------------------------------------')
if sum(result) == 0:
print('Stitching successfully completed')
else:
print('Something has gone wrong, re check your settings')

Reply Good karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.