Run 'Shrink Map Size' function from MapNormalizer editor script.

git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@9175 282e977c-c81d-0410-88c4-b93c2d0d6712
master
akirschbaum 2008-05-30 06:23:54 +00:00
parent 981fa64822
commit 7af382aba0
1 changed files with 52 additions and 36 deletions

View File

@ -1,42 +1,58 @@
<?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.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.getGlobalSettings().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()));
}
}
<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 = mainControl.getMapManager().openMapFile(mapFile, false);
if (map == null) {
print("Cannot load map file");
return;
}
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();
}
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.getGlobalSettings().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>