package library.core.object;

import java.util.ArrayList;

import library.core.debug.CoreLog;
import library.core.model.CoreModel;
import library.core.model.CoreTextModel;
import library.core.screen.CoreScreen;
import library.core.view.CoreTextView;
import library.core.view.CoreView;

public class CoreTextObjectFactory {

	private CoreScreen screen;
	
	private ArrayList<CoreTextObject> createObjects;

	public CoreTextObjectFactory(CoreScreen screen){
		this.screen=screen;
		this.createObjects=new ArrayList<CoreTextObject>();
	}

	public CoreTextObject create(CoreTextModel model,CoreTextView view){

		CoreTextObject object=new CoreTextObject(model, view);
		screen.addTextView(view);
		
		this.createObjects.add(object);

		return object;
	}
	
	/**
	 * オブジェクト削除
	 * @param object
	 */
	public void delete(CoreTextObject object){
		this.screen.deleteTextView(object.getView());
		this.createObjects.remove(object);
		object=null;
	}
	
	public void deleteAll(){
		int objectSize=createObjects.size();
		
		//たぶんこれで全部消える
		for(int i=objectSize-1;i>-1;i--){
			this.delete(createObjects.get(i));
		}
	}
	
	/**
	 * オブジェクトの削除　（モデルデータを基に削除）
	 * @param model
	 */
	public void delete(CoreTextModel model){
		CoreTextObject o=null;
		
		for(int i=0;i<createObjects.size();i++){
			if(createObjects.get(i).getModel().equals(model)){
				o=createObjects.get(i);
			}
		}
		
		if(o==null){
			CoreLog.error("null desu");
			return ;
		}
		
		this.delete(o);
		
		
	}
}
