class State(Directive): ''' Tells the compiler to create a state with the specified variables and frames. ''' ''' The actual state ''' state = None imports = [] def __init__(self, name, params): Directive.__init__(self, name, params) self.state = State() if params.len != 2: raise Exception( 'state directive requires 2 parameters. state "name" { }') self.state.name = params[0] for o in params[1]: if type(o) is Variable and o.name in directly_assignable: if o.name == 'dirs': if o.value == 'CARDINAL': o.value = 4 elif o.value == 'ALL': o.value = 8 else: o.value = 1 setattr(self.state, o.name, directly_assignable[o.name](o.value)) if type(o) is Import: if o.ftype == 'pngs': for dirblock in o.filedef: for i in range(dirblock.frames.len): self.state.setFrame(dirblock.dir, i, dirblock.frames[i])
class State(Directive): ''' Tells the compiler to create a state with the specified variables and frames. ''' ''' The actual state ''' state = None imports = [] def __init__(self,name,params): Directive.__init__(self,name,params) self.state=State() if params.len != 2: raise Exception('state directive requires 2 parameters. state "name" { }') self.state.name=params[0] for o in params[1]: if type(o) is Variable and o.name in directly_assignable: if o.name == 'dirs': if o.value == 'CARDINAL': o.value = 4 elif o.value == 'ALL': o.value = 8 else: o.value = 1 setattr(self.state,o.name,directly_assignable[o.name](o.value)) if type(o) is Import: if o.ftype == 'pngs': for dirblock in o.filedef: for i in range(dirblock.frames.len): self.state.setFrame(dirblock.dir, i, dirblock.frames[i])
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 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 __init__(self, name, params): Directive.__init__(self, name, params) self.state = State() if params.len != 2: raise Exception( 'state directive requires 2 parameters. state "name" { }') self.state.name = params[0] for o in params[1]: if type(o) is Variable and o.name in directly_assignable: if o.name == 'dirs': if o.value == 'CARDINAL': o.value = 4 elif o.value == 'ALL': o.value = 8 else: o.value = 1 setattr(self.state, o.name, directly_assignable[o.name](o.value)) if type(o) is Import: if o.ftype == 'pngs': for dirblock in o.filedef: for i in range(dirblock.frames.len): self.state.setFrame(dirblock.dir, i, dirblock.frames[i])
def __init__(self,name,params): Directive.__init__(self,name,params) self.state=State() if params.len != 2: raise Exception('state directive requires 2 parameters. state "name" { }') self.state.name=params[0] for o in params[1]: if type(o) is Variable and o.name in directly_assignable: if o.name == 'dirs': if o.value == 'CARDINAL': o.value = 4 elif o.value == 'ALL': o.value = 8 else: o.value = 1 setattr(self.state,o.name,directly_assignable[o.name](o.value)) if type(o) is Import: if o.ftype == 'pngs': for dirblock in o.filedef: for i in range(dirblock.frames.len): self.state.setFrame(dirblock.dir, i, dirblock.frames[i])
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)
nfloors = DMI('nfloors.dmi') for tileName,tileDef in tileDefs.items(): base = floors.getFrame(tileDef['base'],directions.SOUTH,0) for color in tileDef['colors']: for arrangement in tileDef['arrangements']: arrname='' arrange=[False,False,False,False] if isinstance(arrangement,str): arrange=arrangements[arrangement] 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))
for tileName, tileDef in tileDefs.items(): base = floors.getFrame(tileDef['base'], directions.SOUTH, 0) for color in tileDef['colors']: for arrangement in tileDef['arrangements']: arrname = '' arrange = [False, False, False, False] if isinstance(arrangement, str): arrange = arrangements[arrangement] 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))