Adapt MapNormalizer plugin script to current Gridarta.

git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@13384 282e977c-c81d-0410-88c4-b93c2d0d6712
master
akirschbaum 2010-06-12 15:05:15 +00:00
parent ac1bf8fc2f
commit 955cd7a531
1 changed files with 27 additions and 12 deletions

View File

@ -3,13 +3,13 @@
<name>MapNormalizer</name>
<code><![CDATA[import java.io.File;
import java.util.Iterator;
import net.sf.gridarta.gameobject.AttributeListUtils;
import net.sf.gridarta.gameobject.GameObject;
import net.sf.gridarta.gui.shrinkmapsizedialog.ShrinkMapSizeUtils;
import net.sf.gridarta.io.RecursiveFileIterator;
import net.sf.gridarta.map.mapmodel.MapModel;
import net.sf.gridarta.map.mapmodel.MapSquare;
import net.sf.gridarta.utils.CommonConstants;
import net.sf.gridarta.model.archetype.AttributeListUtils;
import net.sf.gridarta.model.direction.Direction;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.io.RecursiveFileIterator;
void normalizeGameObject(GameObject gameObject) {
Iterator it = gameObject.iterator();
@ -23,9 +23,10 @@ void normalizeGameObject(GameObject gameObject) {
void normalizeMap(File mapFile, String mapPath) {
print(mapPath);
map = mapManager.openMapFile(mapFile, false);
if (map == null) {
print("Cannot load map file");
try {
map = mapManager.openMapFile(mapFile, false);
} catch (IOException ex) {
print("Cannot load map '"+mapFile+"': "+ex.getMessage());
return;
}
@ -38,10 +39,10 @@ void normalizeMap(File mapFile, String mapPath) {
&& !mapPath.startsWith("/editor/walls")) {
mapArchObject = mapModel.getMapArchObject();
int shrinkFlags = 0;
if (mapArchObject.getTilePath(CommonConstants.NORTH).length() <= 0 && mapArchObject.getTilePath(CommonConstants.SOUTH).length() <= 0) {
if (mapArchObject.getTilePath(Direction.NORTH).length() <= 0 && mapArchObject.getTilePath(Direction.SOUTH).length() <= 0) {
shrinkFlags |= ShrinkMapSizeUtils.SHRINK_EAST;
}
if (mapArchObject.getTilePath(CommonConstants.EAST).length() <= 0 && mapArchObject.getTilePath(CommonConstants.WEST).length() <= 0) {
if (mapArchObject.getTilePath(Direction.EAST).length() <= 0 && mapArchObject.getTilePath(Direction.WEST).length() <= 0) {
shrinkFlags |= ShrinkMapSizeUtils.SHRINK_SOUTH;
}
ShrinkMapSizeUtils.shrinkMap(mapModel, shrinkFlags);
@ -79,10 +80,24 @@ 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()
&& file.getPath().startsWith(rootDirectory)
&& !file.getName().equalsIgnoreCase("README")
&& !file.getName().endsWith(".msg")) {
&& path.startsWith(rootDirectory)
&& !name.equalsIgnoreCase("README")
&& !name.endsWith(".msg")
&& !name.endsWith(".py")
&& !name.endsWith(".png")
&& !name.endsWith(".ppm")
&& !name.endsWith(".quests")
&& !name.endsWith(".animation")
&& !name.equals("pshop_copier")
&& !name.equals("pshop_changelog")
&& !name.equals(".emergency")
&& !name.equals("ChangeLog")
&& !name.equals("COPYING")
&& !path.contains("/Info/")
&& !path.contains("/editor/scripts/")) {
normalizeMap(file, file.getPath().substring(mapDefaultFolder.length()));
}
}