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-b93c2d0d6712master
parent
ac1bf8fc2f
commit
955cd7a531
|
@ -3,13 +3,13 @@
|
||||||
<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.gameobject.AttributeListUtils;
|
|
||||||
import net.sf.gridarta.gameobject.GameObject;
|
|
||||||
import net.sf.gridarta.gui.shrinkmapsizedialog.ShrinkMapSizeUtils;
|
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.MapModel;
|
||||||
import net.sf.gridarta.map.mapmodel.MapSquare;
|
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) {
|
void normalizeGameObject(GameObject gameObject) {
|
||||||
Iterator it = gameObject.iterator();
|
Iterator it = gameObject.iterator();
|
||||||
|
@ -23,9 +23,10 @@ void normalizeGameObject(GameObject gameObject) {
|
||||||
void normalizeMap(File mapFile, String mapPath) {
|
void normalizeMap(File mapFile, String mapPath) {
|
||||||
print(mapPath);
|
print(mapPath);
|
||||||
|
|
||||||
|
try {
|
||||||
map = mapManager.openMapFile(mapFile, false);
|
map = mapManager.openMapFile(mapFile, false);
|
||||||
if (map == null) {
|
} catch (IOException ex) {
|
||||||
print("Cannot load map file");
|
print("Cannot load map '"+mapFile+"': "+ex.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +39,10 @@ void normalizeMap(File mapFile, String mapPath) {
|
||||||
&& !mapPath.startsWith("/editor/walls")) {
|
&& !mapPath.startsWith("/editor/walls")) {
|
||||||
mapArchObject = mapModel.getMapArchObject();
|
mapArchObject = mapModel.getMapArchObject();
|
||||||
int shrinkFlags = 0;
|
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;
|
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;
|
shrinkFlags |= ShrinkMapSizeUtils.SHRINK_SOUTH;
|
||||||
}
|
}
|
||||||
ShrinkMapSizeUtils.shrinkMap(mapModel, shrinkFlags);
|
ShrinkMapSizeUtils.shrinkMap(mapModel, shrinkFlags);
|
||||||
|
@ -79,10 +80,24 @@ String rootDirectory = mapDefaultFolder + baseDirectory;
|
||||||
Iterator it = new RecursiveFileIterator(new File(rootDirectory));
|
Iterator it = new RecursiveFileIterator(new File(rootDirectory));
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
File file = it.next();
|
File file = it.next();
|
||||||
|
String name = file.getName();
|
||||||
|
String path = file.getPath();
|
||||||
if (file.isFile()
|
if (file.isFile()
|
||||||
&& file.getPath().startsWith(rootDirectory)
|
&& path.startsWith(rootDirectory)
|
||||||
&& !file.getName().equalsIgnoreCase("README")
|
&& !name.equalsIgnoreCase("README")
|
||||||
&& !file.getName().endsWith(".msg")) {
|
&& !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()));
|
normalizeMap(file, file.getPath().substring(mapDefaultFolder.length()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue