package controller;

import java.util.ResourceBundle;
import engine.GameEngine;
import gameFactory.GameFactory;
import parser.ParseGame;
import stage.Game;
import reflection.Reflection;

public class DataController {
	public static final String DEFAULT_RESOURCE_PACKAGE = "engineResources/";
	public static final String DEFAULT_CREATEORMODIFY = "CreationOrModify";
	public static final String IS_CREATION = "Creation";
	
	protected Game myGame;
    protected int currentLevelID;
    protected int currentSceneID;
	protected GameFactory myFactory;
	protected ParseGame myParser;
	protected GameEngine myGameEngine;
	protected ResourceBundle myCreateModifyTeller;
	
	public DataController(){
		myParser = new ParseGame();
		myGame = new Game();
		myGameEngine = new GameEngine();
		myFactory = new GameFactory(myGameEngine);
		currentLevelID = 0;
		currentSceneID = 0;
		myCreateModifyTeller = ResourceBundle.getBundle(DEFAULT_RESOURCE_PACKAGE + DEFAULT_CREATEORMODIFY);
	}
	
	/*
	 * Called by Game Authorizing Environment to send the command String
	 * Input is a String order
	 */
	public void receiveOrder(String order){
		String[] orders = order.split(",");
		String methodName = myCreateModifyTeller.getString(orders[0]);
		Reflection.callMethod(this, methodName, order);	
	}
	
	/*
	 * Called by Game Authorizing Environment to export the game data
	 * Input is a url to the XML file created by the GAE
	 */
	public void exportXML(String url){
		//myParser.writeToFile(myGame, url);
	}
	
	/*
	 * Called by PlayView to import the game data
	 * Input is a url to the XML file loaded by PlayView
	 */
	public void readXML(String url){
		//Game game = myParser.readFromFile(url);
	}
	
	
	protected void callFactoryToProcess(String order){
		//myFactory.processOrder(myGame, currentLevelID, currentSceneID, order);
	}
	
	protected void switchToScene(String order){
		String[] orders = order.split(",");
		currentSceneID = Integer.parseInt(orders[2]);
	}
	
	protected void switchToLevel(String order){
		String[] orders = order.split(",");
		currentLevelID = Integer.parseInt(orders[2]);
	}
}

@@ -14,16 +14,39 @@
 oller;%0A%0A
+import java.util.List;%0A
 import j
@@ -70,16 +70,17 @@
 Bundle;%0A
+%0A
 import e
@@ -1466,18 +1466,16 @@
 url)%7B%0A%09%09
-//
 myParser
@@ -1656,19 +1656,27 @@
 %7B%0A%09%09
-//Game game
+List%3CString%3E orders
  = m
@@ -1698,24 +1698,81 @@
 mFile(url);%0A
+%09%09for(String order: orders)%7B%0A%09%09%09receiveOrder(order);%0A%09%09%7D%0A
 %09%7D%0A%09%0A%09%0A%09prot
@@ -1822,12 +1822,10 @@
 r)%7B%0A
+
 %09%09
-//
 myFa

modify DataController