-package com.badlogic.gdx.maps.tiled;
+/*******************************************************************************\r
+ * Copyright 2011 See AUTHORS file.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ ******************************************************************************/
-import java.io.IOException;
-import java.util.StringTokenizer;
+package com.badlogic.gdx.maps.tiled;
import com.badlogic.gdx.assets.AssetDescriptor;
import com.badlogic.gdx.assets.AssetLoaderParameters;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.ImageResolver;
-import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.ImageResolver.AssetManagerImageResolver;
import com.badlogic.gdx.maps.ImageResolver.DirectImageResolver;
+import com.badlogic.gdx.maps.MapProperties;
+import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
import com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile;
import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.XmlReader;
import com.badlogic.gdx.utils.XmlReader.Element;
+import java.io.IOException;
+import java.util.StringTokenizer;
+
public class TideMapLoader extends SynchronousAssetLoader<TiledMap, TideMapLoader.Parameters> {
public static class Parameters extends AssetLoaderParameters<TiledMap> {
}
DirectImageResolver imageResolver = new DirectImageResolver(textures);
TiledMap map = loadMap(root, tideFile, imageResolver);
- map.setOwnedTextures(textures.values().toArray());
+ map.setOwnedResources(textures.values().toArray());
return map;
} catch(IOException e) {
throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
}
@Override
- public TiledMap load (AssetManager assetManager, String fileName, Parameters parameter) {
- FileHandle tideFile = resolve(fileName);
+ public TiledMap load (AssetManager assetManager, String fileName, FileHandle tideFile, Parameters parameter) {
try {
return loadMap(root, tideFile, new AssetManagerImageResolver(assetManager));
} catch (Exception e) {
}
@Override
- public Array<AssetDescriptor> getDependencies (String fileName, Parameters parameter) {
+ public Array<AssetDescriptor> getDependencies (String fileName, FileHandle tmxFile, Parameters parameter) {
Array<AssetDescriptor> dependencies = new Array<AssetDescriptor>();
try {
- FileHandle tmxFile = resolve(fileName);
root = xml.parse(tmxFile);
for(FileHandle image: loadTileSheets(root, tmxFile)) {
dependencies.add(new AssetDescriptor(image.path(), Texture.class));
int spacingY = Integer.parseInt(spacingParts[1]);
FileHandle image = getRelativeFileHandle(tideFile, imageSource);
- Texture texture = imageResolver.getImage(image.path());
+ TextureRegion texture = imageResolver.getImage(image.path());
// TODO: Actually load the tilesheet
// Need to make global ids as Tide doesn't have global ids.
tileset.getProperties().put("firstgid", firstgid);
int gid = firstgid;
- int stopWidth = texture.getWidth() - tileSizeX;
- int stopHeight = texture.getHeight() - tileSizeY;
+ int stopWidth = texture.getRegionWidth() - tileSizeX;
+ int stopHeight = texture.getRegionHeight() - tileSizeY;
for (int y = marginY; y <= stopHeight; y += tileSizeY + spacingY) {
for (int x = marginX; x <= stopWidth; x += tileSizeX + spacingX) {
TiledMapTile tile = new StaticTiledMapTile(new TextureRegion(texture, x, y, tileSizeX, tileSizeY));
+ tile.setId(gid);
tileset.putTile(gid++, tile);
}
}
- Element properties = element.getChildByName("Proeprties");
+ Element properties = element.getChildByName("Properties");
if (properties != null) {
loadProperties(tileset.getProperties(), properties);
}
int tileSizeY = Integer.parseInt(tileSizeParts[1]);
TiledMapTileLayer layer = new TiledMapTileLayer(layerSizeX, layerSizeY, tileSizeX, tileSizeY);
+ layer.setName(id);
+ layer.setVisible(visible.equalsIgnoreCase("True"));
Element tileArray = element.getChildByName("TileArray");
Array<Element> rows = tileArray.getChildrenByName("Row");
TiledMapTileSets tilesets = map.getTileSets();
String name = currentChild.getName();
if (name.equals("TileSheet")) {
currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref"));
- firstgid = currentTileSet.getProperties().getAsInteger("firstgid");
+ firstgid = currentTileSet.getProperties().get("firstgid", Integer.class);
} else if (name.equals("Null")) {
x += currentChild.getIntAttribute("Count");
} else if (name.equals("Static")) {
- layer.setCell(x++, y, currentTileSet.getTile(firstgid + currentChild.getIntAttribute("Index")));
+ Cell cell = new Cell();
+ cell.setTile(currentTileSet.getTile(firstgid + currentChild.getIntAttribute("Index")));
+ layer.setCell(x++, y, cell);
} else if (name.equals("Animated")) {
// Create an AnimatedTile
int interval = currentChild.getInt("Interval");
String frameName = frame.getName();
if (frameName.equals("TileSheet")) {
currentTileSet = tilesets.getTileSet(frame.getAttribute("Ref"));
- firstgid = currentTileSet.getProperties().getAsInteger("firstgid");
+ firstgid = currentTileSet.getProperties().get("firstgid", Integer.class);
} else if (frameName.equals("Static")) {
frameTiles.add((StaticTiledMapTile) currentTileSet.getTile(firstgid + frame.getIntAttribute("Index")));
}
}
- layer.setCell(x++, y, new AnimatedTiledMapTile(interval / 1000f, frameTiles)); //TODO: Reuse existing animated tiles
+ Cell cell = new Cell();
+ cell.setTile(new AnimatedTiledMapTile(interval / 1000f, frameTiles));
+ layer.setCell(x++, y, cell); //TODO: Reuse existing animated tiles
}
}
}
- map.getLayers().addLayer(layer);
+ map.getLayers().add(layer);
}
}
String value = property.getText();
if (type.equals("Int32")) {
-
+ properties.put(key, Integer.parseInt(value));
} else if (type.equals("String")) {
-
+ properties.put(key, value);
} else if (type.equals("Boolean")) {
-
+ properties.put(key, value.equalsIgnoreCase("true"));
} else {
properties.put(key, value);
}
return result;
}
-}
+}
\ No newline at end of file