Ejemplo n.º 1
0
        internal List <LoaderError> Load(IEnumerable <RecipeDef> defs)
        {
            var ret = new List <LoaderError>();

            var c = defs.Count();

            // this will make the internal array resize when needed, and it won't happen multiple times when the defs collection is huge (will cause memory issues due to GC)
            // i.e. this ensures that enough memory is preallocated
            if (recipes.Count + c > recipes.Capacity)
            {
                recipes.Capacity += c;
            }

            ExtendVanillaArrays(c);

            Recipe.newRecipe = new Recipe(); // just to make sure

            foreach (var d in defs)
            {
                recipes.Add(d);

                try
                {
                    CopyDefToVanilla(d, Recipe.newRecipe);
                }
                catch (Exception e)
                {
                    ret.Add(new LoaderError(d.Mod, "Could not load a RecipeDef that creates item " + d.CreateItem + ".", e));
                }

                Recipe.AddRecipe();
            }

            Recipe.numRecipes += c;

            return(ret);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds a Recipe to the game.
 /// </summary>
 /// <param name="r">The Recipe to add</param>
 public static void AddToGame(Recipe r)
 {
     Recipe.newRecipe = r;
     Recipe.AddRecipe();
 }