Shorten scripts by using Gridarta's RecursiveFileIterator class.
git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@8468 282e977c-c81d-0410-88c4-b93c2d0d6712master
parent
96e85af174
commit
0d692a4f17
|
@ -2,14 +2,12 @@
|
|||
<script>
|
||||
<name>LegacySpellConverter</name>
|
||||
<code><![CDATA[import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import net.sf.gridarta.gameobject.ArchetypeParser;
|
||||
import net.sf.gridarta.gameobject.ArchetypeSet;
|
||||
import net.sf.gridarta.gameobject.GameObject;
|
||||
import net.sf.gridarta.io.RecursiveFileIterator;
|
||||
import net.sf.gridarta.map.MapSquare;
|
||||
import net.sf.gridarta.map.validation.ErrorCollector;
|
||||
import net.sf.gridarta.map.validation.ValidationError;
|
||||
|
||||
int countMapFiles = 0;
|
||||
int countSpellObjects = 0;
|
||||
|
@ -303,29 +301,6 @@ void convertMap(File mapFile, String mapPath) {
|
|||
}
|
||||
}
|
||||
|
||||
void convertDirectory(File mapFile, String mapPath) {
|
||||
File[] files = mapFile.listFiles();
|
||||
if (files == null) {
|
||||
print("Cannot read directory " + mapFile);
|
||||
return;
|
||||
}
|
||||
Arrays.sort(files);
|
||||
for (File file : files) {
|
||||
String name = file.getName();
|
||||
if (!name.equals(".svn") && !name.equals("README")) {
|
||||
convertMaps(file, mapPath + "/" + file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void convertMaps(File mapFile, String mapPath) {
|
||||
if (mapFile.isDirectory()) {
|
||||
convertDirectory(mapFile, mapPath);
|
||||
} else if (mapFile.isFile()) {
|
||||
convertMap(mapFile, mapPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (baseDirectory == null || baseDirectory.length() <= 0) {
|
||||
baseDirectory = "/";
|
||||
}
|
||||
|
@ -334,7 +309,17 @@ if (baseDirectory.endsWith("/")) {
|
|||
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
|
||||
}
|
||||
|
||||
convertMaps(new File(mainControl.getMapDefaultFolder() + baseDirectory), baseDirectory);
|
||||
String mapDefaultFolder = mainControl.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")) {
|
||||
convertMap(file, file.getPath().substring(mapDefaultFolder.length()));
|
||||
}
|
||||
}
|
||||
|
||||
print("Done. Created " + countSpellObjects + " spell objects in " + countMapFiles + " map files.");]]></code>
|
||||
<mode>
|
||||
|
|
|
@ -1,58 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<script>
|
||||
<name>MapNormalizer</name>
|
||||
<code><![CDATA[import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import net.sf.gridarta.gameobject.GameObject;
|
||||
import net.sf.gridarta.map.validation.ErrorCollector;
|
||||
import net.sf.gridarta.map.validation.ValidationError;
|
||||
|
||||
void normalizeMap(File mapFile, String mapPath) {
|
||||
print(mapPath);
|
||||
|
||||
map = mainControl.getMapManager().openMapFile(mapFile, false);
|
||||
if (map == null) {
|
||||
print("Cannot load map file");
|
||||
return;
|
||||
}
|
||||
|
||||
map.save();
|
||||
}
|
||||
|
||||
void normalizeDirectory(File mapFile, String mapPath) {
|
||||
File[] files = mapFile.listFiles();
|
||||
if (files == null) {
|
||||
print("Cannot read directory " + mapFile);
|
||||
return;
|
||||
}
|
||||
Arrays.sort(files);
|
||||
for (File file : files) {
|
||||
String name = file.getName();
|
||||
if (!name.equals(".svn") && !name.equals("README")) {
|
||||
normalizeMaps(file, mapPath + "/" + file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void normalizeMaps(File mapFile, String mapPath) {
|
||||
if (mapFile.isDirectory()) {
|
||||
normalizeDirectory(mapFile, mapPath);
|
||||
} else if (mapFile.isFile()) {
|
||||
normalizeMap(mapFile, mapPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (baseDirectory == null || baseDirectory.length() <= 0) {
|
||||
baseDirectory = "/";
|
||||
}
|
||||
print("Normalizing maps below " + baseDirectory + "...");
|
||||
if (baseDirectory.endsWith("/")) {
|
||||
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
|
||||
}
|
||||
|
||||
normalizeMaps(new File(mainControl.getMapDefaultFolder() + baseDirectory), baseDirectory);
|
||||
|
||||
<code><![CDATA[import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import net.sf.gridarta.io.RecursiveFileIterator;
|
||||
|
||||
void normalizeMap(File mapFile, String mapPath) {
|
||||
print(mapPath);
|
||||
|
||||
map = mainControl.getMapManager().openMapFile(mapFile, false);
|
||||
if (map == null) {
|
||||
print("Cannot load map file");
|
||||
return;
|
||||
}
|
||||
|
||||
map.save();
|
||||
}
|
||||
|
||||
if (baseDirectory == null || baseDirectory.length() <= 0) {
|
||||
baseDirectory = "/";
|
||||
}
|
||||
print("Normalizing maps below " + baseDirectory + "...");
|
||||
if (baseDirectory.endsWith("/")) {
|
||||
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
|
||||
}
|
||||
|
||||
String mapDefaultFolder = mainControl.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")) {
|
||||
normalizeMap(file, file.getPath().substring(mapDefaultFolder.length()));
|
||||
}
|
||||
}
|
||||
|
||||
print("Done.");]]></code>
|
||||
<mode>
|
||||
<autoboot>false</autoboot>
|
||||
|
|
|
@ -1,114 +1,101 @@
|
|||
<?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.Arrays;
|
||||
import java.util.Iterator;
|
||||
import net.sf.gridarta.gameobject.GameObject;
|
||||
import net.sf.gridarta.map.validation.ErrorCollector;
|
||||
import net.sf.gridarta.map.validation.ValidationError;
|
||||
|
||||
void log(String message) {
|
||||
print(message);
|
||||
if (logFile != null) {
|
||||
logFile.write(message);
|
||||
logFile.write('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void checkMap(File mapFile, String mapPath) {
|
||||
map = mainControl.getMapManager().openMapFile(mapFile, false);
|
||||
if (map == null) {
|
||||
log(mapPath + ":");
|
||||
log("- cannot load map file");
|
||||
return;
|
||||
}
|
||||
ErrorCollector errorCollector;
|
||||
try {
|
||||
errorCollector = mainControl.runMapValidation(map.getMapModel());
|
||||
} finally {
|
||||
if (map.nViews() <= 0) {
|
||||
mainControl.getMapManager().closeLevel(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);
|
||||
|
||||
GameObject gameObject = validationError.getGameObject();
|
||||
if (gameObject != null) {
|
||||
sb.append(" [").append(gameObject.getBestName()).append(']');
|
||||
}
|
||||
|
||||
String parameter = validationError.getParameter();
|
||||
if (parameter != null) {
|
||||
sb.append(" [").append(parameter).append(']');
|
||||
}
|
||||
|
||||
log(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void checkDirectory(File mapFile, String mapPath) {
|
||||
File[] files = mapFile.listFiles();
|
||||
if (files == null) {
|
||||
log("Cannot read directory " + mapFile);
|
||||
return;
|
||||
}
|
||||
Arrays.sort(files);
|
||||
for (File file : files) {
|
||||
String name = file.getName();
|
||||
if (!name.equals(".svn") && !name.equals("README")) {
|
||||
checkMaps(file, mapPath + "/" + file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkMaps(File mapFile, String mapPath) {
|
||||
if (mapFile.isDirectory()) {
|
||||
checkDirectory(mapFile, mapPath);
|
||||
} else if (mapFile.isFile()) {
|
||||
checkMap(mapFile, mapPath);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
checkMaps(new File(mainControl.getMapDefaultFolder() + baseDirectory), baseDirectory);
|
||||
|
||||
log("Done.");
|
||||
} finally {
|
||||
if (logFile != null) {
|
||||
logFile.close();
|
||||
}
|
||||
<code><![CDATA[import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Iterator;
|
||||
import net.sf.gridarta.gameobject.GameObject;
|
||||
import net.sf.gridarta.io.RecursiveFileIterator;
|
||||
import net.sf.gridarta.map.validation.ErrorCollector;
|
||||
import net.sf.gridarta.map.validation.ValidationError;
|
||||
|
||||
void log(String message) {
|
||||
print(message);
|
||||
if (logFile != null) {
|
||||
logFile.write(message);
|
||||
logFile.write('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void checkMap(File mapFile, String mapPath) {
|
||||
map = mainControl.getMapManager().openMapFile(mapFile, false);
|
||||
if (map == null) {
|
||||
log(mapPath + ":");
|
||||
log("- cannot load map file");
|
||||
return;
|
||||
}
|
||||
ErrorCollector errorCollector;
|
||||
try {
|
||||
errorCollector = mainControl.runMapValidation(map.getMapModel());
|
||||
} finally {
|
||||
if (map.nViews() <= 0) {
|
||||
mainControl.getMapManager().closeLevel(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);
|
||||
|
||||
GameObject gameObject = validationError.getGameObject();
|
||||
if (gameObject != null) {
|
||||
sb.append(" [").append(gameObject.getBestName()).append(']');
|
||||
}
|
||||
|
||||
String parameter = validationError.getParameter();
|
||||
if (parameter != null) {
|
||||
sb.append(" [").append(parameter).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 = mainControl.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")) {
|
||||
checkMap(file, file.getPath().substring(mapDefaultFolder.length()));
|
||||
}
|
||||
}
|
||||
|
||||
log("Done.");
|
||||
} finally {
|
||||
if (logFile != null) {
|
||||
logFile.close();
|
||||
}
|
||||
}]]></code>
|
||||
<mode>
|
||||
<autoboot>false</autoboot>
|
||||
|
|
Loading…
Reference in New Issue