package main.java.engine;

import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import jgame.impl.JGEngineInterface;
import main.java.engine.factories.TowerFactory;
import main.java.engine.map.TDMap;

import java.io.InputStream;
import java.io.InputStreamReader;

public class Model {
    public static final String RESOURCE_PATH = "/main/resources/";

    private JGEngineInterface engine;
    private TowerFactory towerFactory;
    private Gson gsonParser;

    public Model() {
        this.towerFactory = new TowerFactory(engine);
        this.gsonParser = new Gson();
    }

    public void setEngine(JGEngineInterface engine) {
        this.engine = engine;
        this.towerFactory = new TowerFactory(engine);
    }

    public void placeTower(double x, double y) {
        towerFactory.placeTower(x, y);
    }

    /**
     * Loads a map/terrain into the engine.
     *
     * @param fileName The name of the file which contains the map information
     */
    public void loadMap(String fileName) {
        try {
            JsonReader reader = new JsonReader(new InputStreamReader(getClass().getResourceAsStream(RESOURCE_PATH + fileName)));

            TDMap map = gsonParser.fromJson(reader, TDMap.class);
            map.loadIntoGame(engine);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    /**
     * Loads a wave spawn schema into the model
     *
     * @param fileName The name of the JSON file containing wave spawn schema info
     */
    public void loadWaveSpawnSchema(String fileName) {
        try {
            JsonReader reader = new JsonReader(new InputStreamReader(getClass().getResourceAsStream(RESOURCE_PATH + fileName)));
            TDMap map = gsonParser.fromJson(reader, TDMap.class);
            //TODO: load state 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

@@ -210,16 +210,69 @@
 p.TDMap;
+%0Aimport main.java.engine.spawnschema.WaveSpawnSchema;
 %0A%0Aimport
@@ -522,16 +522,57 @@
 nParser;
+%0A    private WaveSpawnSchema currentWave;
 %0A%0A    pu
@@ -1808,33 +1808,47 @@
             
-TDMap map
+WaveSpawnSchema newWave
  = gsonParse
@@ -1858,37 +1858,47 @@
 romJson(reader, 
-TDMap
+WaveSpawnSchema
 .class);%0A       
@@ -1906,102 +1906,334 @@
     
-//TODO: load state %0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D
+%0A          //TODO: set up wave # -%3E wave schema map object%0A            currentWave = newWave; %0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A    %0A    /**%0A     *  Spawns a new wave.%0A     */%0A    public void spawnNextWave() %7B%0A    %09currentWave.spawn();%0A    %09//TODO: keep track of wave# state .. 
 %0A   

Fix loadWaveSpawnSchema in Model