예제 #1
0
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])
예제 #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)