package engine.level;

import java.util.Iterator;
import java.util.List;

import authoring.model.collections.ConditionsCollection;
import authoring.model.collections.GameObjectsCollection;
import authoring.model.collections.LevelsCollection;
import engine.collisionDetection.CollisionDetector;
import engine.conditions.Condition;
import engine.render.GameObjectRenderer;
import engine.gameObject.GameObject;

/**
 * Manages the Levels, and progression of the Game
 * 
 * @author Will Chang
 * @author Abhishek Balakrishnan
 */

public class LevelManager implements Iterable<Level> {
	private LevelsCollection myLevels;
	private GameObjectsCollection myGameObjects;
	private ConditionsCollection myConditions;
	private Level myCurrentLevel;
	private int myCurrentIndex;
	private GameObjectRenderer myRenderer;
	private CollisionDetector myDetector;

	/**
	 * Constructor for a level
	 * 
	 * @param gameObjects
	 * @param levels
	 * @param conditions
	 * @param renderer
	 * @param detector
	 */
	public LevelManager(LevelsCollection levels, GameObjectsCollection gameObjects,
			ConditionsCollection conditions, GameObjectRenderer renderer,
			CollisionDetector detector) {
		myLevels = levels;
		myGameObjects = gameObjects;
		myConditions = conditions;
		myCurrentIndex = 0;
		myCurrentLevel = myLevels.get(myCurrentIndex);
		myRenderer = renderer;
		myDetector = detector;
	}

	/**
	 * Iterates through the list of Levels in the managers
	 */
	public Iterator<Level> iterator() {
		return myLevels.iterator();
	}

	/**
	 * Primitive implementation of level loop...
	 */
	public void nextLevel() {
		if (myCurrentIndex < myLevels.size() - 1) {
			myCurrentIndex += 1;
			myCurrentLevel = myLevels.get(myCurrentIndex);
		} else {
			myCurrentIndex = 0;
		}
	}

	/**
	 * Sets current Level and initializes
	 * 
	 * @param levelIndex
	 */
	public void goToLevel(int levelIndex) {
		myCurrentLevel = myLevels.get(levelIndex);
		initializeCurrentLevel();
	}

	/**
	 * Update call, updates the current level Happens every frame
	 */
	public void update() {
		myCurrentLevel.update();
		updateFrameBasedConditions();
	}

	/**
	 * update the conditions that rely on frame calculations
	 */
	private void updateFrameBasedConditions() {
		for (Condition s : myConditions) {
			s.frameElapsed();
		}
	}

	/**
	 * Initializes the Current Level
	 */
	public void initializeCurrentLevel() {
		setLevelEnabledConditions();
		myRenderer.renderGameObjects(myCurrentLevel);
	}

	/**
     * Set conditions in this level to 
     */
	private void setLevelEnabledConditions() {
		for (Iterator<String> conditionIDIterator = myCurrentLevel.getConditionIDsIterator(); conditionIDIterator
				.hasNext();) {
			String conditionID = conditionIDIterator.next();
			
//			for (Iterator<Condition> conditionIterator = myConditions.iterator() )
			/*
			 * find the condition in myConditions specified by this conditionID
			 * and set it enabled
			 */
		}
	}
	
	/**
	 * 
	 */

}

@@ -516,16 +516,43 @@
 rishnan%0A
+ * @author Eli Lichtenberg%0A
  */%0A%0Apub
@@ -1060,17 +1060,20 @@
  levels,
- 
+%0A%09%09%09
 GameObje
@@ -1098,20 +1098,17 @@
 Objects,
-%0A%09%09%09
+ 
 Conditio
@@ -1131,17 +1131,20 @@
 ditions,
- 
+%0A%09%09%09
 GameObje
@@ -1163,20 +1163,17 @@
 enderer,
-%0A%09%09%09
+ 
 Collisio
@@ -2491,18 +2491,29 @@
 /**%0A
-     * Set
+%09 * Enable or disable
  con
@@ -2524,30 +2524,25 @@
 ons 
-in this level to %0A    
+on myConditions%0A%09
  */%0A
@@ -2645,16 +2645,21 @@
 entLevel
+%0A%09%09%09%09
 .getCond
@@ -2697,21 +2697,16 @@
 Iterator
-%0A%09%09%09%09
 .hasNext
@@ -2772,10 +2772,8 @@
 %09%09%09%0A
-//
 %09%09%09f
@@ -2828,16 +2828,22 @@
 nditions
+%0A%09%09%09%09%09
 .iterato
@@ -2849,31 +2849,55 @@
 or()
- )%0A%09%09%09/*%0A%09%09%09 * find the
+; conditionIterator.hasNext();) %7B%0A%09%09%09%09Condition
  con
@@ -2907,22 +2907,19 @@
 ion 
-in myC
+= c
 ondition
 s sp
@@ -2918,27 +2918,53 @@
 tion
-s specified by this
+Iterator.next();%0A%09%09%09%09if (condition.getID() ==
  con
@@ -2975,40 +2975,47 @@
 onID
+)
 %0A%09%09%09
- * and set it enabled
+%09%09condition.setEnabled(true);
 %0A%09%09%09
- */
+%7D
 %0A%09%09%7D
@@ -3029,17 +3029,40 @@
 /**%0A%09 * 
+Disable all conditions
 %0A%09 */%0A
+%09
 %0A%7D%0A

enable and disable conditions