*
* @param inputDir the input directory containing the tmx files (and tile sets, relative to the path listed in the tmx file)
* @param outputDir The output directory for the TMX files, <strong>should be empty before running</strong>.
* @param settings the settings used in the TexturePacker */
public void processMaps (File inputDir, File outputDir, Settings settings) throws IOException {
FileHandle inputDirHandle = new FileHandle(inputDir.getAbsolutePath());
File[] files = inputDir.listFiles(new TmxFilter());
ObjectMap<String, TiledMapTileSet> tilesetsToPack = new ObjectMap<String, TiledMapTileSet>();
for (File file : files) {
map = mapLoader.load(file.getAbsolutePath());
// if enabled, build a list of used tileids for the tileset used by this map
if (this.settings.stripUnusedTiles) {
int mapWidth = map.getProperties().get("width", Integer.class);
int mapHeight = map.getProperties().get("height", Integer.class);
int numlayers = map.getLayers().getCount();
int bucketSize = mapWidth * mapHeight * numlayers;
Iterator<MapLayer> it = map.getLayers().iterator();
while (it.hasNext()) {
MapLayer layer = it.next();
// some layers can be plain MapLayer instances (ie. object groups), just ignore them
if (layer instanceof TiledMapTileLayer) {
TiledMapTileLayer tlayer = (TiledMapTileLayer)layer;
for (int y = 0; y < mapHeight; ++y) {
for (int x = 0; x < mapWidth; ++x) {
if (tlayer.getCell(x, y) != null) {
int tileid = tlayer.getCell(x, y).getTile().getId() & ~0xE0000000;
String tilesetName = tilesetNameFromTileId(map, tileid);
IntArray usedIds = getUsedIdsBucket(tilesetName, bucketSize);
usedIds.add(tileid);
// track this tileset to be packed if not already tracked
if (!tilesetsToPack.containsKey(tilesetName)) {
tilesetsToPack.put(tilesetName, map.getTileSets().getTileSet(tilesetName));
}
}
}
}
}
}
} else {
for (TiledMapTileSet tileset : map.getTileSets()) {
String tilesetName = tileset.getName();
if (!tilesetsToPack.containsKey(tilesetName)) {
tilesetsToPack.put(tilesetName, tileset);
}
}
}
FileHandle tmxFile = new FileHandle(file.getAbsolutePath());
writeUpdatedTMX(map, outputDir, tmxFile);
}
packTilesets(tilesetsToPack, inputDirHandle, outputDir, settings);
}