def buildDMI(directory, output): dmi = DMI(output) logging.info('Creating {0}...'.format(output)) for root, _, files in os.walk(directory): for filename in files: if filename.endswith('.dmi') and not filename.endswith('.new.dmi'): filepath = os.path.join(root, filename) logging.info('Adding {0}...'.format(filename, output)) subdmi = DMI(filepath) subdmi.loadAll() if subdmi.icon_height != 32 or subdmi.icon_width != 32: logging.warn( 'Skipping {0} - Invalid icon size.'.format(filepath)) changes = 0 for state_name in subdmi.states: if state_name in dmi.states: logging.warn( 'Skipping state {0}:{1} - State exists.'.format( filepath, subdmi.states[state_name].displayName())) continue dmi.states[state_name] = subdmi.states[state_name] changes += 1 logging.info('Added {0} states.'.format(changes)) # save logging.info('Saving {0} states to {1}...'.format(len(dmi.states), output)) dmi.save(output)
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())
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)
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)
def buildDMI(directory, output): dmi = DMI(output) logging.info('Creating {0}...'.format(output)) for root, _, files in os.walk(directory): for filename in files: if filename.endswith('.dmi') and not filename.endswith('.new.dmi'): filepath = os.path.join(root, filename) logging.info('Adding {0}...'.format(filename, output)) subdmi = DMI(filepath) subdmi.loadAll() if subdmi.icon_height != 32 or subdmi.icon_width != 32: logging.warn('Skipping {0} - Invalid icon size.'.format(filepath)) changes = 0 for state_name in subdmi.states: if state_name in dmi.states: logging.warn('Skipping state {0}:{1} - State exists.'.format(filepath, subdmi.states[state_name].displayName())) continue dmi.states[state_name] = subdmi.states[state_name] changes += 1 logging.info('Added {0} states.'.format(changes)) # save logging.info('Saving {0} states to {1}...'.format(len(dmi.states), output)) dmi.save(output)
def makeDMI(): dmi = DMI('snowfx.dmi') # LAYER 1 state_name = 'snowlayer1' state = State(state_name) state.dirs = 1 state.frames = 31 state.icons = animate_layer(Image.open('snow1.png'), layer1_op, 31) # Add state to DMI dmi.states[state_name] = state # LAYER 2 state_name = 'snowlayer2' state = State(state_name) state.dirs = 1 state.frames = 15 state.icons = animate_layer(Image.open('snow2.png'), layer2_op, 15) # Add state to DMI dmi.states[state_name] = state #save dmi.save('snowfx.dmi', sort=False)
def makeDMI(): dmi = DMI('snowfx.dmi') # LAYER 1 state_name='snowlayer1' state=State(state_name) state.dirs=1 state.frames=31 state.icons=animate_layer(Image.open('snow1.png'),layer1_op,31) # Add state to DMI dmi.states[state_name]=state # LAYER 2 state_name='snowlayer2' state=State(state_name) state.dirs=1 state.frames=15 state.icons=animate_layer(Image.open('snow2.png'),layer2_op,15) # Add state to DMI dmi.states[state_name]=state #save dmi.save('snowfx.dmi', sort=False)
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')
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.loadAll() 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(mine[state].displayName(), mine[state].ToString()) o += '\n + {0}: {1}'.format(theirs[state].displayName(), theirs[state].ToString()) elif kwargs.get('check_changed',True): diff_count=0 for i in xrange(len(theirs[state].icons)): theirF = theirs[state].icons[i] myF = theirs[state].icons[i] theirData = list(theirF.getdata()) myData = list(myF.getdata()) #diff = [] for i in xrange(len(theirData)): dr = theirData[i][0] - myData[i][0] dg = theirData[i][1] - myData[i][1] db = theirData[i][2] - myData[i][2] #diff[idx] = (abs(dr), abs(dg), abs(db)) if((dr != 0) or (dg != 0) or (db != 0)): diff_count += 1 break if diff_count > 0: o += '\n ! {0}: {1} frames differ'.format(theirs[state].displayName(), diff_count) if new2mine is not None: new2mine.states[state] = theirsDMI.states[state] if new2theirs is not None: new2theirs.states[state] = mineDMI.states[state] 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)
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')