public new void PopulateRecipeList(ArrayList importedRecipes)
        {
            // Set up a dictionary to hold the map property for each recipe
            // This has to be done before because the original function will delete the ID first otherwise,
            // making it impossible to re-associate the property with the recipe.
            var recipeMaps = new Dictionary <string, string>();

            for (var i = 0; i < importedRecipes.Count; i++)
            {
                var recipeData = importedRecipes.GetHashtable(i);
                var id         = recipeData["id"].ToString();
                if (!recipeData.ContainsKey("map"))
                {
                    continue;
                }
                recipeMaps[id] = recipeData["map"].ToString();
                recipeMaps.Remove("map");
            }

            // Import all the recipes
            orig_PopulateRecipeList(importedRecipes);

            // Add the map IDs
            foreach (var recipe in Recipes)
            {
                if (!recipeMaps.ContainsKey(recipe.Id))
                {
                    continue;
                }
                var moddedRecipe = (Recipe)recipe;
                moddedRecipe.MapId = recipeMaps[recipe.Id];
            }
        }
Example #2
0
        public new void PopulateRecipeList(ArrayList importedRecipes)
        {
            // Set up dictionaries to hold the additional properties for each recipe
            // This has to be done before because the original function will delete the ID first otherwise,
            // making it impossible to re-associate the property with the recipe.
            var recipeMaps         = new Dictionary <string, string>();
            var remoteAlternatives = new Dictionary <string, List <bool> >();

            for (var i = 0; i < importedRecipes.Count; i++)
            {
                var recipeData = importedRecipes.GetHashtable(i);
                var id         = recipeData["id"].ToString();
                if (recipeData.ContainsKey("map"))
                {
                    recipeMaps[id] = recipeData["map"].ToString();
                    recipeMaps.Remove("map");
                    recipeData.Remove("map");
                }

                if (recipeData.ContainsKey("alternativerecipes"))
                {
                    remoteAlternatives[id] = new List <bool>();
                    foreach (Hashtable ra in recipeData.GetArrayList("alternativerecipes"))
                    {
                        var isRemote = ra.GetBool("remote");
                        remoteAlternatives[id].Add(isRemote);
                        if (isRemote)
                        {
                            ra.Remove("remote");
                        }
                    }
                }
            }

            // Import all the recipes
            orig_PopulateRecipeList(importedRecipes);

            // Add the map IDs
            foreach (var recipe in Recipes)
            {
                if (recipeMaps.ContainsKey(recipe.Id))
                {
                    var moddedRecipe = recipe;
                    moddedRecipe.MapId = recipeMaps[recipe.Id];
                }

                if (remoteAlternatives.ContainsKey(recipe.Id))
                {
                    for (int i = 0; i < remoteAlternatives[recipe.Id].Count; i++)
                    {
                        recipe.AlternativeRecipes[i].Remote = remoteAlternatives[recipe.Id][i];
                    }
                }
            }
        }
Example #3
0
    private void SetupTown(Hashtable townDefinition)
    {
        // get house definitions
        ArrayList houseDefinitions = townDefinition.GetArrayList("town");

        // process each house definition
        for (int i = 0; i < houseDefinitions.Count; i++)
        {
            Hashtable houseDefinition = houseDefinitions.GetHashtable(i);

            Debug.Log("building house:" + houseDefinition.JsonString());

            // create house gameObject
            GameObject house = new GameObject(houseDefinition.GetString("name"));

            // get elements
            ArrayList elementDefinitions = houseDefinition.GetArrayList("archelements");
            for (int j = 0; j < elementDefinitions.Count; j++)
            {
                Hashtable  elementDefinition = elementDefinitions.GetHashtable(j);
                GameObject prototype         = null;
                if (elementDefinition.GetString("type") == "wall")
                {
                    prototype = wallPrototype;
                }
                else if (elementDefinition.GetString("type") == "roof")
                {
                    prototype = roofPrototype;
                }

                if (prototype != null)
                {
                    // create element
                    GameObject element = (GameObject)GameObject.Instantiate(prototype);
//					element.transform.SetParent( house.transform );
                    element.transform.parent        = house.transform;
                    element.transform.localPosition = elementDefinition.GetVector3("offset");
                    element.GetComponent <MeshRenderer>().material.color = elementDefinition.GetColor("color");
                }
            }

            // position the house
            house.transform.position = houseDefinition.GetVector3("position");

            // scale the house
            house.transform.localScale = houseDefinition.GetVector3("scale");

            // add to houses array for future access
            houses.Add(house);
        }
    }
    // Only import a specific tag
    public static Hashtable Import(string xml, string tagName, bool caseInsensitive = false)
    {
        int end = xml.Length;
        int idx = FindEndOfXmlIdentifier(xml);

        if(tagName != null && tagName.Length > 0) {
            idx = xml.IndexOf("<"+tagName, idx);
            if(idx >= 0) {
                end = xml.LastIndexOf("</"+tagName+">");
                if(end >= 0) end += 4 + tagName.Length;
            }
            if(end < idx) {
                end = xml.IndexOf("/>", idx);
                if(end >= 0) end += 3;
            }
            if(idx < 0 || end < idx) {
                Debug.Log("Tag "+tagName+" not found");
                return null;
            }
        }

        ArrayList result = new ArrayList();
        int line = 1;
        while(idx<end) {
            string key = "";
            int idxPrev = idx;
            ArrayList node = ReadNode(xml, out key, ref idx, end, ref line, caseInsensitive);
            SetPropertyValue(result, "SimpleXmlImport", key, node, caseInsensitive);
            if(idx <= idxPrev) {
                Debug.LogWarning("SimpleXmlImporter: empty node at line "+line);
                break; // little safety precaution against infinite loops
            }
        }
        if(result.Count <= 1) {
        //			Debug.Log(result.GetHashtable(0).JsonString());
            return result.GetHashtable(0);
        }
        Hashtable wrapper = new Hashtable();
        if(tagName == null || tagName.Length == 0) tagName = "SimpleXmlImport";
        wrapper[tagName] = result;
        Debug.Log(wrapper.JsonString());
        return wrapper;
    }
Example #5
0
 private static void SetPropertyValue(ArrayList parentNode, string parentKey, string key, ArrayList value, bool caseInsensitive)
 {
     if (value == null || value.Count == 0)
     {
         return;
     }
     if (value.Count == 1)
     {
         Hashtable node = value.GetHashtable(0);
         if (node.Count == 1 && node.ContainsKey(".value."))
         {
             if (key.Length <= 0)
             {
                 key = parentKey;
             }
             SetPropertyValue(parentNode, parentKey, key, node.GetString(".value."), caseInsensitive);
         }
         else
         {
             Hashtable parentFirstNode = parentNode.GetHashtable(0);
             if (parentFirstNode == null)
             {
                 parentFirstNode = new Hashtable();
                 parentNode.Add(parentFirstNode);
             }
             if (parentFirstNode.ContainsKey(key))
             {
                 if (parentFirstNode[key].GetType() == typeof(ArrayList))
                 {
                     ArrayList firstNodeList = (ArrayList)parentFirstNode[key];
                     for (int i = 0; i < firstNodeList.Count; i++)
                     {
                         if (firstNodeList[i].GetType() == typeof(Hashtable))
                         {
                             Hashtable hash = (Hashtable)firstNodeList[i];
                             if (!hash.ContainsKey(".tag."))
                             {
                                 hash[".tag."] = key;
                             }
                         }
                     }
                     node[".tag."] = key;
                     ((ArrayList)parentFirstNode[key]).Add(node);
                 }
                 else if (parentFirstNode[key].GetType() == typeof(Hashtable) && parentFirstNode.Count == 1)
                 {
                     parentNode[0] = parentFirstNode[key];
                     ((Hashtable)parentNode[0])[".tag."] = key;
                     parentFirstNode = parentNode.GetHashtable(0);
                     node[".tag."]   = key;
                     parentNode.Add(node);
                 }
                 else if (parentFirstNode[key].GetType() == typeof(Hashtable))
                 {
                     ArrayList newArray = new ArrayList();
                     ((Hashtable)parentFirstNode[key])[".tag."] = key;
                     newArray.Add(parentFirstNode[key]);
                     node[".tag."] = key;
                     newArray.Add(node);
                     parentFirstNode[key] = newArray;
                 }
             }
             else if (parentFirstNode.GetString(".tag.") == key)
             {
                 node[".tag."] = key;
                 parentNode.Add(node);
             }
             else
             {
                 if (parentNode.Count > 1 && parentFirstNode.ContainsKey(".tag."))
                 {
                     ArrayList newList = new ArrayList();
                     string    tag     = parentFirstNode.GetString(".tag.");
                     for (int i = parentNode.Count - 1; i >= 0; i--)
                     {
                         Hashtable oldNode = parentNode.GetHashtable(i);
                         if (oldNode.GetString(".tag.") == tag)
                         {
                             newList.Insert(0, parentNode[i]);
                             parentNode.RemoveAt(i);
                         }
                     }
                     Hashtable newHash = new Hashtable();
                     newHash[tag] = newList;
                     if (value.Count > 1)
                     {
                         newHash[key] = value;
                     }
                     else
                     {
                         newHash[key] = value[0];
                     }
                     parentNode.Insert(0, newHash);
                 }
                 else
                 {
                     parentFirstNode[key] = node;
                 }
             }
         }
     }
     else
     {
         Hashtable node = parentNode.GetHashtable(0);
         if (node == null)
         {
             node = new Hashtable();
             parentNode.Add(node);
         }
         if (node.ContainsKey(key))
         {
             node = new Hashtable();
             parentNode.Add(node);
         }
         node[key] = value;
     }
 }
Example #6
0
    private static void SetPropertyValue(ArrayList parentNode, string parentKey, string key, string value, bool caseInsensitive)
    {
        if (value == null)
        {
            return;
        }
        key = TrimPropertyValue(key);
        if (caseInsensitive)
        {
            key = key.ToLower();
        }
        value = TrimPropertyValue(value).XmlDecode();
        if (key.Length <= 0 && value.Length <= 0)
        {
            return;                                              // no key and no value, skip this
        }
        Hashtable parentFirstNode = parentNode.GetHashtable(0);

        if (parentFirstNode == null)
        {
            parentFirstNode = new Hashtable();
            parentNode.Add(parentFirstNode);
        }
        if (key.Length > 0 && parentFirstNode.ContainsKey(key))
        {
            if (parentFirstNode[key].GetType() == typeof(ArrayList))
            {
                Hashtable newNode = new Hashtable();
                newNode[key] = value;
                ((ArrayList)parentFirstNode[key]).Add(newNode);
            }
            else if (parentFirstNode.Count == 1)                 // the only key in the parent
            {
                Hashtable newNode = new Hashtable();
                newNode[key] = value;
                parentNode.Add(newNode);
            }
            else
            {
                ArrayList newArray = new ArrayList();
                Hashtable newNode  = new Hashtable();
                newNode[key] = parentFirstNode[key];
                newArray.Add(newNode);
                newNode      = new Hashtable();
                newNode[key] = value;
                newArray.Add(newNode);
                parentFirstNode[key] = newArray;
            }
        }
        else if (key.Length > 0)
        {
            parentFirstNode[key] = value;     // add the string value
        }
        else if (value.Length > 0)            // add a key
        {
            if (parentFirstNode.Count == 0)
            {
                key = ".value.";
            }
            else
            {
                key = parentKey;
            }
            parentFirstNode[key] = value;
        }
    }
Example #7
0
    // Only import a specific tag
    public static Hashtable Import(string xml, string tagName, bool caseInsensitive = false)
    {
        int end = xml.Length;
        int idx = FindEndOfXmlIdentifier(xml);

        if (tagName != null && tagName.Length > 0)
        {
            idx = xml.IndexOf("<" + tagName, idx);
            if (idx >= 0)
            {
                end = xml.LastIndexOf("</" + tagName + ">");
                if (end >= 0)
                {
                    end += 4 + tagName.Length;
                }
            }
            if (end < idx)
            {
                end = xml.IndexOf("/>", idx);
                if (end >= 0)
                {
                    end += 3;
                }
            }
            if (idx < 0 || end < idx)
            {
//				Debug.Log("Tag "+tagName+" not found");
                return(null);
            }
        }

        ArrayList result = new ArrayList();
        int       line   = 1;

        while (idx < end)
        {
            string    key     = "";
            int       idxPrev = idx;
            ArrayList node    = ReadNode(xml, out key, ref idx, end, ref line, caseInsensitive);
            SetPropertyValue(result, "SimpleXmlImport", key, node, caseInsensitive);
            if (idx <= idxPrev)
            {
                Debug.LogWarning("SimpleXmlImporter: empty node at line " + line);
                break;                 // little safety precaution against infinite loops
            }
        }
        if (result.Count <= 1)
        {
//			Debug.Log(result.GetHashtable(0).JsonString());
            return(result.GetHashtable(0));
        }
        Hashtable wrapper = new Hashtable();

        if (tagName == null || tagName.Length == 0)
        {
            tagName = "SimpleXmlImport";
        }
        wrapper[tagName] = result;
        Debug.Log(wrapper.JsonString());
        return(wrapper);
    }
 private static void SetPropertyValue(ArrayList parentNode, string parentKey, string key, ArrayList value, bool caseInsensitive)
 {
     if(value == null || value.Count == 0) return;
     if(value.Count == 1) {
         Hashtable node = value.GetHashtable(0);
         if(node.Count == 1 && node.ContainsKey(".value.")) {
             if(key.Length <= 0) key = parentKey;
             SetPropertyValue(parentNode, parentKey, key, node.GetString(".value."), caseInsensitive);
         } else {
             Hashtable parentFirstNode = parentNode.GetHashtable(0);
             if(parentFirstNode == null) {
                 parentFirstNode = new Hashtable();
                 parentNode.Add(parentFirstNode);
             }
             if(parentFirstNode.ContainsKey(key)) {
                 if(parentFirstNode[key].GetType() == typeof(ArrayList)) {
                     ArrayList firstNodeList = (ArrayList)parentFirstNode[key];
                     for(int i=0;i<firstNodeList.Count;i++) {
                         if(firstNodeList[i].GetType() == typeof(Hashtable)) {
                             Hashtable hash = (Hashtable)firstNodeList[i];
                             if(!hash.ContainsKey(".tag.")) hash[".tag."] = key;
                         }
                     }
                     node[".tag."] = key;
                     ((ArrayList)parentFirstNode[key]).Add(node);
                 } else if(parentFirstNode[key].GetType() == typeof(Hashtable) && parentFirstNode.Count == 1) {
                     parentNode[0] = parentFirstNode[key];
                     ((Hashtable)parentNode[0])[".tag."] = key;
                     parentFirstNode = parentNode.GetHashtable(0);
                     node[".tag."] = key;
                     parentNode.Add(node);
                 } else if(parentFirstNode[key].GetType() == typeof(Hashtable)) {
                     ArrayList newArray = new ArrayList();
                     ((Hashtable)parentFirstNode[key])[".tag."] = key;
                     newArray.Add(parentFirstNode[key]);
                     node[".tag."] = key;
                     newArray.Add(node);
                     parentFirstNode[key] = newArray;
                 }
             } else if(parentFirstNode.GetString(".tag.") == key) {
                 node[".tag."] = key;
                 parentNode.Add(node);
             } else {
                 if(parentNode.Count > 1 && parentFirstNode.ContainsKey(".tag.")) {
                     ArrayList newList = new ArrayList();
                     string tag = parentFirstNode.GetString(".tag.");
                     for(int i = parentNode.Count-1;i>=0;i--) {
                         Hashtable oldNode = parentNode.GetHashtable(i);
                         if(oldNode.GetString(".tag.") == tag) {
                             newList.Insert(0, parentNode[i]);
                             parentNode.RemoveAt(i);
                         }
                     }
                     Hashtable newHash = new Hashtable();
                     newHash[tag] = newList;
                     if(value.Count > 1)	newHash[key] = value;
                     else newHash[key] = value[0];
                     parentNode.Insert(0, newHash);
                 } else {
                     parentFirstNode[key] = node;
                 }
             }
         }
     } else {
         Hashtable node = parentNode.GetHashtable(0);
         if(node == null) {
             node = new Hashtable();
             parentNode.Add(node);
         }
         if(node.ContainsKey(key)) {
             node = new Hashtable();
             parentNode.Add(node);
         }
         node[key] = value;
     }
 }
 private static void SetPropertyValue(ArrayList parentNode, string parentKey, string key, string value, bool caseInsensitive)
 {
     if(value == null) return;
     key = TrimPropertyValue(key);
     if(caseInsensitive) key = key.ToLower();
     value = TrimPropertyValue(value).XmlDecode();
     if(key.Length <= 0 && value.Length <= 0) return; // no key and no value, skip this
     Hashtable parentFirstNode = parentNode.GetHashtable(0);
     if(parentFirstNode == null) {
         parentFirstNode = new Hashtable();
         parentNode.Add(parentFirstNode);
     }
     if(key.Length > 0 && parentFirstNode.ContainsKey(key)) {
         if(parentFirstNode[key].GetType() == typeof(ArrayList)) {
             Hashtable newNode = new Hashtable();
             newNode[key] = value;
             ((ArrayList)parentFirstNode[key]).Add(newNode);
         } else if(parentFirstNode.Count == 1) {  // the only key in the parent
             Hashtable newNode = new Hashtable();
             newNode[key] = value;
             parentNode.Add(newNode);
         } else {
             ArrayList newArray = new ArrayList();
             Hashtable newNode = new Hashtable();
             newNode[key] = parentFirstNode[key];
             newArray.Add(newNode);
             newNode = new Hashtable();
             newNode[key] = value;
             newArray.Add(newNode);
             parentFirstNode[key] = newArray;
         }
     } else if(key.Length > 0) {
         parentFirstNode[key] = value;  // add the string value
     } else if(value.Length > 0) { // add a key
         if(parentFirstNode.Count == 0) key = ".value.";
         else key = parentKey;
         parentFirstNode[key] = value;
     }
 }