package engine;

import java.util.Map;
import javafx.scene.input.KeyEvent;
import util.reflection.Reflection;
import authoringEnvironment.GameManager;
import engine.element.Game;
import engine.element.sprites.Sprite;


/**
 * This class contains the main game loop which runs the game and updates the Scene. The constructor
 * is given an ObservableList of nodes in the scene, as well as a list of the towers, enemies and
 * map created by the authoring environment. A new version of this class must be created by the
 * player whenever a new game is loaded. The player calls this class when it loads a new game, and
 * this class then runs the game.
 * 
 * @author Qian Wang
 */

public class GameController {
    /**
     * Holds an instance of an entire game
     */
    Game myGame;

    public GameController () throws InsufficientParametersException {
        myGame = new Game();
    }

    /**
     * Given a location of a game file, the {@link GameManager#loadGame(String)} method if called,
     * which generates a map of objects names to the parameters which those objects should contain.
     * Those objects are then instantiated and their parameter lists are set.
     * 
     * @param filepath String of location of the game file
     */
    public void loadGame (String filepath) {
        Map<String, Map<String, Object>> allDataObjects = GameManager.loadGame(filepath);

        for (String s : allDataObjects.keySet()) {
            Sprite currentObject = (Sprite) Reflection.createInstance(s);
            currentObject.setParameterMap(allDataObjects.get(s));
            // allObjects.add(currentObject);
            // TODO need way to load objects into correct classes, like Layout and Wave
        }
    }

    // Will handle hotkeys
    public void handleKeyInput (KeyEvent k) {

    }

}

@@ -10,16 +10,42 @@
 ngine;%0A%0A
+import java.util.HashMap;%0A
 import j
@@ -170,16 +170,61 @@
 anager;%0A
+import authoringEnvironment.InstanceManager;%0A
 import e
@@ -855,105 +855,852 @@
 me;%0A
-%0A    public GameController () throws InsufficientParametersException %7B%0A        myGame = new Game(
+    /**%0A     * Holds a map of a part name to the package to use to reflect%0A     */%0A    Map%3CString, String%3E myPartTypeToPackage = new HashMap%3C%3E();%0A%0A    public GameController () %7B%0A        myGame = new Game();%0A        myPartTypeToPackage.put(%22Tower%22, %22engine.element.sprites.Tower%22);%0A        myPartTypeToPackage.put(%22Enemy%22, %22engine.element.sprites.Enemy%22);%0A        myPartTypeToPackage.put(%22Projectile%22, %22engine.element.sprites.Projectile%22);%0A        myPartTypeToPackage.put(%22GridCell%22, %22engine.element.sprites.GridCell%22);%0A        myPartTypeToPackage.put(%22Game%22, %22engine.element.Game%22);%0A        myPartTypeToPackage.put(%22Level%22, %22engine.element.Level%22);%0A        myPartTypeToPackage.put(%22Round%22, %22engine.element.Round%22);%0A        myPartTypeToPackage.put(%22Wave%22, %22engine.element.Wave%22);%0A        myPartTypeToPackage.put(%22Layout%22, %22engine.element.Layout%22
 );%0A 
@@ -2248,24 +2248,160 @@
 keySet()) %7B%0A
+//            String partType = part.get(InstanceManager.partTypeKey);%0A            String packageLocation = myPartTypeToPackage.get(s);%0A
             

Add map of part type to package location