package macampcorp.macamp.game;

import android.app.Activity;

import java.io.Serializable;
import java.util.HashMap;

/**
 * Created by ptitcois on 18/08/16.
 * Cette classe gère les differentes ressources
 */
public class ResourceManager implements Serializable{
    protected HashMap<String, Resource> mResources = new HashMap<String, Resource>();
    protected Resource mLatestResource = null;
    protected static ResourceManager sThis = null;

    private ResourceManager()
    {
    }

    public static ResourceManager newInstance()
    {
        return sThis=new ResourceManager();
    }

    public void setInstance(){ sThis=this;}

    public static ResourceManager getInstance()
    {
        if(sThis==null) return newInstance();
        return sThis;
    }

    public void addResource(String name, Activity act)
    {
        Resource r = new Resource(name, act);
        mResources.put(name, r);
    }

    public boolean contains(String name){return mResources.containsKey(name);}

    public Resource get(String name)
    {
        return mResources.get(name);
    }

    public int count()
    {
        return mResources.keySet().size();
    }

    public String[] getResourceList()
    {
        Object[] x = mResources.keySet().toArray();
        String[] s = new String[mResources.size()];
        for(int i=0; i<mResources.size(); i++)
            s[i]=(String) x[i];

        return s;
    }


}
