Example #1
0
    //This function creates Recipe objects based on Recipes.json to use them in game.
    //Recipes are saved in Recipes array.
    private void GenerateActualRecipes()
    {
        Debug.Log("Generating recipes");
        var json = RecipeJSONParser.getInstance().getRecipeJSON();

        Recipes = new Recipe[json.Count];
        int j = 0;

        foreach (JSONObject o in json)
        {
            Debug.Log(o.Print(true));
            var ingredients = o["Ingredints"];
            var name        = o.GetField("Name").str;
            var time        = o.GetField("CraftTime").n;
            Dictionary <string, int> ingredient = new Dictionary <string, int>();
            var ing = o["Ingredients"];
            for (int i = 0; i < ing.Count; i++)
            {
                var key   = ing.keys[i];
                var value = (int)ing[key].n;
                ingredient.Add(key, value);
            }
            Recipes[j] = new Recipe(name, time, ingredient);
            j++;
        }
    }
Example #2
0
 public static RecipeJSONParser getInstance()
 {
     if (_instance == null)
     {
         _instance = new RecipeJSONParser();
     }
     return(_instance);
 }
Example #3
0
 private void Awake()
 {
     RecipeJSONParser.getInstance().LoadString();
     GenerateActualRecipes();
 }