package de.samdev.absgdx.framework.tmxloader;

import java.util.ArrayList;
import java.util.HashMap;

public class TileMapData {
	
	public static final long GID_MASK = 0x3fffffff;
	
	// Map data fields 
	
	public String name;
	public int height, width;
	public int tilewidth, tileheight;
	public String orientation;
	
	public ArrayList<TileSet> tilesets;
	public ArrayList<TMXObject> objects;
	public ArrayList<Layer> layers;

	static class TileSet{
		public String name;
		
		public int firstGID;
		public int tileWidth, tileHeight;
		
		public String ImageFilename;
		public int imageWidth, imageHeight;
		
		// HashMap<GID, Properties<String, String>>
		public HashMap<String, HashMap<String, String>> properties;		
	}
	
	static class Layer{
		/*
		  Holds the tile placement data for a layer of the tilemap
		 */
		
		public String name;
		
		public long[][] tiles;
		public int width, height;
		public double opacity;
		
		HashMap<String, String> properties;
		
	}
	
	static class TMXObject{
		String name;
		String type;
		int x, y;
		int width, height;
		
		String objectGroup;
	}
	
	public long getGIDAt(int x, int y){
		return ((layers.get(0).tiles[x][y]) & GID_MASK);
	}
	
	public long getGIDAt(int x, int y, int layerIndex)
	{
		return((layers.get(layerIndex).tiles[y][x]) & GID_MASK);
		
	}
	
	public Long getLocalID(long GID){
		long currentFirstGID;
		for(int i = tilesets.size() - 1; i >= 0; i--){
			currentFirstGID = tilesets.get(i).firstGID;
			if(currentFirstGID <= GID) return new Long(GID - currentFirstGID);
		}
		return null;
		
	}
	
	public Integer getTileSetIndex(long GID){
		long currentFirstGID;
		for(int i = tilesets.size() - 1; i >= 0; i--){
			currentFirstGID = tilesets.get(i).firstGID;
			if(currentFirstGID <= GID) return new Integer(i);
		}
		return null;
		
	}
	
	public Integer getLayerIndex(String name){
		for(int i = 0; i < layers.size(); i++){
			if(layers.get(i).name.equals(name)) return new Integer(i);
		}
		return null;
	}
	
	
	public TileMapData(){
		tilesets = new ArrayList<TileSet>();
		objects = new ArrayList<TMXObject>();
		layers = new ArrayList<Layer>();
	}
	
}

@@ -1585,32 +1585,35 @@
 ndex(long GID)%7B%0A
+%09%09%0A
 %09%09long currentFi
@@ -1612,32 +1612,32 @@
 urrentFirstGID;%0A
-
 %09%09for(int i = ti
@@ -1788,32 +1788,260 @@
 n null;%0A%09%09%0A%09%7D%0A%09%0A
+%09public Integer getTileSetIndex(String name)%7B%0A%09%09// get the index of a tileset by name%0A%09%09%0A%09%09for(int i = tilesets.size() -1; i %3E= 0; i--)%7B%0A%09%09%09if(name.equals(tilesets.get(i).name)) return new Integer(i);%0A%09%09%7D%0A%09%09%0A%09%09return null;%0A%09%7D%0A%09%0A
 %09public Integer 
@@ -2068,16 +2068,54 @@
  name)%7B%0A
+%09%09// get the index of a layer by name%0A
 %09%09for(in

edit class TileMapData