Ignore:
Timestamp:
10/19/09 02:09:01 (10 years ago)
Author:
Kaydeth_parpg
Message:

Ticket #120. Patch by beliar and Kaydeth. Added some new lines and indentation to the map editor so the saved file is more readable and looks more like it used to when it was created by hand. comments[s:trac, t:120]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/editor/savers.py

    r317 r335  
    3838        } 
    3939        self.map_element = Element('map', attrib) 
    40  
     40        self.map_element.text = "\n\t" 
     41        self.map_element.tail = "\n" 
    4142        # serialize FIFE details 
    4243        self.write_imports(import_list) 
     
    4445        self.write_cameras() 
    4546 
     47        # add newlines to the elements 
     48#        for subElement in self.map_element: 
     49#            subElement.tail = "\n" 
    4650        # finally write out the XML file 
    4751        file(self.filepath, 'w').write( 
    48             """<?xml version="1.0" encoding="ascii"?>%s\n""" 
     52            """<?xml version="1.0" encoding="ascii"?>\n%s""" 
    4953                % (tostring(self.map_element),)) 
    5054 
     
    7983    def write_import(self, filename): 
    8084        """Write an import filename""" 
    81         self.map_element.append(Element('import', { 'file': filename })) 
     85        import_element = Element('import', { 'file': filename }) 
     86        import_element.tail = "\n\t" 
     87        self.map_element.append(import_element) 
    8288 
    8389    def write_import_dir(import_dir): 
    8490        """Write an import dir""" 
    85         self.map_element.append(Element('import', { 'dir': import_dir })) 
     91        import_dir_element = Element('import', { 'dir': import_dir }) 
     92        import_dir_element.tail = "\n" 
     93        self.map_element.append(import_dir_element) 
    8694 
    8795    def write_layers(self): 
     
    101109            } 
    102110            layer_element = SubElement(self.map_element, 'layer', attrib) 
     111            layer_element.text = "\n\t\t" 
     112            layer_element.tail = "\n\n\t" 
    103113            self.write_instances(layer_element, layer) 
    104114 
     
    106116        """Write out the instances in a layer""" 
    107117        instances_element = SubElement(layer_element, 'instances') 
     118        instances_element.text = "\n\t\t\t" 
     119        instances_element.tail = "\n\t" 
    108120        for inst in layer.getInstances(): 
    109121            position = inst.getLocationRef().getExactLayerCoordinates() 
     
    136148                del attrib['type'] 
    137149 
    138             instances_element.append(Element('i', attrib)) 
     150            inst_element = Element('i', attrib) 
     151            inst_element.tail = "\n\t\t\t" 
     152            instances_element.append(inst_element) 
    139153 
    140154    def write_cameras(self): 
     
    159173            if viewport != self.engine.getRenderBackend().getArea(): 
    160174                attrib['viewport'] = '%d,%d,%d,%d' % (viewport.x, viewport.y, viewport.w, viewport.h) 
    161             self.map_element.append(Element('camera', attrib)) 
     175                 
     176            camera_element = Element('camera', attrib) 
     177            camera_element.tail = "\n" 
     178            self.map_element.append(camera_element) 
    162179 
    163180    def pathing_val_to_str(self, val): 
Note: See TracChangeset for help on using the changeset viewer.