Ignore:
Timestamp:
04/30/09 02:10:48 (11 years ago)
Author:
maximinus_parpg
Message:

/utilities/gfxsplit.py now writes xml files as well.
Adjusted file structure for building objects.
Converted building1 to use split tile gfxs.
Looks ugly but it's a start.

File:
1 edited

Legend:

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

    r47 r49  
    2929        self.filename=name 
    3030 
    31 def SaveFiles(files): 
     31def writeXML(name): 
     32    """Write the XML file as well 
     33       Always the same small file so we do it automatically""" 
     34    # we need to strip off the entire path up to the last 
     35    # TODO: this code will not work on windows 
     36    # strip off the png part and replace with the XML 
     37    filename=name.split('/')[-1] 
     38    x_file=open(name[:-4]+".xml","wt") 
     39    x_file.write('''<?fife type="object"?>\n''') 
     40    x_file.write('''<object id="''') 
     41    x_file.write(filename[:-4]) 
     42    x_file.write('''" namespace="PARPG" blocking="1" static="1">\n''') 
     43    x_file.write('''    <image source="''') 
     44    x_file.write(filename) 
     45    x_file.write('''" direction="0" />\n''') 
     46    # the \n\n is ESSENTIAL otherwise the XML parser in FIFE craps out! 
     47    x_file.write('''</object>\n\n''') 
     48    x_file.close 
     49 
     50def saveFiles(files): 
    3251    """Given a list of TileImages, output them as seperate files 
    3352       Returns True if it worked""" 
     
    3756        try: 
    3857            pygame.image.save(i.image,i.filename) 
     58            # output the XML file as well 
     59            writeXML(i.filename) 
    3960        except: 
    4061            print "Error: Failed to save",filename 
     
    5071    return True 
    5172             
    52 def SplitImage(image,filename): 
     73def splitImage(image,filename): 
    5374    """Quite complex this, as there are many differing layouts on the 
    5475       hexes that we could be dealing with. However, for now we assume 
     
    7495            xpos+=(TILE_WIDTH/2) 
    7596        # store the image for later 
    76         tiles.append(TileImage(new_surface,filename+str(file_counter)+".png")) 
     97        tiles.append(TileImage(new_surface, 
     98            filename+chr(ord('a')+file_counter)+".png")) 
    7799        file_counter+=1 
    78100    return tiles 
    79101             
    80 def ConvertFiles(filename): 
     102def convertFiles(filename): 
    81103    """Take a file, slice into seperate images and then save these new images 
    82104       as filename0, filename1 ... filenameN 
     
    90112    # split into seperate files 
    91113    # the [:-4] is used to split off the .png from the filename 
    92     images=SplitImage(image,filename[:-4]) 
     114    images=splitImage(image,filename[:-4]) 
    93115    # save it and we are done 
    94116    if(images==[]): 
     
    96118        print "Error: Couldn't splice given image file" 
    97119        return False 
    98     return(SaveFiles(images)) 
     120    return(saveFiles(images)) 
    99121 
    100122if __name__=="__main__": 
     
    105127    # ok, so init pygame and do it 
    106128    pygame.init() 
    107     sys.exit(ConvertFiles(sys.argv[1])) 
     129    sys.exit(convertFiles(sys.argv[1])) 
    108130 
Note: See TracChangeset for help on using the changeset viewer.