Ignore:
Timestamp:
05/13/09 09:54:25 (11 years ago)
Author:
maximinus_parpg
Message:

All code now PEP-8 standard, with spaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PARPG/utilities/gfxsplit.py

    r52 r67  
    2525 
    2626class TileImage: 
    27     def __init__(self,picture,name): 
    28         self.image=picture 
    29         self.filename=name 
     27    def __init__(self, picture, name): 
     28        self.image = picture 
     29        self.filename = name 
    3030 
    3131def writeXML(name): 
     
    3535    # TODO: this code will not work on windows 
    3636    # strip off the png part and replace with the XML 
    37     filename=name.split('/')[-1] 
    38     x_file=open(name[:-4]+".xml","wt") 
     37    filename = name.split('/')[-1] 
     38    x_file = open(name[:-4]+".xml","wt") 
    3939    x_file.write('''<?fife type="object"?>\n''') 
    4040    x_file.write('''<object id="''') 
     
    5252       Returns True if it worked""" 
    5353    # files is a list of TileImages 
    54     complete=[] 
     54    complete = [] 
    5555    for i in files: 
    5656        try: 
    57             pygame.image.save(i.image,i.filename) 
     57            pygame.image.save(i.image, i.filename) 
    5858            # output the XML file as well 
    5959            writeXML(i.filename) 
     
    6161            print "Error: Failed to save",filename 
    6262            # if we saved some anyway, then tell the user 
    63             if(complete!=[]): 
     63            if(complete != []): 
    6464                print "  Managed to save", 
    6565                for name in complete: 
     
    7171    return True 
    7272             
    73 def splitImage(image,filename): 
     73def splitImage(image, filename): 
    7474    """Quite complex this, as there are many differing layouts on the 
    7575       hexes that we could be dealing with. However, for now we assume 
    7676       that we blit from left to right, with the image x position increasing 
    7777       by one and the y value staying the same (on the grid map)""" 
    78     xpos=0 
    79     file_counter=0 
    80     tiles=[] 
    81     height=image.get_height() 
     78    xpos = 0 
     79    file_counter = 0 
     80    tiles = [] 
     81    height = image.get_height() 
    8282    while(xpos<image.get_width()): 
    8383        # create a new surface the same height as the original but 
    8484        # with a width of TILE_WIDTH, and with per-pixel alpha 
    85         new_surface=pygame.Surface((TILE_WIDTH,height),pygame.SRCALPHA,32) 
     85        new_surface = pygame.Surface((TILE_WIDTH, height),pygame.SRCALPHA,32) 
    8686        # now blit a strip of the image across 
    87         if(xpos==0): 
    88             new_surface.blit(image,(0,0),pygame.Rect(0,0,TILE_WIDTH,height)) 
     87        if(xpos == 0): 
     88            new_surface.blit(image,(0,0), 
     89                             pygame.Rect(0,0, TILE_WIDTH, height)) 
    8990            # on the first time around, move ahead by the width of a tile 
    90             xpos+=TILE_WIDTH 
     91            xpos += TILE_WIDTH 
    9192        else: 
    9293            # we need to offset into halfway through the tile on other blits 
    93             new_surface.blit(image,((TILE_WIDTH/2)-1,0), 
    94                 pygame.Rect(xpos,0,TILE_WIDTH/2,height)) 
    95             xpos+=(TILE_WIDTH/2) 
     94            new_surface.blit(image, ((TILE_WIDTH/2)-1, 0), 
     95                pygame.Rect(xpos, 0, TILE_WIDTH/2, height)) 
     96            xpos += (TILE_WIDTH/2) 
    9697        # store the image for later 
    9798        tiles.append(TileImage(new_surface, 
    98             filename+chr(ord('a')+file_counter)+".png")) 
    99         file_counter+=1 
     99            filename + chr(ord('a')+file_counter) + ".png")) 
     100        file_counter += 1 
    100101    return tiles 
    101102             
     
    114115    images=splitImage(image,filename[:-4]) 
    115116    # save it and we are done 
    116     if(images==[]): 
     117    if(images == []): 
    117118        # something funny happened 
    118119        print "Error: Couldn't splice given image file" 
     
    122123if __name__=="__main__": 
    123124    # check we have some options 
    124     if(len(sys.argv)<2): 
     125    if(len(sys.argv) < 2): 
    125126        sys.stderr.write("Error: No image given!\n") 
    126127        sys.exit(False) 
Note: See TracChangeset for help on using the changeset viewer.