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"?> <?xml version="1.0" encoding="UTF-8"?>
<script> <script>
<name>MapNormalizer</name> <name>MapNormalizer</name>
<code><![CDATA[import java.io.File; <code><![CDATA[import java.io.File;
import java.util.Iterator; import java.util.Iterator;
import net.sf.gridarta.io.RecursiveFileIterator; import net.sf.gridarta.CommonConstants;
import net.sf.gridarta.io.RecursiveFileIterator;
void normalizeMap(File mapFile, String mapPath) { import net.sf.gridarta.map.ShrinkMapSizeUtils;
print(mapPath);
void normalizeMap(File mapFile, String mapPath) {
map = mainControl.getMapManager().openMapFile(mapFile, false); print(mapPath);
if (map == null) {
print("Cannot load map file"); map = mainControl.getMapManager().openMapFile(mapFile, false);
return; if (map == null) {
} print("Cannot load map file");
return;
map.save(); }
}
if (!mapPath.startsWith("/styles")
if (baseDirectory == null || baseDirectory.length() <= 0) { && !mapPath.startsWith("/editor")) {
baseDirectory = "/"; mapModel = map.getMapModel();
} mapArchObject = mapModel.getMapArchObject();
print("Normalizing maps below " + baseDirectory + "..."); int shrinkFlags = 0;
if (baseDirectory.endsWith("/")) { if (mapArchObject.getTilePath(CommonConstants.NORTH).length() <= 0 && mapArchObject.getTilePath(CommonConstants.SOUTH).length() <= 0) {
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1); shrinkFlags |= ShrinkMapSizeUtils.SHRINK_EAST;
} }
if (mapArchObject.getTilePath(CommonConstants.EAST).length() <= 0 && mapArchObject.getTilePath(CommonConstants.WEST).length() <= 0) {
String mapDefaultFolder = mainControl.getGlobalSettings().getMapDefaultFolder(); shrinkFlags |= ShrinkMapSizeUtils.SHRINK_SOUTH;
String rootDirectory = mapDefaultFolder + baseDirectory; }
Iterator it = new RecursiveFileIterator(new File(rootDirectory)); ShrinkMapSizeUtils.shrinkMap(mapModel, shrinkFlags);
while (it.hasNext()) { }
File file = it.next();
if (file.isFile() map.save();
&& file.getPath().startsWith(rootDirectory) }
&& !file.getName().equalsIgnoreCase("README")) {
normalizeMap(file, file.getPath().substring(mapDefaultFolder.length())); 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> print("Done.");]]></code>
<mode> <mode>
<autoboot>false</autoboot> <autoboot>false</autoboot>