package engine;

import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import exceptions.GameObjectException;

public abstract class GameObject {
	private transient ResourceBundle resources;
	private List<Parameter> params;
	private Entity entity;
	private transient ResourceBundle gameObjectExceptions = ResourceBundle.getBundle("resources/GameObjectExceptions");
	private GameInfo info;

	public GameObject(String name) {
		resources = ResourceBundle.getBundle("resources/" + name);
		params = new ArrayList<Parameter>();
	}

	public String getDisplayName() {
		return resources.getString(getClass().getSimpleName().toString());
	}

	public String getDisplayDescription() {
		return resources.getString(getClass().getSimpleName() + "Description");
	}

	public List<Parameter> getParams() {
		return params;
	}

	public void addParam(Parameter param) {
		params.add(param);
	}

	public void updateParam(String name, Object value) {
		findParameter(name).setObject(value);
	}

	public void setParams(List<Parameter> params) {
		this.params = params;
	}

	public Object getParam(String name) {
		return findParameter(name).getObject();
	}

	public void setEntity(Entity entity) {
		this.entity = entity;
	}

	public Entity getEntity() {
		return entity;
	}

	private Parameter findParameter(String name) {
		try {
			for (Parameter param : params) {
				if (param.getName().equals(name))
					return param;
			}
		} catch (Exception e) {
			throw new GameObjectException(gameObjectExceptions.getString("NoParameter"));
		}
		return null;
	}
	
	public GameInfo getGameInfo(){
		return this.info;
	}
	public void setGameInfo(GameInfo info){
		this.info = info;
	}
	
	public GameObject getInstance(){
		try {
			return getClass().getConstructor().newInstance();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	public GameObject clone(){
		GameObject copy = getInstance();
		copy.setGameInfo(getGameInfo());
		List<Parameter> params = new ArrayList<Parameter>();
		params.addAll(getParams());
		copy.setParams(params);
		return copy;
	}
}

@@ -93,16 +93,52 @@
 eBundle;
+%0Aimport java.util.stream.Collectors;
 %0A%0Aimport
@@ -1596,25 +1596,24 @@
 rn null;%0A%09%7D%0A
-%09
 %0A%09public Gam
@@ -1631,16 +1631,17 @@
 meInfo()
+ 
 %7B%0A%09%09retu
@@ -1653,24 +1653,25 @@
 is.info;%0A%09%7D%0A
+%0A
 %09public void
@@ -1697,16 +1697,17 @@
 fo info)
+ 
 %7B%0A%09%09this
@@ -1723,17 +1723,16 @@
 nfo;%0A%09%7D%0A
-%09
 %0A%09public
@@ -1756,16 +1756,17 @@
 stance()
+ 
 %7B%0A%09%09try 
@@ -1931,16 +1931,17 @@
 %0A%09%09%7D%0A%09%7D%0A
+%0A
 %09public 
@@ -1958,16 +1958,17 @@
  clone()
+ 
 %7B%0A%09%09Game
@@ -2086,16 +2086,17 @@
 ter%3E();%0A
+%0A
 %09%09params
@@ -2114,16 +2114,146 @@
 Params()
+.stream().map(s -%3E %7B%0A%09%09%09return new Parameter(s.getName(), s.getParameterClass(), s.getObject());%0A%09%09%7D).collect(Collectors.toList())
 );%0A%09%09cop

fix issue on cloning