package org.freerealm.tile;
import java.util.HashMap;
import java.util.Iterator;
import org.freerealm.ModifierImpl;
import org.freerealm.property.Property;
import org.freerealm.property.SetMovementCost;
/**
*
* @author Deniz ARIKAN
*/
public class TileModifierImpl extends ModifierImpl implements TileModifier {
private HashMap<Integer, TileType> tileTypes;
public TileModifierImpl() {
tileTypes = new HashMap<Integer, TileType>();
}
public boolean hasTileType(TileType tileType) {
return getTileTypes().containsKey(tileType.getId());
}
public void addTileType(TileType tileType) {
getTileTypes().put(tileType.getId(), tileType);
}
public void removeTileType(TileType tileType) {
getTileTypes().remove(tileType.getId());
}
public int getTileTypeCount() {
return getTileTypes().size();
}
public Iterator<TileType> getTileTypesIterator() {
return getTileTypes().values().iterator();
}
public float getMovementCost() {
float movementCost = 0;
Iterator<Property> propertyEditor = getPropertiesIterator();
while (propertyEditor.hasNext()) {
Property property = propertyEditor.next();
if (property instanceof SetMovementCost) {
SetMovementCost setMovementCost = (SetMovementCost) property;
if (movementCost == 0 || setMovementCost.getMovementCost() < movementCost) {
movementCost = setMovementCost.getMovementCost();
}
}
}
return movementCost;
}
private HashMap<Integer, TileType> getTileTypes() {
return tileTypes;
}
}