Changeset 91


Ignore:
Timestamp:
06/05/09 06:19:56 (10 years ago)
Author:
maximinus_parpg
Message:

Big update to gfxsplit.py
It almost works now.
Added small wall section to map for testing.

Location:
trunk/PARPG
Files:
15 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/PARPG/maps/map.xml

    r62 r91  
    1010        <import file="../objects/ground/block/block.xml"></import> 
    1111        <import file="../objects/objects/crate/crate.xml"></import> 
     12        <import file="../objects/ground/misc/test.xml"></import> 
    1213        <!-- import the buildings --> 
    1314        <import file="../objects/buildings/building1/building1.xml"></import> 
    1415        <import file="../objects/buildings/building2/building2.xml"></import> 
    1516        <import file="../objects/buildings/building3/building3.xml"></import> 
     17         
     18        <!-- Import the test building --> 
     19        <import file="../objects/buildings/test-build/maximinusa.xml"></import> 
     20        <import file="../objects/buildings/test-build/maximinusb.xml"></import> 
     21        <import file="../objects/buildings/test-build/maximinusc.xml"></import> 
     22         
    1623        <!-- Import the tile transition tiles --> 
    1724        <import file="../objects/ground/grass/transition/grass-tc01.xml"></import> 
     
    10541061        <layer x_offset="0.0" pathing="cell_edges_and_diagonals" y_offset="0.0" grid_type="square" id="ObjectLayer" x_scale="1" y_scale="1" rotation="0.0"> 
    10551062                <instances> 
     1063                    <!-- Test building --> 
     1064                    <i x="3" o="maximinusa" z="0.0" y="-4" r="0"></i> 
     1065                    <i x="3" o="maximinusb" z="0.0" y="-3" r="0"></i> 
     1066                    <i x="3" o="maximinusc" z="0.0" y="-2" r="0"></i> 
     1067                     
     1068                    <!-- test to line up 
     1069                    <i x="3" o="test" z="0.0" y="-4" r="0"></i> 
     1070                    <i x="3" o="test" z="0.0" y="-3" r="0"></i> 
     1071                    <i x="3" o="maximinusc" z="0.0" y="-2" r="0"></i> --> 
     1072                 
    10561073                <i x="8.0" o="block" z="0.0" y="-12.0" r="0"></i> 
    10571074                        <i x="9.0" o="block" z="0.0" y="-12.0" r="0"></i> 
  • trunk/PARPG/objects/ground/misc/test.xml

    r49 r91  
    11<?fife type="object"?> 
    2 <object id="test" namespace="PARPG" blocking="0" static="1"> 
     2<object id="test" namespace="PARPG" blocking="1" static="1"> 
    33        <image source="test.png" direction="0" /> 
    44</object> 
  • trunk/PARPG/scripts/world.py

    r82 r91  
    203203            t = "screenshots/screen-%s-%s.png" % (date.today().strftime('%Y-%m-%d'), 
    204204                                                  time.strftime('%H-%M-%S')) 
     205            print "PARPG: Saved:",t 
    205206            self.engine.getRenderBackend().captureScreen(t) 
    206207        if(keyval == key.I): 
  • trunk/PARPG/utilities/gfxsplit.py

    r87 r91  
    2222TILE_WIDTH  =   72 
    2323TILE_HEIGHT =   36 
     24# is this is true, output a file of the pics together 
     25STITCH      =   False 
    2426 
    2527# this is very much a simple routine, but we still have a simple class 
    2628 
    2729class TileImage: 
    28     def __init__(self, picture, name): 
     30    def __init__(self, picture, name, yoff): 
    2931        self.image = picture 
    3032        self.filename = name 
     33        self.y_offset = yoff 
    3134 
    32 def writeXML(name): 
     35def writeXML(name, yoff): 
    3336    """Write the XML file as well 
    3437       Always the same small file so we do it automatically""" 
     
    4447    x_file.write('''    <image source="''') 
    4548    x_file.write(filename) 
    46     x_file.write('''" direction="0" />\n''') 
     49    x_file.write('''" direction="0"''') 
     50    x_file.write(''' y_offset="''') 
     51    x_file.write(yoff) 
     52    x_file.write('''" />\n''') 
    4753    # the \n\n is ESSENTIAL otherwise the XML parser in FIFE craps out! 
    4854    x_file.write('''</object>\n\n''') 
    4955    x_file.close 
    5056 
     57def stitchImages(files, width, height): 
     58    """Put the images together and output them to stitched.png""" 
     59    new_image=pygame.Surface((width, height), pygame.SRCALPHA, 32) 
     60    xpos = 0 
     61    for i in files: 
     62        new_image.blit(i.image, (xpos, 0)) 
     63        xpos += i.image.get_width() 
     64    pygame.image.save(new_image,"stitched.png") 
     65     
    5166def saveFiles(files): 
    5267    """Given a list of TileImages, output them as seperate files 
     
    5469    # files is a list of TileImages 
    5570    complete = [] 
     71    width = 0 
     72    height = 0 
    5673    for i in files: 
     74        width += i.image.get_width() 
     75        if(i.image.get_height() > height): 
     76            height = i.image.get_height() 
    5777        try: 
    5878            pygame.image.save(i.image, i.filename) 
    5979            # output the XML file as well 
    60             writeXML(i.filename) 
     80            writeXML(i.filename, str(i.y_offset)) 
    6181        except: 
    62             print "Error: Failed to save",filename 
     82            print "Error: Failed to save",i.filename 
    6383            # if we saved some anyway, then tell the user 
    6484            if(complete != []): 
     
    7090        complete.append(i.filename) 
    7191    # seems like all was ok 
     92    if(STITCH == True): 
     93        stitchImages(files, width, height) 
    7294    return True 
    7395             
     
    78100       by one and the y value staying the same (on the grid map)""" 
    79101    # 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         print t 
    97         if((t[1] != 0)and(last_x == True)): 
    98             # switchback, so this tile must fill the whole width 
    99             pass 
    100         if(t[1] == 0): 
    101             last_x = False 
    102             # assume +1 for now 
    103         else: 
    104             last_x = True 
    105             # assume +1 for now 
    106             ypos += TILE_HEIGHT / 2 
    107             xpos += TILE_WIDTH / 2 
    108             height += TILE_HEIGHT / 2 
    109  
     102    height = (image.get_height() / 2) + (TILE_HEIGHT / 2) 
    110103    xpos = 0 
    111104    file_counter = 0 
    112105    tiles = [] 
    113     height = image.get_height() 
    114     while(xpos<image.get_width()): 
    115         # create a new surface the same height as the original but 
    116         # with a width of TILE_WIDTH, and with per-pixel alpha 
     106    height_adjust = 0 
     107    yoff_next = -((height - TILE_HEIGHT) / 2) 
     108    for t in data: 
     109        yoff = yoff_next 
     110        if(t == 'm'): 
     111            # switchback, so this tile must fill the whole width 
     112            width += TILE_WIDTH 
     113        elif(t == 'r'): 
     114            # moving forward on the y axis 
     115            width = TILE_WIDTH / 2 
     116            height_adjust = - (TILE_HEIGHT / 2) 
     117        elif(t == 'l'): 
     118            # moving forward on the x axis 
     119            width = TILE_WIDTH / 2 
     120            height_adjust = TILE_HEIGHT / 2 
     121            yoff_next -= TILE_HEIGHT / 4 
     122        else: 
     123            # TODO: Handle integer moves (i.e. > 1 tile up down) 
     124            print "Error: Can't handle integer tile moves yet" 
     125            sys.exit(False) 
     126        # build the new surface 
    117127        new_surface = pygame.Surface((TILE_WIDTH, height), pygame.SRCALPHA, 32) 
    118128        # now blit a strip of the image across 
    119         if(xpos == 0): 
    120             new_surface.blit(image, (0, 0), 
    121                              pygame.Rect(0, 0, TILE_WIDTH, height)) 
    122             # on the first time around, move ahead by the width of a tile 
    123             xpos += TILE_WIDTH 
    124         else: 
    125             # we need to offset into halfway through the tile on other blits 
    126             new_surface.blit(image, ((TILE_WIDTH/2)-1, 0), 
    127                 pygame.Rect(xpos, 0, TILE_WIDTH/2, height)) 
    128             xpos += (TILE_WIDTH/2) 
     129        new_surface.blit(image, (0, 0), pygame.Rect(xpos, 0, width, height)) 
    129130        # store the image for later 
    130131        tiles.append(TileImage(new_surface, 
    131             filename + chr(ord('a')+file_counter) + ".png")) 
     132            filename + chr(ord('a')+file_counter) + ".png",yoff)) 
    132133        file_counter += 1 
     134        # amend variables 
     135        xpos += width 
     136        height += height_adjust 
    133137    return tiles 
    134138             
     
    140144       on the LHS MUST be in the centre of the image""" 
    141145    # first we need to ensure that the data sent is correct. split it up first 
    142     data=txt_data.split(",") 
     146    data=[] 
     147    for i in txt_data: 
     148        data.append(i) 
    143149    if(len(data) < 2): 
    144150        print "Error: Invalid tile data layout" 
    145151        return False 
    146152    # validate each data statement 
    147     ndata = [] 
    148153    for i in data: 
    149         if(((i[0] != 'x')and(i[0] != 'y'))and(i[1].isdigit()==False)): 
     154        if((i != 'l')and(i != 'r')and(i != 'm')and(i.isdigit()==False)): 
    150155            # some issue 
    151156            print "Error: Can't decode tile string structure" 
    152157            return False 
    153         else: 
    154             # make the data a bit easier to understand 
    155             if(i[0] == 'x'): 
    156                 ndata.append([int(i[1]),0]) 
    157             else: 
    158                 ndata.append([0,int(i[1])]) 
    159158    # then load the file 
    160159    try: 
     
    163162        print "Error: Couldn't load",filename 
    164163        return False         
    165     # check the length of the data, make sure it's long enough... 
    166     if((TILE_WIDTH / 2) * (len(data) + 1)>image.get_width()): 
    167         print "Error: Target GFX too narrow" 
    168         return False    
    169164    # split into seperate files 
    170165    # the [:-4] is used to split off the .png from the filename 
    171     images = splitImage(image, filename[:-4], ndata) 
     166    images = splitImage(image, filename[:-4], data) 
    172167    # save it and we are done 
    173168    if(images == []): 
     
    175170        print "Error: Couldn't splice given image file" 
    176171        return False 
    177     #return(saveFiles(images)) 
     172    return(saveFiles(images)) 
    178173 
    179174if __name__=="__main__": 
Note: See TracChangeset for help on using the changeset viewer.