1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.maps.tiled; 18 19 import java.util.Iterator; 20 import com.badlogic.gdx.maps.MapProperties; 21 import com.badlogic.gdx.utils.IntMap; 22 23 /** @brief Set of {@link TiledMapTile} instances used to compose a TiledMapLayer */ 24 public class TiledMapTileSet implements Iterable<TiledMapTile> { 25 26 private String name; 27 28 private IntMap<TiledMapTile> tiles; 29 30 private MapProperties properties; 31 32 /** @return tileset's name */ getName()33 public String getName () { 34 return name; 35 } 36 37 /** @param name new name for the tileset */ setName(String name)38 public void setName (String name) { 39 this.name = name; 40 } 41 42 /** @return tileset's properties set */ getProperties()43 public MapProperties getProperties () { 44 return properties; 45 } 46 47 /** Creates empty tileset */ TiledMapTileSet()48 public TiledMapTileSet () { 49 tiles = new IntMap<TiledMapTile>(); 50 properties = new MapProperties(); 51 } 52 53 /** Gets the {@link TiledMapTile} that has the given id. 54 * 55 * @param id the id of the {@link TiledMapTile} to retrieve. 56 * @return tile matching id, null if it doesn't exist */ getTile(int id)57 public TiledMapTile getTile (int id) { 58 return tiles.get(id); 59 } 60 61 /** @return iterator to tiles in this tileset */ 62 @Override iterator()63 public Iterator<TiledMapTile> iterator () { 64 return tiles.values().iterator(); 65 } 66 67 /** Adds or replaces tile with that id 68 * 69 * @param id the id of the {@link TiledMapTile} to add or replace. 70 * @param tile the {@link TiledMapTile} to add or replace. */ putTile(int id, TiledMapTile tile)71 public void putTile (int id, TiledMapTile tile) { 72 tiles.put(id, tile); 73 } 74 75 /** @param id tile's id to be removed */ removeTile(int id)76 public void removeTile (int id) { 77 tiles.remove(id); 78 } 79 80 /** @return the size of this TiledMapTileSet. */ size()81 public int size () { 82 return tiles.size; 83 } 84 } 85