package de.heatup.mapengine;

import java.awt.Point;
import java.util.ArrayList;

import de.heatup.cfg.Config;
import de.heatup.objects.StaticObject;

public class MapObjectHandler {
	
	private static final int singleTileWidth = Config.singleTilePixels;
	
	private static ArrayList<StaticObject> allMapObjects = new ArrayList<StaticObject>();
	private static ArrayList<StaticObject> allWallObjects = new ArrayList<StaticObject>();
	private static ArrayList<StaticObject> allWayObjects = new ArrayList<StaticObject>();
	private static ArrayList<StaticObject> allHardwareObjects = new ArrayList<StaticObject>();
	private static ArrayList<StaticObject> allHardwareTriggerObjects = new ArrayList<StaticObject>();
	
	protected static ArrayList<StaticObject> getAllMapObjects(MapEngine me) {
		createAllMapObjectsArrayList(me);
		return allMapObjects;
	}
	protected static void createAllMapObjectsArrayList(MapEngine me) {
		addAllWallsAndWaysTiles(me);
		addAllHardwareTiles(me);
	}
	protected static void addAllHardwareTiles(MapEngine me) {
		for (int i = 0; i<me.getAvailableHardwareTileTypes().size(); i++) {
			char currentType = me.getAvailableHardwareTileTypes().get(i);
			ArrayList<Point> allPointsOfCurrentType = me.getAllCoordinatesOfTileType(currentType);
			Point firstPoint = allPointsOfCurrentType.get(0);
			Point lastPoint = allPointsOfCurrentType.get(allPointsOfCurrentType.size()-1);

			int currentTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth;
			int currentTilesTotalHeight = lastPoint.y-firstPoint.y+singleTileWidth;
			
			StaticObject newStaticObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight);
			MapObjectHandler.allMapObjects.add(newStaticObject);
			MapObjectHandler.allHardwareObjects.add(newStaticObject);
		}
	}
	protected static void addAllWallsAndWaysTiles(MapEngine me) {
		ArrayList<Point> allCoordinatesOfWayTileType = me.getAllCoordinatesOfTileType(Config.wayChar);
		ArrayList<Point> allCoordinatesOfWallTileType = me.getAllCoordinatesOfTileType(Config.wallChar);
		
		for (int i = 0; i < allCoordinatesOfWayTileType.size(); i++) {
			Point currentPoint = allCoordinatesOfWayTileType.get(i);
			StaticObject newStaticObject = new StaticObject(Config.wayChar, currentPoint);
			MapObjectHandler.allMapObjects.add(newStaticObject);
			MapObjectHandler.allWayObjects.add(newStaticObject);
		}
		for (int i = 0; i < allCoordinatesOfWallTileType.size(); i++) {
			Point currentPoint = allCoordinatesOfWallTileType.get(i);
			StaticObject newStaticObject = new StaticObject(Config.wallChar, currentPoint);
			MapObjectHandler.allMapObjects.add(newStaticObject);
			MapObjectHandler.allWallObjects.add(newStaticObject);
		}
	}
	protected static ArrayList<StaticObject> getAllHardwareObjects() {
		return allHardwareObjects;
	}
	protected static ArrayList<StaticObject> getAllWallObjects() {
		return allWallObjects;
	}
	protected static ArrayList<StaticObject> getAllWayObjects() {
		return allWayObjects;
	}
	protected static ArrayList<StaticObject> getAllHardwareTriggerObjects() {
		return allHardwareTriggerObjects;
	}
}
