75 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			XML
		
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			XML
		
	
	
| <?xml version="1.0" encoding="UTF-8"?>
 | |
| <script>
 | |
|   <name>MapNormalizer</name>
 | |
|   <code><![CDATA[import java.io.File;
 | |
| import java.util.Iterator;
 | |
| import net.sf.gridarta.CommonConstants;
 | |
| import net.sf.gridarta.io.RecursiveFileIterator;
 | |
| import net.sf.gridarta.map.ShrinkMapSizeUtils;
 | |
| 
 | |
| void normalizeMap(File mapFile, String mapPath) {
 | |
|     print(mapPath);
 | |
| 
 | |
|     map = mapManager.openMapFile(mapFile, false);
 | |
|     if (map == null) {
 | |
|         print("Cannot load map file");
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     try {
 | |
|         if (!mapPath.startsWith("/styles")
 | |
|         && !mapPath.startsWith("/editor")) {
 | |
|             mapModel = map.getMapModel();
 | |
|             mapArchObject = mapModel.getMapArchObject();
 | |
|             int shrinkFlags = 0;
 | |
|             if (mapArchObject.getTilePath(CommonConstants.NORTH).length() <= 0 && mapArchObject.getTilePath(CommonConstants.SOUTH).length() <= 0) {
 | |
|                 shrinkFlags |= ShrinkMapSizeUtils.SHRINK_EAST;
 | |
|             }
 | |
|             if (mapArchObject.getTilePath(CommonConstants.EAST).length() <= 0 && mapArchObject.getTilePath(CommonConstants.WEST).length() <= 0) {
 | |
|                 shrinkFlags |= ShrinkMapSizeUtils.SHRINK_SOUTH;
 | |
|             }
 | |
|             ShrinkMapSizeUtils.shrinkMap(mapModel, shrinkFlags);
 | |
|         }
 | |
| 
 | |
|         map.save();
 | |
|     } finally {
 | |
|         mapManager.release(map);
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (baseDirectory == null || baseDirectory.length() <= 0) {
 | |
|     baseDirectory = "/";
 | |
| }
 | |
| print("Normalizing maps below " + baseDirectory + "...");
 | |
| if (baseDirectory.endsWith("/")) {
 | |
|     baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
 | |
| }
 | |
| 
 | |
| String mapDefaultFolder = globalSettings.getMapDefaultFolder();
 | |
| String rootDirectory = mapDefaultFolder + baseDirectory;
 | |
| Iterator it = new RecursiveFileIterator(new File(rootDirectory));
 | |
| while (it.hasNext()) {
 | |
|     File file = it.next();
 | |
|     if (file.isFile()
 | |
|     && file.getPath().startsWith(rootDirectory)
 | |
|     && !file.getName().equalsIgnoreCase("README")
 | |
|     && !file.getName().endsWith(".msg")) {
 | |
|         normalizeMap(file, file.getPath().substring(mapDefaultFolder.length()));
 | |
|     }
 | |
| }
 | |
| 
 | |
| print("Done.");]]></code>
 | |
|   <mode>
 | |
|     <autoboot>false</autoboot>
 | |
|     <bash>true</bash>
 | |
|     <filter>false</filter>
 | |
|   </mode>
 | |
|   <parameter>
 | |
|     <name>baseDirectory</name>
 | |
|     <description>Base Directory</description>
 | |
|     <type>java.lang.String</type>
 | |
|     <value>/</value>
 | |
|   </parameter>
 | |
| </script>
 | |
| 
 |