示例#1
0
def make_dmi(path, dest, parser):
	if(os.path.isfile(path)):
		dmi = None
		try:
			dmi = DMI(dest)
			dmi.make(path)
			dmi.save(dest)
		except SystemError as e:
			print("!!! Received SystemError in %s, halting: %s" % (dmi.filename, traceback.format_exc(e)))
			print('# of cells: %d' % len(dmi.states))
			print('Image h/w: %s' % repr(dmi.size))
			sys.exit(1)
		except Exception as e:
			print("Received error, continuing: %s" % traceback.format_exc())
示例#2
0
def makeDMI():
    dmi = DMI('state_limit.dmi')
    #
    for i in range(513):
        # Make a new tile
        img = Image.new('RGBA', (32, 32))
        # Set up PIL's drawing stuff
        draw = ImageDraw.Draw(img)
        # Define a font.
        font = ImageFont.truetype('arial.ttf', 10)
        # Draw the tile number
        draw.text((10, 0), str(i + 1), (0, 0, 0), font=font)
        # Make state
        state_name='state {0}'.format(i+1)
        state=State(state_name)
        state.dirs=1
        state.frames=1
        state.icons=[img]
        # Add state to DMI
        dmi.states[state_name]=state
    #save
    dmi.save('state_limit.dmi', sort=False)
示例#3
0
                arrname=arrangement
            elif isinstance(arrangement,list):
                arrange=arrangement[1:]
                arrname=arrangement[0]
            state='{base} {color} {arrangement}'.format(base=tileDef['base'],color=color,arrangement=arrname)
            nstate=State(state)
            nstate.dirs=len(arrange)
            nstate.frames=1
            nstate.icons=[None for _ in range(nstate.dirs)]
            #statedebug = DMI(state+'.dmi')
            nfloors.states[state]=nstate
            for d in range(len(arrange)):
                cmap = arrange[d]
                dirf = 0
                dirn = 'SOUTH'
                if len(arrange) > 1:
                    dirf = directions.IMAGE_INDICES[d]
                    dirn = directions.getNameFromDir(dirf)
                print(' Generating state {0} ({1})...'.format(repr(state),dirn))
                #print(repr(arrange))
                img=Image.new('RGBA',(32,32))
                img.paste(base)
                for i in range(len(cmap)):
                    bbox=quadDefs[i]
                    if cmap[i]:
                        img.paste(knownQuads[i][color],bbox)
                nfloors.setFrame(state, dirf, 0, img)
            #statedebug.states[state]=nfloors.states[state]
            #statedebug.save(state+'.dmi')
nfloors.save('nfloors.dmi')
示例#4
0
def compare(theirsfile, minefile, parser, reportstream, **kwargs):
	# print('\tD %s -> %s' % (theirsfile, minefile))
	theirs = []
	theirsDMI = None
	mine = []
	mineDMI = None
	states = []
	
	new2mineFilename = minefile.replace('.dmi', '.new.dmi')
	new2theirsFilename = theirsfile.replace('.dmi', '.new.dmi')
	
	new2mine=None
	if os.path.isfile(new2mineFilename):
		os.remove(new2mineFilename)
	if kwargs.get('newfile_mine',True):
		new2mine = DMI(new2mineFilename)
	
	new2theirs=None
	if os.path.isfile(new2theirsFilename):
		os.remove(new2theirsFilename)
	if kwargs.get('newfile_theirs',False):
		new2theirs = DMI(new2theirsFilename)
	
	
	o = ''
	if(os.path.isfile(theirsfile)):
		try:
			theirsDMI = DMI(theirsfile)
			theirsDMI.loadAll()
			theirs = theirsDMI.states
		except SystemError as e:
			print("!!! Received SystemError in %s, halting: %s" % (theirs.filename, traceback.format_exc(e)))
			print('# of cells: %d' % len(theirs.states))
			print('Image h/w: %s' % repr(theirs.size))
			sys.exit(1)
		except Exception as e:
			print("Received error, continuing: %s" % traceback.format_exc())
			o += "\n {0}: Received error, continuing: {1}".format(theirsfile, traceback.format_exc())
		for stateName in theirs:
			if stateName not in states:
				states.append(stateName)
	if(os.path.isfile(minefile)):
		try:
			mineDMI = DMI(minefile)
			mineDMI.loadMetadata()
			mine = mineDMI.states
		except SystemError as e:
			print("!!! Received SystemError in %s, halting: %s" % (mine.filename, traceback.format_exc(e)))
			print('# of cells: %d' % len(mine.states))
			print('Image h/w: %s' % repr(mine.size))
			sys.exit(1)
		except Exception as e:
			print("Received error, continuing: %s" % traceback.format_exc())
			o += "\n {0}: Received error, continuing: {1}".format(minefile, traceback.format_exc())
		for stateName in mine:
			if stateName not in states:
				states.append(stateName)
	for state in sorted(states):
		inTheirs = state in theirs
		inMine = state in mine 
		if inTheirs and not inMine:
			o += '\n + {1}'.format(minefile, state)
			if new2mine is not None:
				new2mine.states[state] = theirsDMI.states[state]
		elif not inTheirs and inMine:
			o += '\n - {1}'.format(theirsfile, state)
			if new2theirs is not None:
				new2theirs.states[state] = mineDMI.states[state]
		elif inTheirs and inMine:
			if theirs[state].ToString() != mine[state].ToString():
				o += '\n - {0}: {1}'.format(state, mine[state].ToString())
				o += '\n + {0}: {1}'.format(state, theirs[state].ToString())
	if o != '': 
		reportstream.write('\n--- {0}'.format(theirsfile))
		reportstream.write('\n+++ {0}'.format(minefile))
		reportstream.write(o)
		
		if new2mine is not None:
			if len(new2mine.states) > 0:
				new2mine.save(new2mineFilename)
			else:
				if os.path.isfile(new2mineFilename):
					os.remove(new2mineFilename)
					#print('RM {0}'.format(new2mineFilename))
		if new2theirs is not None:
			if len(new2theirs.states) > 0:
				new2theirs.save(new2theirsFilename)
			else:
				if os.path.isfile(new2theirsFilename):
					os.remove(new2theirsFilename)