160 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			XML
		
	
	
			
		
		
	
	
			160 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			XML
		
	
	
| <?xml version="1.0" encoding="UTF-8"?>
 | |
| <script>
 | |
|   <name>MapValidator</name>
 | |
|   <code><![CDATA[import java.io.BufferedWriter;
 | |
| import java.io.File;
 | |
| import java.io.FileWriter;
 | |
| import java.util.Iterator;
 | |
| import net.sf.gridarta.model.gameobject.GameObject;
 | |
| import net.sf.gridarta.model.io.RecursiveFileIterator;
 | |
| import net.sf.gridarta.model.validation.ErrorCollector;
 | |
| import net.sf.gridarta.model.validation.errors.ValidationError;
 | |
| 
 | |
| void log(String message) {
 | |
|     print(message);
 | |
|     if (logFile != null) {
 | |
|         logFile.write(message);
 | |
|         logFile.write('\n');
 | |
|     }
 | |
| }
 | |
| 
 | |
| void checkMap(File mapFile, String mapPath) {
 | |
|     try {
 | |
|         map = mapManager.openMapFile(mapFile, false);
 | |
|     } catch (IOException ex) {
 | |
|         print("Cannot load map '"+mapFile+"': "+ex.getMessage());
 | |
|         return;
 | |
|     }
 | |
|     if (map == null) {
 | |
|         log(mapPath + ":");
 | |
|         log("- cannot load map file");
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     ErrorCollector errorCollector;
 | |
|     try {
 | |
|         try {
 | |
|             validators.validateAll(map.getMapModel());
 | |
|         } finally {
 | |
|             errorCollector = map.getMapModel().getErrors();
 | |
|         }
 | |
|     } finally {
 | |
|         mapManager.release(map);
 | |
|     }
 | |
| 
 | |
|     StringBuffer sb = new StringBuffer();
 | |
|     int numberOfErrors = 0;
 | |
|     Iterator it = errorCollector.iterator();
 | |
|     while (it.hasNext()) {
 | |
|         ValidationError validationError = it.next();
 | |
| 
 | |
|         if (errorLimit > 0 && numberOfErrors >= errorLimit) {
 | |
|             log("- <skipping more errors>");
 | |
|             break;
 | |
|         }
 | |
| 
 | |
|         if (numberOfErrors == 0) {
 | |
|             log(mapPath + ":");
 | |
|         }
 | |
|         numberOfErrors++;
 | |
| 
 | |
|         sb.setLength(0);
 | |
|         sb.append("- ");
 | |
| 
 | |
|         sb.append(validationError);
 | |
| 
 | |
|         Iterator it2 = validationError.getGameObjects().iterator();
 | |
|         while (it2.hasNext()) {
 | |
|             GameObject gameObject = it2.next();
 | |
|             sb.append(" [").append(gameObject.getBestName()).append(']');
 | |
|         }
 | |
| 
 | |
|         String parameter0 = validationError.getParameter(0);
 | |
|         if (parameter0 != null) {
 | |
|             sb.append(" [").append(parameter0);
 | |
|             String parameter1 = validationError.getParameter(1);
 | |
|             if (parameter1 != null) {
 | |
|                 sb.append(", ").append(parameter1);
 | |
|             }
 | |
|             sb.append(']');
 | |
|         }
 | |
| 
 | |
|         log(sb.toString());
 | |
|     }
 | |
| }
 | |
| 
 | |
| Writer logFile = logFilename.length() <= 0 ? null : new BufferedWriter(new FileWriter(logFilename));
 | |
| try {
 | |
|     if (baseDirectory == null || baseDirectory.length() <= 0) {
 | |
|         baseDirectory = "/";
 | |
|     }
 | |
|     log("Checking maps below " + baseDirectory + "...");
 | |
|     if (baseDirectory.endsWith("/")) {
 | |
|         baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
 | |
|     }
 | |
| 
 | |
|     String mapDefaultFolder = globalSettings.getMapsDirectory().getPath();
 | |
|     String rootDirectory = mapDefaultFolder + baseDirectory;
 | |
|     Iterator it = new RecursiveFileIterator(new File(rootDirectory));
 | |
|     while (it.hasNext()) {
 | |
|         File file = it.next();
 | |
|         String name = file.getName();
 | |
|         String path = file.getPath();
 | |
|         if (file.isFile()
 | |
|         && path.startsWith(rootDirectory)
 | |
|         && !name.equalsIgnoreCase("README")
 | |
|         && !name.endsWith(".animation")
 | |
|         && !name.endsWith(".msg")
 | |
|         && !name.endsWith(".png")
 | |
|         && !name.endsWith(".ppm")
 | |
|         && !name.endsWith(".py")
 | |
|         && !name.endsWith(".pyc")
 | |
|         && !name.endsWith(".quests")
 | |
|         && !name.endsWith(".txt")
 | |
|         && !name.endsWith(".zip")
 | |
|         && !name.equals("pshop_copier")
 | |
|         && !name.equals("pshops_changelog")
 | |
|         && !name.equals(".emergency")
 | |
|         && !name.equals("ChangeLog")
 | |
|         && !name.equals("COPYING")
 | |
|         && !name.equals("TODO")
 | |
|         && !path.contains("/Info/")
 | |
|         && !path.contains("/editor/scripts/")) {
 | |
|             checkMap(file, file.getPath().substring(mapDefaultFolder.length()));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     log("Done.");
 | |
| } finally {
 | |
|     if (logFile != null) {
 | |
|         logFile.close();
 | |
|     }
 | |
| }]]></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>
 | |
|   <parameter>
 | |
|     <name>errorLimit</name>
 | |
|     <description>Maximum number of errors to show for each map; 0=show all errors</description>
 | |
|     <type>java.lang.Integer</type>
 | |
|     <value>20</value>
 | |
|     <minimum>0</minimum>
 | |
|     <maximum>2147483647</maximum>
 | |
|   </parameter>
 | |
|   <parameter>
 | |
|     <name>logFilename</name>
 | |
|     <description>Copy errors to this file; empty=no copy to file</description>
 | |
|     <type>java.lang.String</type>
 | |
|     <value />
 | |
|   </parameter>
 | |
| </script>
 | |
| 
 |