package org.studiorailgun.sim.space.gen;

import org.studiorailgun.Globals;
import org.studiorailgun.sim.config.space.RegionDefinitionFile;
import org.studiorailgun.sim.space.Region;

/**
 * Generates a region
 */
public class RegionGenerator {
    
    /**
     * Generates a region
     * @param type The type of the region
     * @return The region
     */
    public static Region generate(String type){
        Region rVal = new Region();
        RegionDefinitionFile def = Globals.config.getRegionDefinitionManager().getDefinition(type);

        //generate all mandatory child region types
        if(def.getChildrenMandatory() != null){
            for(String childType : def.getChildrenMandatory()){
                Region child = RegionGenerator.generate(childType);
                rVal.addChild(child);
            }
        } else if(def.getDiscoverables() != null){
            String locType = def.getDiscoverables().get(0);
            rVal.addLocation(LocationGenerator.generate(locType));
        }

        return rVal;
    }

}
