package org.studiorailgun.sim.config.creature;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.studiorailgun.FileUtils;

/**
 * Manages all the creature definitions
 */
public class CreatureDefManager {
    
    /**
     * Path to the root folder
     */
    static final String ROOT_FOLDER_PATH = "./data/sim/creature";

    /**
     * Map of creature definition name -> creature definition
     */
    Map<String,CreatureDef> definitions = new HashMap<String,CreatureDef>();

    /**
     * The list of creatures that build civilizations
     */
    List<CreatureDef> civBuilders = new LinkedList<CreatureDef>();

    /**
     * Loads the location def manager
     * @return The location def manager
     */
    public static CreatureDefManager loadManager(){
        CreatureDefManager rVal = new CreatureDefManager();

        File dir = new File(ROOT_FOLDER_PATH);
        for(File defFile : dir.listFiles()){
            CreatureDef defn = FileUtils.loadObjectFromFile(defFile, CreatureDef.class);
            rVal.addDefinition(defn);
        }

        return rVal;
    }

    /**
     * Adds a location definition to the manager
     * @param file
     */
    public void addDefinition(CreatureDef file){
        definitions.put(file.getName(), file);
    }

    /**
     * Gets the location file by its name
     * @param name The name of the location
     * @return The definition if it exists, null otherwise
     */
    public CreatureDef getDefinition(String name){
        return definitions.get(name);
    }

    /**
     * Gets the collection of all creature definitions
     * @return The collection of all creature definitions
     */
    public Collection<CreatureDef> getDefinitions(){
        return definitions.values();
    }

    

}
