package app.brest.utils;

import android.app.Activity;
import android.content.res.Resources;
import android.util.Log;

import java.io.Serializable;
import java.util.ArrayList;

import app.brest.utils.app.brest.game.Game;
import app.brest.utils.app.brest.game.Resource;
import min3d.core.Object3d;
import min3d.core.Object3dContainer;
import min3d.parser.IParser;
import min3d.parser.Parser;

/**
 * Created by ptitcois on 18/08/16.
 */
public class ResourceManager implements Serializable{
    protected ArrayList<Resource> mAllResources = new ArrayList<Resource>();
    protected ArrayList< ArrayList<Resource> > mResourcesAquiered  = new ArrayList<ArrayList<Resource> >();
    protected ArrayList<Resource> mResourcesLeft  = new ArrayList<Resource>();

    public ResourceManager(Game g, Activity act)
    {
        mAllResources = g.getAllResources(act);
    }

    public Resource getResourceLeftByName(String name)
    {
        for(int i=0; i<mResourcesLeft.size(); i++)
        {
            if(mResourcesLeft.get(i).getName()==name)
                return mResourcesLeft.get(i);
        }
        return null;
    }

    public void nextStage(int stage)
    {
        mResourcesAquiered.add(new ArrayList<Resource>());
        mResourcesLeft.clear();
        for(int i=0; i<mAllResources.size(); i++)
            if(mAllResources.get(i).getStage()==stage)
                mResourcesLeft.add(mAllResources.get(i));
    }

    public boolean pickUpResource(String name)
    {
        for(int i=0; i<mResourcesLeft.size(); i++)
        {
            if(mResourcesLeft.get(i).getName()==name)
            {
                mResourcesAquiered.get(mResourcesAquiered.size()-1).add(mResourcesLeft.get(i));
                mResourcesLeft.remove(i);
                return true;
            }
        }
        return false;
    }

    public ArrayList<Resource> getResourceLeft()
    {
        return mResourcesLeft;
    }

    public ArrayList<Resource> getResourceAquiered(int stage)
    {
        return mResourcesAquiered.get(stage-1);
    }


    public ArrayList< ArrayList<Resource> > getResourceAquiered()
    {
        return mResourcesAquiered;
    }


    public void deleteAll3DModel()
    {
        for(int i=0; i<mAllResources.size(); i++)
            mAllResources.get(i).delete3DModel();
    }

}
