Changeset 84


Ignore:
Timestamp:
06/03/09 10:01:35 (10 years ago)
Author:
maximinus_parpg
Message:

Amended gfxsplit.py
Added test gfx

Location:
trunk/PARPG/utilities
Files:
2 added
1 edited

Legend:

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

    r81 r84  
    2121 
    2222TILE_WIDTH  =   72 
     23TILE_HEIGHT =   36 
    2324 
    2425# this is very much a simple routine, but we still have a simple class 
     
    7172    return True 
    7273             
    73 def splitImage(image, filename): 
     74def splitImage(image, filename, data): 
    7475    """Quite complex this, as there are many differing layouts on the 
    75        hexes that we could be dealing with. However, for now we assume 
    76        that we blit from left to right, with the image x position increasing 
     76       hexes that we could be dealing with. We blit from left to right 
     77       data holds the hex position changes in [x,y] format. 
    7778       by one and the y value staying the same (on the grid map)""" 
     79    # the starting point for the grab is always the middle of the image 
     80    # + half a tile height 
     81    ypos = (image.get_height() / 2) + (TILE_HEIGHT / 2) 
     82    # you only ever grab half 
     83    width = TILE_WIDTH / 2 
     84    # the height is the rest of the image 
     85    height = image.get_height() - ypos 
     86    # and xpos is logical 
     87    xpos = 0 
     88    tiles = [] 
     89    new_surface = pygame.Surface((TILE_WIDTH, height), pygame.SRCALPHA, 32) 
     90    new_surface.blit(image, (0, 0), pygame.Rect(0, 0, width, height)) 
     91    tiles.append(new_surface) 
     92    xpos += TILE_WIDTH / 2 
     93    last_x = True 
     94    x_offset = 0 
     95    for t in data: 
     96        if((t[1] != 0)and(last_x=True)): 
     97            # switchback, so this tile must fill the whole width 
     98        if(t[1] == 0): 
     99            last_x = False 
     100            # assume +1 for now 
     101        else: 
     102            last_x = True 
     103            # assume +1 for now 
     104            ypos += TILE_HEIGHT / 2 
     105            xpos += TILE_WIDTH / 2 
     106            height += TILE_HEIGHT / 2 
     107 
    78108    xpos = 0 
    79109    file_counter = 0 
     
    83113        # create a new surface the same height as the original but 
    84114        # with a width of TILE_WIDTH, and with per-pixel alpha 
    85         new_surface = pygame.Surface((TILE_WIDTH, height),pygame.SRCALPHA,32) 
     115        new_surface = pygame.Surface((TILE_WIDTH, height), pygame.SRCALPHA, 32) 
    86116        # now blit a strip of the image across 
    87117        if(xpos == 0): 
    88             new_surface.blit(image,(0,0), 
    89                              pygame.Rect(0,0, TILE_WIDTH, height)) 
     118            new_surface.blit(image, (0, 0), 
     119                             pygame.Rect(0, 0, TILE_WIDTH, height)) 
    90120            # on the first time around, move ahead by the width of a tile 
    91121            xpos += TILE_WIDTH 
     
    112142        print "Error: Invalid tile data layout" 
    113143        return False 
    114      
    115144    # validate each data statement 
     145    ndata = [] 
    116146    for i in data: 
    117         print i 
    118      
    119     print "sdfsdf" 
    120      
    121     return True 
    122      
    123     print "sdfsdf" 
    124      
    125     # check the length of the data 
    126     length=(TILE_WIDTH / 2) * (len(data) + 1) 
     147        if(((i[0] != 'x')and(i[0] != 'y'))and(i[1].isdigit()==False)): 
     148            # some issue 
     149            print "Error: Can't decode tile string structure" 
     150            return False 
     151        else: 
     152            # make the data a bit easier to understand 
     153            if(i[0] == 'x'): 
     154                ndata.append(int(i[1]),0) 
     155            else: 
     156                ndata.append(0,int(i[1])) 
    127157    # then load the file 
    128158    try: 
    129         image=pygame.image.load(filename) 
     159        image = pygame.image.load(filename) 
    130160    except(pygame.error): 
    131161        print "Error: Couldn't load",filename 
    132         return False 
     162        return False         
     163    # check the length of the data, make sure it's long enough... 
     164    if((TILE_WIDTH / 2) * (len(data) + 1)>image.get_width)): 
     165        print "Error: Target GFX too narrow" 
     166        return False    
    133167    # split into seperate files 
    134168    # the [:-4] is used to split off the .png from the filename 
    135     images=splitImage(image,filename[:-4]) 
     169    images = splitImage(image, filename[:-4], txt_data) 
    136170    # save it and we are done 
    137171    if(images == []): 
     
    139173        print "Error: Couldn't splice given image file" 
    140174        return False 
    141     return(saveFiles(images)) 
     175    #return(saveFiles(images)) 
    142176 
    143177if __name__=="__main__": 
Note: See TracChangeset for help on using the changeset viewer.