コード例 #1
0
def procObj(obj):
    objname = obj.ask("name")
    print "processing", objname

    if obj.ask("type", "none").lower() in [
            "res", "com", "ind", "cur"
    ]:  # needs default string because of lower()
        dims = obj.ask("dims", "1,1,1")
        dims = dims.split(",")
        if len(dims) == 2:
            dims.append("1")
        # dims converted to canonical form [?, ?, ?] of strings

        rots = int(dims[2])
        has_winter = False
        max_height = 0
        max_anim = 0

        images = obj.ask_indexed("backimage")

        # preparsing pass - find what are the features of object: seasons, animation...
        for item in images:  # tuples [params] = value -> (params, value)
            indices = item[0].split("][")
            # first and last item still have the single bracket!
            if len(indices) > 0:
                indices[0] = indices[0][1:]
                indices[-1] = indices[-1][:-1]
                # so fix them ^
                if len(indices) == 6:
                    has_winter = indices[5] == "1" or has_winter
                max_anim = max(int(indices[4]), max_anim)
                max_height = max(int(indices[3]), max_height)

        # now we know the numbers so we can select new image layout etc.
        if max_anim > 0:
            # animated?
            # primary animation, secondary rotations, then snow and height
            layout = 0
            new_height = 1 + (max_height + 1) * rots * (
                2 if has_winter else 1)  # first +1 for text row
            new_width = max((max_anim + 1), minwidth)
        elif rots > 1:
            # no anim. -> rotations?
            # primary rotations, secondary snow and height
            layout = 1
            new_height = 1 + (max_height + 1) * (2 if has_winter else 1)
            new_width = max(rots, minwidth)
        else:
            # no anim or rotation?
            # primary climates (if any!), secondary height
            layout = 2
            new_height = 1 + (max_height + 1)
            new_width = max((2 if has_winter else 1), minwidth)

        newimage = pygame.Surface((paksize * new_width, paksize * new_height))
        newimage.fill((231, 255, 255))  # background
        newimage.fill(
            (255, 255, 255),
            (0, 0, new_width * paksize, paksize))  # description stripe

        text = "name: " + obj.ask("name", "?")
        surf = font.render(text, False, (0, 0, 0),
                           (255, 255, 255))  # black text on white
        newimage.blit(surf, (10, 10))

        text = "copyright: " + obj.ask("copyright", "?")
        surf = font.render(text, False, (0, 0, 0),
                           (255, 255, 255))  # black text on white
        newimage.blit(surf, (10, 10 + fntsize + 4))

        cname = simutools.canonicalObjName(objname)

        # blitting pass - copy the parts onto new picture
        for rot in xrange(rots):
            for z in xrange(
                    max_height + 1
            ):  # +1 because we read maximal index, not number of them!
                for t in xrange(max_anim + 1):  # +1 same here
                    indexstr = "backimage[%i][0][0][%i][%i]" % (rot, z, t)
                    value = obj.ask(indexstr)
                    if value == None:
                        # failed but asking is precise, so ask again for explicit number with no winter
                        indexstr = "backimage[%i][0][0][%i][%i][0]" % (rot, z,
                                                                       t)
                        value = obj.ask(indexstr)
                    # now it must be a string! or a mising image
                    if value != None:
                        # the good case
                        imgref = simutools.SimutransImgParam(value)
                        imgname = os.path.join(os.path.dirname(obj.srcfile),
                                               imgref.file + ".png")
                        if not loadedimages.has_key(imgname):
                            loadedimages[imgname] = pygame.image.load(imgname)
                        srccoords = pygame.Rect(imgref.coords[1] * paksize, \
                         imgref.coords[0] * paksize, paksize, paksize) # calculate position on old image
                        if layout == 2:
                            targetcoords = [0, 1 + max_height - z]
                        elif layout == 1:
                            targetcoords = [rot, 1 + max_height - z]
                        else:  # 0
                            targetcoords = [
                                t, 1 + (max_height - z) * (rot + 1) *
                                (2 if has_winter else 1)
                            ]
                        imgref.coords[0] = targetcoords[1]
                        imgref.coords[1] = targetcoords[0]
                        targetcoords[0] *= paksize
                        targetcoords[1] *= paksize
                        newimage.blit(loadedimages[imgname], targetcoords,
                                      srccoords)  # copy image tile
                        imgref.file = cname
                        obj.put(indexstr, str(imgref))
                    else:
                        # say if it is mising!
                        print "Missing image", indexstr
                    if has_winter:
                        indexstr = "backimage[%i][0][0][%i][%i][1]" % (rot, z,
                                                                       t)
                        value = obj.ask(indexstr)
                        if value != None:
                            imgref = simutools.SimutransImgParam(value)
                            imgname = os.path.join(
                                os.path.dirname(obj.srcfile),
                                imgref.file + ".png")
                            if not loadedimages.has_key(imgname):
                                loadedimages[imgname] = pygame.image.load(
                                    imgname)
                            srccoords = pygame.Rect(imgref.coords[1] * paksize, \
                             imgref.coords[0] * paksize, paksize, paksize)
                            if layout == 2:
                                targetcoords = [1, 1 + max_height - z]
                            elif layout == 1:
                                targetcoords = [
                                    rot, 1 + (max_height + 1) * 2 - 1 - z
                                ]
                            else:  # 0
                                targetcoords = [
                                    t, 1 + (max_height * 2 - z) * (rot + 1) *
                                    (2 if has_winter else 1)
                                ]
                            imgref.coords[0] = targetcoords[1]
                            imgref.coords[1] = targetcoords[0]
                            targetcoords[0] *= paksize
                            targetcoords[1] *= paksize
                            newimage.blit(loadedimages[imgname], targetcoords,
                                          srccoords)
                            imgref.file = cname
                            obj.put(indexstr, str(imgref))
                        else:
                            # misssing winter image even if winter declared
                            print "Missing image", indexstr

        pygame.image.save(newimage, os.path.join(outdir, cname + ".png"))

        f = open(os.path.join(outdir, cname + ".dat"), 'w')
        for l in obj.lines:
            f.write(l)
        f.close()
コード例 #2
0
def procObj(obj) :
	objname = obj.ask("name")
	print "processing", objname
	
	if obj.ask("type", "none").lower() in ["res", "com", "ind", "cur"] : # needs default string because of lower()
		dims = obj.ask("dims", "1,1,1")
		dims = dims.split(",")
		if len(dims) == 2 :
			dims.append("1")
		# dims converted to canonical form [?, ?, ?] of strings
		
		rots = int(dims[2])
		has_winter = False
		max_height = 0
		max_anim = 0
		
		images = obj.ask_indexed("backimage")
		
		# preparsing pass - find what are the features of object: seasons, animation...
		for item in images : # tuples [params] = value -> (params, value)
			indices = item[0].split("][")
			# first and last item still have the single bracket!
			if len(indices) > 0 :
				indices[0] = indices[0][1:]
				indices[-1] = indices[-1][:-1]
				# so fix them ^
				if len(indices) == 6 :
					has_winter = indices[5] == "1" or has_winter
				max_anim = max(int(indices[4]), max_anim)
				max_height = max(int(indices[3]), max_height)
		
		# now we know the numbers so we can select new image layout etc.
		if max_anim > 0 :
			# animated?
			# primary animation, secondary rotations, then snow and height
			layout = 0
			new_height = 1 + (max_height + 1) * rots * (2 if has_winter else 1) # first +1 for text row
			new_width = max((max_anim + 1), minwidth)
		elif rots > 1 :
			# no anim. -> rotations?
			# primary rotations, secondary snow and height
			layout = 1
			new_height = 1 + (max_height + 1) * (2 if has_winter else 1)
			new_width = max(rots, minwidth)
		else :
			# no anim or rotation?
			# primary climates (if any!), secondary height
			layout = 2
			new_height = 1 + (max_height + 1)
			new_width = max((2 if has_winter else 1), minwidth)
		
		newimage = pygame.Surface((paksize * new_width, paksize * new_height))
		newimage.fill((231,255,255)) # background
		newimage.fill((255,255,255), (0, 0, new_width * paksize, paksize)) # description stripe
		
		text = "name: " + obj.ask("name", "?")
		surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
		newimage.blit(surf, (10, 10))
		
		text = "copyright: " + obj.ask("copyright", "?")
		surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
		newimage.blit(surf, (10, 10 + fntsize + 4))
		
		cname = simutools.canonicalObjName(objname)
		
		# blitting pass - copy the parts onto new picture
		for rot in xrange(rots) :
			for z in xrange(max_height + 1) : # +1 because we read maximal index, not number of them!
				for t in xrange(max_anim + 1) : # +1 same here
					indexstr = "backimage[%i][0][0][%i][%i]" % (rot, z, t)
					value = obj.ask(indexstr)
					if value == None :
						# failed but asking is precise, so ask again for explicit number with no winter
						indexstr = "backimage[%i][0][0][%i][%i][0]" % (rot, z, t)
						value = obj.ask(indexstr)
					# now it must be a string! or a mising image
					if value != None :
						# the good case
						imgref = simutools.SimutransImgParam(value)
						imgname = os.path.join(os.path.dirname(obj.srcfile), imgref.file + ".png")
						if not loadedimages.has_key(imgname) :
							loadedimages[imgname] = pygame.image.load(imgname)
						srccoords = pygame.Rect(imgref.coords[1] * paksize, \
							imgref.coords[0] * paksize, paksize, paksize) # calculate position on old image
						if layout == 2 :
							targetcoords = [0, 1 + max_height - z]
						elif layout == 1 :
							targetcoords = [rot, 1 + max_height - z]
						else : # 0
							targetcoords = [t, 1 + (max_height - z) * (rot + 1) * (2 if has_winter else 1)]
						imgref.coords[0] = targetcoords[1]; imgref.coords[1] = targetcoords[0]
						targetcoords[0] *= paksize; targetcoords[1] *= paksize
						newimage.blit(loadedimages[imgname], targetcoords, srccoords) # copy image tile
						imgref.file = cname
						obj.put(indexstr, str(imgref))
					else :
						# say if it is mising!
						print "Missing image", indexstr
					if has_winter :
						indexstr = "backimage[%i][0][0][%i][%i][1]" % (rot, z, t)
						value = obj.ask(indexstr)
						if value != None :
							imgref = simutools.SimutransImgParam(value)
							imgname = os.path.join(os.path.dirname(obj.srcfile), imgref.file + ".png")
							if not loadedimages.has_key(imgname) :
								loadedimages[imgname] = pygame.image.load(imgname)
							srccoords = pygame.Rect(imgref.coords[1] * paksize, \
								imgref.coords[0] * paksize, paksize, paksize)
							if layout == 2 :
								targetcoords = [1, 1 + max_height - z]
							elif layout == 1 :
								targetcoords = [rot, 1 + (max_height + 1) * 2 - 1 - z]
							else : # 0
								targetcoords = [t, 1 + (max_height * 2 - z) * (rot + 1) * (2 if has_winter else 1)]
							imgref.coords[0] = targetcoords[1]; imgref.coords[1] = targetcoords[0]
							targetcoords[0] *= paksize; targetcoords[1] *= paksize
							newimage.blit(loadedimages[imgname], targetcoords, srccoords)
							imgref.file = cname
							obj.put(indexstr, str(imgref))
						else :
							# misssing winter image even if winter declared
							print "Missing image", indexstr

		
		pygame.image.save(newimage, os.path.join(outdir, cname + ".png"))
		
		f = open(os.path.join(outdir, cname + ".dat"), 'w')
		for l in obj.lines :
			f.write(l)
		f.close()
コード例 #3
0
ファイル: split-vehicles.py プロジェクト: 2015a0001/testarea
def procObj(obj) :
	objname = obj.ask("name")
	print("processing", objname)
	
	num_freights = len(obj.ask_indexed("freightimagetype")) # we don't need them, just numbers
	
	emptyimages = obj.ask_indexed("emptyimage")
	freightimages = obj.ask_indexed("freightimage")
	
	if len(emptyimages) < 1 :
		raise Exception("no images!")
	
	rows = 1 + 1 + max([num_freights, int(len(freightimages) > 0), 0])
	# description + empty + max(variable freights, 1|0 for freightimages present, 0)
	
	text_step = fntsize
	
	newimage = pygame.Surface((outsize * 8, outsize * rows)) #(w,h)
	newimage.fill((231,255,255)) # background
	newimage.fill((255,255,255), (0, 0, 8 * outsize, outsize)) # description stripe is white
	
	text = "name: " + obj.ask("name", "?")
	surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
	newimage.blit(surf, (10, 10 + 0 * text_step))
	
	text = "copyright: " + obj.ask("copyright", "?")
	surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
	newimage.blit(surf, (10, 10 + 1 * text_step))
	
	text = "timeline: %s - %s" % (obj.ask("intro_year", "*"), obj.ask("retire_year", "*"))
	surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
	newimage.blit(surf, (10, 10 + 2 * text_step))

	text = "stats: %s km/h, %s kW, %s/16 tile" % (obj.ask("speed", "???"), obj.ask("power", "0"), obj.ask("length", "8 (default)"))
	surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
	newimage.blit(surf, (10, 10 + 3 * text_step))
	
	text = "cargo: %s  %s" % (obj.ask("payload", "0"), obj.ask("freight", "None"))
	surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
	newimage.blit(surf, (10, 10 + 4 * text_step))
	
	img_name =  simutools.canonicalObjName(objname)
	
	for i in range(len(dirs)) :
		indexstr = "emptyimage[%s]" % (dirs[i])
		targetcoords = [i, 1] # always second row
		transferImageTile(obj, indexstr, newimage, targetcoords, img_name)
	
	if (num_freights > 0) :
		# more image sets
		for cargo in range(num_freights) :
			for i in range(len(dirs)) :
				indexstr = "freightimage[%i][%s]" % (cargo, dirs[i])
				targetcoords = [i, 2 + cargo] # starting at third row
				transferImageTile(obj, indexstr, newimage, targetcoords, img_name)
		
	elif (len(freightimages) > 0) :
		# single cargo image set
		for i in range(len(dirs)) :
			indexstr = "freightimage[%s]" % (dirs[i])
			targetcoords = [i, 2] # always third row
			transferImageTile(obj, indexstr, newimage, targetcoords, img_name)
	
	pygame.image.save(newimage, os.path.join(outdir, img_name + ".png"))
	
	f = open(os.path.join(outdir, img_name + ".dat"), 'w')
	for l in obj.lines :
		f.write(l)
	f.close()
コード例 #4
0
def procObj(obj) :
	objname = obj.ask("name")
	cname = simutools.canonicalObjName(objname)

	images = []
	
	for param in simutools.ImageParameterNames :
		images += map(lambda i: (param, i[0], i[1]), obj.ask_indexed(param))
	
	for param in simutools.SingleImageParameterNames :
		value = obj.ask(param)
		if value :
			images.append((param, "", value))
	
	newimage = pygame.Surface((paksize, paksize))
	newimage.fill((231,255,255)) # background
	
	for i in range(len(images)) :
		key, indices, raw_ref = images[i]
		imgref = simutools.SimutransImgParam(raw_ref)
		
		if not imgref.isEmpty() :
		
			imgname = os.path.normpath(os.path.join(os.path.dirname(obj.srcfile), imgref.file + ".png"))
			
			if not imgname in loadedimages :
				loadedimages[imgname] = pygame.image.load(imgname)
			
			srccoords_px = pygame.Rect(imgref.coords[1] * paksize, \
				imgref.coords[0] * paksize, paksize, paksize) # calculate position on old image
			
			newimage.blit(loadedimages[imgname], (0,0), srccoords_px) # copy image tile
			
			off_x, off_y = imgref.offset
			off_x, off_y = -off_x, -off_y
			changed = True
			save = False
			while True :
				pygame.time.wait(50)
				
				pygame.event.pump()
				keys = pygame.key.get_pressed()
				if keys[pygame.K_SPACE] or keys[pygame.K_ESCAPE] :
					pygame.time.wait(500)
					break
				elif keys[pygame.K_RETURN] :
					pygame.time.wait(500)
					save = True
					break
				elif keys[pygame.K_LEFT] :
					off_x = off_x - 1
					changed = True
				elif keys[pygame.K_RIGHT] :
					off_x = off_x + 1
					changed = True
				elif keys[pygame.K_UP] :
					off_y = off_y - 1
					changed = True
				elif keys[pygame.K_DOWN] :
					off_y = off_y + 1
					changed = True
				elif pygame.mouse.get_pressed()[0] :
					mx, my = pygame.mouse.get_pos()
					off_x = mx - 100 - paksize / 2
					off_y = my - 100 - (paksize * 3) / 4
					changed = True
				
				if changed :
					screen.fill((0,0,0))
					screen.blit(newimage, (100,100))
					screen.blit(cursor, (100 + off_x, 100 + off_y), newimage.get_bounding_rect())
					pygame.display.flip()
					changed = False

			if save :
				imgref.offset = -off_x, -off_y
				obj.put(key + indices, str(imgref))
			
	
	f = open(os.path.join(outdir, cname + ".dat"), 'w')
	for l in obj.lines :
		f.write(l)
	f.close()
コード例 #5
0
def procObj(obj):
    objname = obj.ask("name")
    print("processing", objname)

    num_freights = len(obj.ask_indexed(
        "freightimagetype"))  # we don't need them, just numbers

    emptyimages = obj.ask_indexed("emptyimage")
    freightimages = obj.ask_indexed("freightimage")

    if len(emptyimages) < 1:
        raise Exception("no images!")

    rows = 1 + 1 + max([num_freights, int(len(freightimages) > 0), 0])
    # description + empty + max(variable freights, 1|0 for freightimages present, 0)

    text_step = fntsize

    newimage = pygame.Surface((outsize * 8, outsize * rows))  #(w,h)
    newimage.fill((231, 255, 255))  # background
    newimage.fill((255, 255, 255),
                  (0, 0, 8 * outsize, outsize))  # description stripe is white

    text = "name: " + obj.ask("name", "?")
    surf = font.render(text, False, (0, 0, 0),
                       (255, 255, 255))  # black text on white
    newimage.blit(surf, (10, 10 + 0 * text_step))

    text = "copyright: " + obj.ask("copyright", "?")
    surf = font.render(text, False, (0, 0, 0),
                       (255, 255, 255))  # black text on white
    newimage.blit(surf, (10, 10 + 1 * text_step))

    text = "timeline: %s - %s" % (obj.ask("intro_year",
                                          "*"), obj.ask("retire_year", "*"))
    surf = font.render(text, False, (0, 0, 0),
                       (255, 255, 255))  # black text on white
    newimage.blit(surf, (10, 10 + 2 * text_step))

    text = "stats: %s km/h, %s kW, %s/16 tile" % (obj.ask(
        "speed", "???"), obj.ask("power", "0"), obj.ask(
            "length", "8 (default)"))
    surf = font.render(text, False, (0, 0, 0),
                       (255, 255, 255))  # black text on white
    newimage.blit(surf, (10, 10 + 3 * text_step))

    text = "cargo: %s  %s" % (obj.ask("payload",
                                      "0"), obj.ask("freight", "None"))
    surf = font.render(text, False, (0, 0, 0),
                       (255, 255, 255))  # black text on white
    newimage.blit(surf, (10, 10 + 4 * text_step))

    img_name = simutools.canonicalObjName(objname)

    for i in range(len(dirs)):
        indexstr = "emptyimage[%s]" % (dirs[i])
        targetcoords = [i, 1]  # always second row
        transferImageTile(obj, indexstr, newimage, targetcoords, img_name)

    if (num_freights > 0):
        # more image sets
        for cargo in range(num_freights):
            for i in range(len(dirs)):
                indexstr = "freightimage[%i][%s]" % (cargo, dirs[i])
                targetcoords = [i, 2 + cargo]  # starting at third row
                transferImageTile(obj, indexstr, newimage, targetcoords,
                                  img_name)

    elif (len(freightimages) > 0):
        # single cargo image set
        for i in range(len(dirs)):
            indexstr = "freightimage[%s]" % (dirs[i])
            targetcoords = [i, 2]  # always third row
            transferImageTile(obj, indexstr, newimage, targetcoords, img_name)

    pygame.image.save(newimage, os.path.join(outdir, img_name + ".png"))

    f = open(os.path.join(outdir, img_name + ".dat"), 'w')
    for l in obj.lines:
        f.write(l)
    f.close()
コード例 #6
0
ファイル: pakdoc.py プロジェクト: havekes/pak128.modern
def generate_vehicles() :
	waytypes = ["all", "road", "track", "water", "tram_track", "air", "maglev_track", "monorail_track", "narrowgauge_track"] #!!!!
	goods = ["all"] + list(goods_types)
	wtg_table = list(product(waytypes, goods)) # list of tuples (wt,gt)
	
	main_params = ["icon", "name", "waytype", "speed", "power", "freight", "payload", "cost", "runningcost", "intro_year", "retire_year"] #!!!!
	heads = ["<th>%s</th>" % _(p) for p in main_params]
	heads[0] = """<th class="sorttable_nosort">image</th>"""
	table_header = """<thead>%s</thead>""" % ("".join(heads))
	
	vehicles = {}
	for wtg in wtg_table :
		vehicles[wtg] = [[], 0, "", ""] # objects, file handle, html nav, subfolder nav (reused by individual files!)
	
	name_table = {} # name:obj, for checking constraints
	# categorize and count stuff
	for obj in Items["vehicle"] :
		obj.put("goods", goods_table[obj.ask("freight", "None")]) # exchange goods for their categories where applicable
		name = obj.ask("name")
		obj.cname = simutools.canonicalObjName(name)
		obj.fname = "%s.html" % obj.cname
		obj.iconname = "%s_icon.%s" % (obj.cname, imgformat)
		wt = obj.ask("waytype")
		gt = obj.ask("goods", "None")
		vehicles[(wt,gt)][0].append(obj)
		vehicles[("all",gt)][0].append(obj)
		vehicles[(wt,"all")][0].append(obj)
		vehicles[("all","all")][0].append(obj)
		name_table[name] = obj
	
	# overview html files - generate navigations, open files etc
	for wtg in wtg_table :
		wt,gt = wtg # unpack tuple into vars
		
		links = ["""<a href="vehicles_wt_%s_gt_%s.html">%s (%d)</a>""" % (iwt, gt, _(iwt), len(vehicles[(iwt,gt)][0])) for iwt in waytypes]
		veh_wt_nav = """<p class="nav">waytypes: [ """ + " | ".join(links) + """ ]</p>\n"""
		links = ["""<a href="vehicles_wt_%s_gt_%s.html">%s (%d)</a>""" % (wt, igt, _(igt), len(vehicles[(wt,igt)][0])) for igt in goods]
		veh_g_nav = """<p class="nav">goods: [ """ + " | ".join(links) + """ ]</p>\n"""
		veh_nav_help = """<p class="nav">(Clicking changes way or goods type, keeping the other as curently selected.)</p>\n"""
		veh_nav = veh_wt_nav + veh_g_nav + veh_nav_help

		links = ["""<a href="../vehicles_wt_%s_gt_%s.html">%s (%d)</a>""" % (iwt, gt, _(iwt), len(vehicles[(iwt,gt)][0])) for iwt in waytypes]
		sub_wt_nav = """<p class="nav">waytypes: [ """ + " | ".join(links) + """ ]</p>\n"""
		links = ["""<a href="../vehicles_wt_%s_gt_%s.html">%s (%d)</a>""" % (wt, igt, _(igt), len(vehicles[(wt,igt)][0])) for igt in goods]
		sub_g_nav = """<p class="nav">goods: [ """ + " | ".join(links) + """ ]</p>\n"""
		sub_nav = sub_wt_nav + sub_g_nav
		
		f = open(local_filename("vehicles_wt_%s_gt_%s.html" % (wt,gt)), 'w')
		f.write(html_start("Vehicle overview - %s, %s" % (_(wt),_(gt))))
		f.write(veh_nav)
		f.write(html_h1("Vehicle overview - %s, %s" % (_(wt),_(gt))))
		f.write("""<table class="sortable">\n""")
		f.write(table_header)
		
		vehicles[wtg][1] = f
		vehicles[wtg][2] = veh_nav
		vehicles[wtg][3] = sub_nav
	
	for obj in Items["vehicle"] :
		name = obj.ask("name")
		f = open(local_filename(obj.fname, "vehicles"), 'w')
		f.write(html_start(_(name), 1))
		# navigations - need way and goods type
		wt = obj.ask("waytype")
		gt = obj.ask("goods", "None")
		f.write(vehicles[(wt,gt)][3])
		f.write(html_h1(_(name)))
		# icon
		icon = compose_vehicle_icon(obj)
		pygame.image.save(icon, local_filename(obj.iconname, "vehicles"))
		# image
		mainimage = compose_vehicle_image(obj)
		imagename = "image_vehicle_%s.%s" % (obj.cname, imgformat)
		pygame.image.save(mainimage, local_filename(imagename, "vehicles"))
		f.write(html_img(imagename))

		# output to own file
		params = {}
		detail_params = main_params + ["intro_month", "retire_month", "engine_type", "weight", "gear"] #!!!!
		for param in detail_params :
			params[param] = obj.ask(param, "-")
		params["icon"] = """<img src="%s" />""" % (obj.iconname)
		f.write(html_deflist(params))
		
		# constraints
		f.write(html_h2("Constraints"))
		f.write("""<table class="constraints">\n<thead><th>prev</th><th>this</th><th>next</th></thead>\n""")
		constr = obj.ask_indexed("constraint")
		prev = []
		next = []
		this = [name]
		for c in constr :
			if (c[1].lower() != "none") and (c[1] not in name_table.keys()) :
				print("  invalid constraint: %s, %s=%s" % (name, c[0], c[1]))
				break
			if c[0][:6] == "[prev]" :
				prev.append(c[1])
			elif c[0][:6] == "[next]" :
				next.append(c[1])
		# here, logic gets tricky because the axis of lists is orthogonal to order of writing the html table
		# so make all lists same length into a "fake 2d array" spanning the 3, then "iterate sideways" across them
		# resulting table has always full side columns and the middle has only first cell with rowspan
		total_rows = max(len(prev), len(next), 1)
		prev += [""]*(total_rows - len(prev)) # padding at ends
		this += [""]*(total_rows - len(this))
		next += [""]*(total_rows - len(next))
		for i in range(total_rows) :
			p = prev[i]
			t = this[i]
			n = next[i]
			if p == "" :
				p = "<td></td>"
			elif p == "none" :
				p = "<td>(start of convoy)</td>"
			else :
				pc = simutools.canonicalObjName(p)
				p = """<td><a href="%s.html"><img src="%s_icon.%s" title="%s" /></a></td>""" % (pc, pc, imgformat, _(p))
			if t != "" :
				t = """<td rowspan="%d" class="this"><img src="%s" title="%s" /></td>""" % (total_rows, obj.iconname, _(name))
				# special - has rowspan, centers etc.
			if n == "" :
				n = "<td></td>"
			elif n == "none" :
				n = "<td>(end of convoy)</td>"
			else :
				nc = simutools.canonicalObjName(n)
				n = """<td><a href="%s.html"><img src="%s_icon.%s" title="%s" /></a></td>""" % (nc, nc, imgformat, _(n))
			f.write("""<tr>%s%s%s</tr>\n""" % (p,t,n))
		f.write("</table>\n")
		
		# output to overviews
		params["icon"] = """<a href="vehicles/%s"><img src="vehicles/%s" /></a>""" % (obj.fname, obj.iconname)
		params["name"] = """<a href="vehicles/%s">%s</a>""" % (obj.fname, _(name))
		table_cells = ["<td>%s</td>" % _(params[p]) for p in main_params]
		table_line = "<tr>" + "".join(table_cells) + "</tr>\n"
		for spec in [(wt,gt), (wt, "all"), ("all",gt), ("all","all")] :
			vehicles[spec][1].write(table_line)
		# finalize own file
		f.write(html_end())
		f.close()
	
	for wtg in wtg_table :
		f = vehicles[wtg][1]
		f.write("</table>\n")
		f.write(html_end())
		f.close()
コード例 #7
0
def procObj(obj) :
	objname = obj.ask("name")
	objkind = obj.ask("obj")
	cname = simutools.canonicalObjName(objname)
	if use_obj_kind_prefix :
		cname = "%s,%s" % (cname, objkind)
	print("processing", objname)
	
	images = []
	
	for param in simutools.ImageParameterNames :
		images += map(lambda i: (param, i[0], i[1]), obj.ask_indexed(param))
	
	for param in simutools.SingleImageParameterNames :
		value = obj.ask(param)
		if value :
			images.append((param, "", value))
	
	total_length_px = len(images) * paksize
	max_width_px = 1024.0
	min_width_px = 384.0 # both fixed, based on common screen and text
	
	new_width_px = max(min(total_length_px, max_width_px), min_width_px) # restrict to range
	new_width = int(float(new_width_px) / paksize)
	new_height = math.ceil(len(images) / float(new_width)) + 1
	
	newimage = pygame.Surface((paksize * new_width, paksize * new_height))
	newimage.fill((231,255,255)) # background
	newimage.fill((255,255,255), (0, 0, new_width * paksize, paksize)) # description stripe
	
	text = "name: " + objname
	surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
	newimage.blit(surf, (10, 10))
	
	text = "copyright: " + obj.ask("copyright", "?", False)
	surf = font.render(text, False, (0,0,0), (255,255,255))
	newimage.blit(surf, (10, 10 + fntsize + 4))
	
	type = obj.ask("type", "?")
	if type != "?" :
		text = "obj: %s ; type: %s" % (objkind, type)
	else :
		text = "obj: %s" % objkind
	surf = font.render(text, False, (0,0,0), (255,255,255))
	newimage.blit(surf, (10, 10 + 2 * (fntsize + 4)))
	
	text = "timeline: %s - %s" % (obj.ask("intro_year", "*"), obj.ask("retire_year", "*"))
	surf = font.render(text, False, (0,0,0), (255,255,255))
	newimage.blit(surf, (10, 10 + 3 * (fntsize + 4)))
	
	targetcoords = [0, 1]
	
	for i in range(len(images)) :
		kind, indices, imgref = images[i]
		imgref = simutools.SimutransImgParam(imgref)
		
		if not imgref.isEmpty() :
		
			imgname = os.path.normpath(os.path.join(os.path.dirname(obj.srcfile), imgref.file + ".png"))
			
			if not imgname in loadedimages :
				loadedimages[imgname] = pygame.image.load(imgname)
			
			srccoords_px = pygame.Rect(imgref.coords[1] * paksize, \
				imgref.coords[0] * paksize, paksize, paksize) # calculate position on old image
			
			imgref.coords[0] = targetcoords[1]; imgref.coords[1] = targetcoords[0]
			targetcoords_px = [x * paksize for x in targetcoords]
			
			newimage.blit(loadedimages[imgname], targetcoords_px, srccoords_px) # copy image tile
			imgref.file = cname
			obj.put(kind + indices, str(imgref))
			
			targetcoords[0] += 1
			if targetcoords[0] >= new_width :
				targetcoords[0] = 0
				targetcoords[1] += 1
	
	pygame.image.save(newimage, os.path.join(outdir, cname + ".png"))
	
	f = open(os.path.join(outdir, cname + ".dat"), 'w')
	for l in obj.lines :
		f.write(l)
	f.close()
コード例 #8
0
ファイル: pakdoc.py プロジェクト: havekes/pak128.modern
def generate_stations() :
	waytypes = {"extension":[], "road":[], "track":[], "water":[], "tram_track":[], "air":[], "maglev_track":[], "monorail_track":[], "narrowgauge_track":[]} #!!!!
	
	for obj in Items["station"] :
		name = obj.ask("name")
		type = obj.ask("type", "")
		if type == "extension" :
			obj.put("waytype", "extension")
		elif type == "habour" :
			obj.put("waytype", "water")
		wt = obj.ask("waytype", "extension").lower()
		waytypes[wt].append(obj)
		obj.cname = simutools.canonicalObjName(name)
		obj.fname = "%s.html" % obj.cname
		obj.iconname = "%s_icon.%s" % (obj.cname, imgformat)
		enables = ""
		pax = bool(int(obj.ask("enables_pax", "0")))
		mail = bool(int(obj.ask("enables_post", "0")))
		cargo = bool(int(obj.ask("enables_ware", "0")))
		if pax :
			enables += ", pax"
		if mail :
			enables += ", mail"
		if cargo :
			enables += ", cargo"
		if enables :
			enables = enables[2:]
		else :
			enables = "-"
		obj.put("enables", enables)
	
	# navigation links, need counts
	links = ["""<a href="stations_%s.html">%s (%d)</a>""" % (type,_(type),len(objs)) for type,objs in waytypes.items()]
	links.insert(0, """<a href="stations_all.html">all (%d)</a>""" % len(Items["station"]))
	stat_nav = """<p class="nav">waytypes: [ %s ]</p>\n""" % (" | ".join(links))
	
	# generate total overview
	main_params = ["icon", "name", "waytype", "enables", "level", "intro", "retire"] #!!!!
	mainf = open(local_filename("stations_all.html"), 'w')
	mainf.write(html_start("Station overview - all types"))
	mainf.write(stat_nav)
	mainf.write(html_h1("Station overview - all types"))
	heads = ["""<th>%s</th>""" % _(p) for p in main_params]
	heads[0] = """<th class="sorttable_nosort">icon</th>"""
	mainf.write("""<table class="sortable">\n<thead>%s</thead>\n""" % "".join(heads))
	
	# init local overviews
	loc_f = {}
	for wt in waytypes.keys() :
		f = open(local_filename("stations_%s.html" % wt), 'w')
		name = "Station overview - %s" % _(wt)
		f.write(html_start(name))
		f.write(stat_nav)
		f.write(html_h1(name))
		f.write("""<table class="sortable">\n<thead>%s</thead>\n""" % "".join(heads))
		loc_f[wt] = f
	
	# navigation links again
	links = ["""<a href="../stations_%s.html">%s (%d)</a>""" % (type,_(type),len(objs)) for type,objs in waytypes.items()]
	links.insert(0, """<a href="../stations_all.html">all (%d)</a>""" % len(Items["station"]))
	stat_nav = """<p class="nav">waytypes: [ %s ]</p>\n""" % (" | ".join(links))
	
	# generate individual objects
	for obj in Items["station"] :
		name = obj.ask("name")
		# icon
		icon = compose_building_icon(obj)
		pygame.image.save(icon, local_filename(obj.iconname, "stations"))
		# image composed from overlaid backimages and frontimages and icon
		mainimage = compose_building_image(obj)
		imagename = "%s_image.%s" % (obj.cname, imgformat)
		pygame.image.save(mainimage, local_filename(imagename, "stations"))
		# prepare values
		params = {}
		params["icon"] = """<a href="stations/%s"><img src="stations/%s" /></a>""" % (obj.fname, obj.iconname)
		params["name"] = """<a href="stations/%s">%s</a>""" % (obj.fname, _(name))
		params["waytype"] = obj.ask("waytype", "none")
		params["enables"] = obj.ask("enables", "-")
		params["level"] = obj.ask("level", "-")
		intro_month = int(obj.ask("intro_month", "1"))
		intro_year = int(obj.ask("intro_year", "-1"))
		params["intro"] = "%s %d" % (MONTHS[intro_month], intro_year) if intro_year>-1 else "-"
		intro_sort = "%d+%s" % (intro_year, intro_month)
		retire_month = int(obj.ask("retire_month", "1"))
		retire_year = int(obj.ask("retire_year", "-1"))
		params["retire"] = "%s %d" % (MONTHS[retire_month], retire_year) if retire_year>-1 else "-"
		retire_sort = "%d+%s" % (retire_year, retire_month)
		# output to overviews
		table_cells = ["<td>%s</td>" % _(params[p]) for p in main_params]
		table_line = """<tr>%s</tr>\n""" % "".join(table_cells)
		mainf.write(table_line)
		loc_f[params["waytype"]].write(table_line)
		# prepare values for writing own file
		if intro_year > -1 :
			if retire_year > -1 :
				# both dates set
				timeline = params["intro"] + " - " + params["retire"]
			else :
				# only intro
				timeline = "since " + params["intro"]
		else :
			if retire_year > -1 :
				# only retire
				timeline = "until " + params["retire"]
			else :
				# no timeline
				timeline = "always available"
		# output to own file
		f = open(local_filename(obj.fname, "stations"), 'w')
		f.write(html_start(_(name), 1))
		f.write(stat_nav)
		f.write(html_h1(_(name)))
		f.write(html_img(imagename))
		f.write("""<table class="parameters"><tbody>\n""")
		f.write("<tr><td>internal name</td><td>%s</td></tr>" % name)
		f.write("<tr><td>%s</td><td>%s</td></tr>" % (_("waytype"), _(params["waytype"])))
		f.write("<tr><td>type</td><td>%s</td></tr>" % _(type))
		f.write("<tr><td>%s</td><td>%s</td></tr>" % (_("enables"), _(params["enables"])))
		f.write("<tr><td>%s</td><td>%s</td></tr>" % (_("level"), params["level"]))
		f.write("<tr><td>timeline</td><td>%s</td></tr>" % timeline)
		f.write("</tbody></table>\n")
		f.write(html_end())
		f.close()
		
	mainf.write("</table>\n")
	mainf.write(html_end())
	mainf.close()
	
	for wt in waytypes.keys() :
		f = loc_f[wt]
		f.write("</table>\n")
		f.write(html_end())
		f.close()
コード例 #9
0
ファイル: pakdoc.py プロジェクト: havekes/pak128.modern
def generate_ways() :
	waytypes = {"road":[], "track":[], "water":[], "tram_track":[], "air":[], "maglev_track":[], "monorail_track":[], "narrowgauge_track":[], "power":[]} #!!!!
	all_ways = Items["way"]+Items["bridge"]+Items["tunnel"]
	
	# preprocessing - sort into types, graphics etc.
	for obj in all_ways :
		waytypes[obj.ask("waytype")].append(obj)
		obj.cname = simutools.canonicalObjName(obj.ask("name"))
		obj.fname = "%s.html" % obj.cname
		obj.iconname = "%s_icon.%s" % (obj.cname, imgformat)
	
	# navigation links, need counts
	links = ["""<a href="ways_%s.html">%s (%d)</a>""" % (type,_(type),len(objs)) for type,objs in waytypes.items()]
	links.insert(0, """<a href="ways_all.html">all (%d)</a>""" % len(all_ways))
	way_nav = """<p class="nav">Waytypes: [ %s ]</p>\n""" % (" | ".join(links))
	
	# generate total overview
	main_params = ["icon", "name", "waytype", "topspeed", "cost", "maintenance", "intro", "retire"] #!!!!
	mainf = open(local_filename("ways_all.html"), 'w')
	mainf.write(html_start("Way overview, all types", 0, "way"))
	mainf.write(way_nav)
	mainf.write(html_h1("Way overview, all types"))
	heads = ["<th>%s</th>" % _(p) for p in main_params]
	heads[0] = """<th class="sorttable_nosort">icon</th>"""
	mainf.write("""<table class="sortable">\n<thead>%s</thead>\n""" % "".join(heads))
	
	# init specific overviews
	loc_f = {}
	for wt in waytypes.keys() :
		f = open(local_filename("ways_%s.html" % wt), 'w')
		f.write(html_start("Way overview - %s" % wt))
		f.write(way_nav)
		f.write(html_h1("Way overview - %s" % wt))
		f.write("""<table class="sortable">\n<thead>""")
		f.write("".join(heads) + "\n")
		f.write("</thead>\n")
		loc_f[wt] = f
	
	# navigation again - retarget links (now in subfolder)
	links = ["""<a href="../ways_%s.html">%s (%d)</a>""" % (type,_(type),len(objs)) for type,objs in waytypes.items()]
	links.insert(0, """<a href="../ways_all.html">all (%d)</a>""" % len(all_ways))
	way_nav = """<p class="nav">Waytypes: [ %s ]</p>\n""" % (" | ".join(links))

	# generate individual objects
	for obj in all_ways :
		name = obj.ask("name")
		# icon
		icon = compose_way_icon(obj)
		pygame.image.save(icon, local_filename(obj.iconname, "ways"))
		# image composed from overlaid backimage and frontimage and icon
		mainimage = compose_way_image(obj)
		imagename = "%s_image.%s" % (obj.cname, imgformat)
		pygame.image.save(mainimage, local_filename(imagename, "ways"))
		# prepare values
		params = {}
		params["icon"] = html_img(obj.iconname)
		params["name"] = name
		params["waytype"] = obj.ask("waytype", "-")
		params["topspeed"] = obj.ask("topspeed", "-")
		params["cost"] = obj.ask("cost", "-")
		params["maintenance"] = obj.ask("maintenance", "-")
		intro_month = int(obj.ask("intro_month", "1"))
		intro_year = int(obj.ask("intro_year", "-1"))
		params["intro"] = "%s %d" % (MONTHS[intro_month], intro_year) if intro_year>-1 else "-"
		intro_sort = "%d+%s" % (intro_year, intro_month)
		retire_month = int(obj.ask("retire_month", "1"))
		retire_year = int(obj.ask("retire_year", "-1"))
		params["retire"] = "%s %d" % (MONTHS[retire_month], retire_year) if retire_year>-1 else "-"
		retire_sort = "%d+%s" % (retire_year, retire_month)
		# output to overviews
		params["icon"] = """<a href="ways/%s"><img src="ways/%s" /></a>""" % (obj.fname, obj.iconname)
		params["name"] = """<a href="ways/%s">%s</a>""" % (obj.fname, _(name))
		table_cells = ["<td>%s</td>" % _(params[p]) for p in main_params]
		table_line = """<tr>%s</tr>\n""" % "".join(table_cells)
		mainf.write(table_line)
		loc_f[params["waytype"]].write(table_line)
		# prepare values for writing own file
		type = obj.ask("obj")
		if type=="way" and obj.ask("system_type")=="1" :
			type = "elevated"
		if intro_year > -1 :
			if retire_year > -1 :
				# both dates set
				timeline = params["intro"] + " - " + params["retire"]
			else :
				# only intro
				timeline = "since " + params["intro"]
		else :
			if retire_year > -1 :
				# only retire
				timeline = "until " + params["retire"]
			else :
				# no timeline
				timeline = "always available"
		# output to own file
		f = open(local_filename(obj.fname, "ways"), 'w')
		f.write(html_start(_(name), 1))
		f.write(way_nav)
		f.write(html_h1(_(name)))
		f.write(html_img(imagename))
		f.write("""<table class="parameters"><tbody>\n""")
		f.write("<tr><td>internal name</td><td>%s</td></tr>" % name)
		f.write("<tr><td>%s</td><td>%s</td></tr>" % (_("waytype"), _(params["waytype"])))
		f.write("<tr><td>type</td><td>%s</td></tr>" % _(type))
		f.write("<tr><td>%s</td><td>%s</td></tr>" % (_("topspeed"), _(params["topspeed"])))
		f.write("<tr><td>%s</td><td>%s</td></tr>" % (_("cost"), params["cost"]))
		f.write("<tr><td>%s</td><td>%s</td></tr>" % (_("maintenance"), params["maintenance"]))
		f.write("<tr><td>timeline</td><td>%s</td></tr>" % timeline)
		f.write("</tbody></table>\n")
		f.write(html_end())
		f.close()
		
	mainf.write("</table>\n")
	mainf.write(html_end())
	mainf.close()
	
	for wt in waytypes.keys() :
		f = loc_f[wt]
		f.write("</table>\n")
		f.write(html_end())
		f.close()
コード例 #10
0
def procObj(obj) :
	objname = obj.ask("name")
	print("processing", objname)
	
	if obj.ask("type", "none").lower() in ["res", "com", "ind", "cur"] : # needs default string because of lower()
		
		images = obj.ask_indexed("backimage")
		
		total_length_px = len(images) * paksize
		max_width_px = 1024.0
		min_width_px = 384.0 # both fixed, based on common screen and text
		
		new_width_px = max(min(total_length_px, max_width_px), min_width_px) # restrict to range
		new_width = int(float(new_width_px) / paksize)
		new_height = math.ceil(len(images) / float(new_width)) + 1
		
		newimage = pygame.Surface((paksize * new_width, paksize * new_height))
		newimage.fill((231,255,255)) # background
		newimage.fill((255,255,255), (0, 0, new_width * paksize, paksize)) # description stripe
		
		text = "name: " + obj.ask("name", "?")
		surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
		newimage.blit(surf, (10, 10))
		
		text = "copyright: " + obj.ask("copyright", "?")
		surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
		newimage.blit(surf, (10, 10 + fntsize + 4))
		
		cname = simutools.canonicalObjName(objname)
		
		targetcoords = [0, 1]
		
		for i in range(len(images)) :
			indices, imgref = images[i]
			imgref = simutools.SimutransImgParam(imgref)
			
			imgname = os.path.normpath(os.path.join(os.path.dirname(obj.srcfile), imgref.file + ".png"))
			
			if not imgname in loadedimages :
				loadedimages[imgname] = pygame.image.load(imgname)
			
			srccoords_px = pygame.Rect(imgref.coords[1] * paksize, \
				imgref.coords[0] * paksize, paksize, paksize) # calculate position on old image
			
			imgref.coords[0] = targetcoords[1]; imgref.coords[1] = targetcoords[0]
			targetcoords_px = [x * paksize for x in targetcoords]
			
			newimage.blit(loadedimages[imgname], targetcoords_px, srccoords_px) # copy image tile
			imgref.file = cname
			obj.put("backimage" + indices, str(imgref))
			
			targetcoords[0] += 1
			if targetcoords[0] >= new_width :
				targetcoords[0] = 0
				targetcoords[1] += 1
		
		pygame.image.save(newimage, os.path.join(outdir, cname + ".png"))
		
		f = open(os.path.join(outdir, cname + ".dat"), 'w')
		for l in obj.lines :
			f.write(l)
		f.close()
コード例 #11
0
def procObj(obj):
    objname = obj.ask("name")
    cname = simutools.canonicalObjName(objname)

    images = []

    for param in simutools.ImageParameterNames:
        images += map(lambda i: (param, i[0], i[1]), obj.ask_indexed(param))

    for param in simutools.SingleImageParameterNames:
        value = obj.ask(param)
        if value:
            images.append((param, "", value))

    newimage = pygame.Surface((paksize, paksize))
    newimage.fill((231, 255, 255))  # background

    for i in range(len(images)):
        key, indices, raw_ref = images[i]
        imgref = simutools.SimutransImgParam(raw_ref)

        if not imgref.isEmpty():

            imgname = os.path.normpath(
                os.path.join(os.path.dirname(obj.srcfile),
                             imgref.file + ".png"))

            if not imgname in loadedimages:
                loadedimages[imgname] = pygame.image.load(imgname)

            srccoords_px = pygame.Rect(imgref.coords[1] * paksize, \
             imgref.coords[0] * paksize, paksize, paksize) # calculate position on old image

            newimage.blit(loadedimages[imgname], (0, 0),
                          srccoords_px)  # copy image tile

            off_x, off_y = imgref.offset
            off_x, off_y = -off_x, -off_y
            changed = True
            save = False
            while True:
                pygame.time.wait(50)

                pygame.event.pump()
                keys = pygame.key.get_pressed()
                if keys[pygame.K_SPACE] or keys[pygame.K_ESCAPE]:
                    pygame.time.wait(500)
                    break
                elif keys[pygame.K_RETURN]:
                    pygame.time.wait(500)
                    save = True
                    break
                elif keys[pygame.K_LEFT]:
                    off_x = off_x - 1
                    changed = True
                elif keys[pygame.K_RIGHT]:
                    off_x = off_x + 1
                    changed = True
                elif keys[pygame.K_UP]:
                    off_y = off_y - 1
                    changed = True
                elif keys[pygame.K_DOWN]:
                    off_y = off_y + 1
                    changed = True
                elif pygame.mouse.get_pressed()[0]:
                    mx, my = pygame.mouse.get_pos()
                    off_x = mx - 100 - paksize / 2
                    off_y = my - 100 - (paksize * 3) / 4
                    changed = True

                if changed:
                    screen.fill((0, 0, 0))
                    screen.blit(newimage, (100, 100))
                    screen.blit(cursor, (100 + off_x, 100 + off_y),
                                newimage.get_bounding_rect())
                    pygame.display.flip()
                    changed = False

            if save:
                imgref.offset = -off_x, -off_y
                obj.put(key + indices, str(imgref))

    f = open(os.path.join(outdir, cname + ".dat"), 'w')
    for l in obj.lines:
        f.write(l)
    f.close()
コード例 #12
0
def procObj(obj) :
	objname = obj.ask("name")
	print("processing", objname)
	
	if obj.ask("type", "none").lower() in ["res", "com", "ind", "cur"] : # needs default string because of lower()
		
		images = obj.ask_indexed("backimage")
		
		total_length_px = len(images) * paksize
		max_width_px = 1024.0
		min_width_px = 384.0 # both fixed, based on common screen and text
		
		new_width_px = max(min(total_length_px, max_width_px), min_width_px) # restrict to range
		new_width = int(float(new_width_px) / paksize)
		new_height = math.ceil(len(images) / float(new_width)) + 1
		
		newimage = pygame.Surface((paksize * new_width, paksize * new_height))
		newimage.fill((231,255,255)) # background
		newimage.fill((255,255,255), (0, 0, new_width * paksize, paksize)) # description stripe
		
		text = "name: " + obj.ask("name", "?")
		surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
		newimage.blit(surf, (10, 10))
		
		text = "copyright: " + obj.ask("copyright", "?")
		surf = font.render(text, False, (0,0,0), (255,255,255)) # black text on white
		newimage.blit(surf, (10, 10 + fntsize + 4))
		
		cname = simutools.canonicalObjName(objname)
		
		targetcoords = [0, 1]
		
		for i in range(len(images)) :
			indices, imgref = images[i]
			imgref = simutools.SimutransImgParam(imgref)
			
			imgname = os.path.normpath(os.path.join(os.path.dirname(obj.srcfile), imgref.file + ".png"))
			
			if not imgname in loadedimages :
				loadedimages[imgname] = pygame.image.load(imgname)
			
			srccoords_px = pygame.Rect(imgref.coords[1] * paksize, \
				imgref.coords[0] * paksize, paksize, paksize) # calculate position on old image
			
			imgref.coords[0] = targetcoords[1]; imgref.coords[1] = targetcoords[0]
			targetcoords_px = [x * paksize for x in targetcoords]
			
			newimage.blit(loadedimages[imgname], targetcoords_px, srccoords_px) # copy image tile
			imgref.file = cname
			obj.put("backimage" + indices, str(imgref))
			
			targetcoords[0] += 1
			if targetcoords[0] >= new_width :
				targetcoords[0] = 0
				targetcoords[1] += 1
		
		pygame.image.save(newimage, os.path.join(outdir, cname + ".png"))
		
		f = open(os.path.join(outdir, cname + ".dat"), 'w')
		for l in obj.lines :
			f.write(l)
		f.close()