Ejemplo n.º 1
0
        /// <summary>
        /// <para>Allows you to edit Linked Items for TechTypes.</para>
        /// <para>Can be used for existing TechTypes too.</para>
        /// </summary>
        /// <param name="techType">The TechType whose TechData you want to edit.</param>
        /// <param name="linkedItems">The collection of Ingredients for that TechType.</param>
        /// <seealso cref="Ingredient"/>
        void ICraftDataHandler.SetLinkedItems(TechType techType, ICollection <TechType> linkedItems)
        {
            if (!CraftDataPatcher.CustomTechData.TryGetValue(techType, out JsonValue smlJsonValue))
            {
                CraftDataPatcher.CustomTechData.Add(techType, new JsonValue());
                smlJsonValue = CraftDataPatcher.CustomTechData[techType];
            }

            if (!smlJsonValue.Contains(TechData.PropertyToID("linkedItems")))
            {
                smlJsonValue.Add(TechData.PropertyToID("linkedItems"), new JsonValue(JsonValue.Type.Array));
            }
            else
            {
                smlJsonValue[TechData.PropertyToID("linkedItems")] = new JsonValue(JsonValue.Type.Array);
            }

            JsonValue linkedItemslist = smlJsonValue[TechData.PropertyToID("linkedItems")];

            int current = 0;

            foreach (TechType i in linkedItems)
            {
                linkedItemslist.Add(new JsonValue(current));
                linkedItemslist[current] = new JsonValue((int)i);
                current++;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>Allows you to edit recipes for TechTypes.</para>
        /// <para>Can be used for existing TechTypes too.</para>
        /// </summary>
        /// <param name="techType">The TechType whose TechData you want to edit.</param>
        /// <param name="ingredients">The collection of Ingredients for that TechType.</param>
        /// <seealso cref="Ingredient"/>
        void ICraftDataHandler.SetIngredients(TechType techType, ICollection <Ingredient> ingredients)
        {
            if (!CraftDataPatcher.CustomTechData.TryGetValue(techType, out JsonValue smlJsonValue))
            {
                smlJsonValue = new JsonValue();
                CraftDataPatcher.CustomTechData.Add(techType, smlJsonValue);
            }

            if (!smlJsonValue.Contains(TechData.PropertyToID("ingredients")))
            {
                smlJsonValue.Add(TechData.PropertyToID("ingredients"), new JsonValue(JsonValue.Type.Array));
            }
            else
            {
                smlJsonValue[TechData.PropertyToID("ingredients")] = new JsonValue(JsonValue.Type.Array);
            }

            JsonValue ingredientslist = smlJsonValue[TechData.PropertyToID("ingredients")];

            int amount  = TechData.PropertyToID("amount");
            int tech    = TechData.PropertyToID("techType");
            int current = 0;

            foreach (Ingredient i in ingredients)
            {
                ingredientslist.Add(new JsonValue(current));
                ingredientslist[current] = new JsonValue(JsonValue.Type.Object)
                {
                    { amount, new JsonValue(i.amount) },
                    { tech, new JsonValue((int)i.techType) }
                };
                current++;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <para>Allows you to add or edit RecipeData for TechTypes.</para>
        /// <para>Can be used for existing TechTypes too.</para>
        /// </summary>
        /// <param name="techType">The TechType whose TechData you want to edit.</param>
        /// <param name="recipeData">The TechData for that TechType.</param>
        /// <seealso cref="RecipeData"/>
        void ICraftDataHandler.SetTechData(TechType techType, RecipeData recipeData)
        {
            if (CraftDataPatcher.CustomTechData.TryGetValue(techType, out JsonValue jsonValue))
            {
                jsonValue[TechData.PropertyToID("techType")]    = new JsonValue((int)techType);
                jsonValue[TechData.PropertyToID("craftAmount")] = new JsonValue(recipeData.craftAmount);
            }
            else
            {
                jsonValue = new JsonValue
                {
                    { TechData.PropertyToID("techType"), new JsonValue((int)techType) },
                    { TechData.PropertyToID("craftAmount"), new JsonValue(recipeData.craftAmount) }
                };

                CraftDataPatcher.CustomTechData.Add(techType, jsonValue);
            }

            if (recipeData.ingredientCount > 0)
            {
                Main.SetIngredients(techType, recipeData.Ingredients);
            }
            if (recipeData.linkedItemCount > 0)
            {
                Main.SetLinkedItems(techType, recipeData.LinkedItems);
            }
        }
        /// <summary>
        /// <para>Allows you to add or edit TechData for TechTypes.</para>
        /// <para>Can be used for existing TechTypes too.</para>
        /// </summary>
        /// <param name="techType">The TechType whose TechData you want to edit.</param>
        /// <param name="jsonValue">The TechData for that TechType.</param>
        /// <seealso cref="TechData.defaults"/>
        void ICraftDataHandler.SetTechData(TechType techType, JsonValue jsonValue)
        {
            var techTypeValue = new JsonValue((int)techType);

            if (techTypeValue != jsonValue[TechData.PropertyToID("techType")])
            {
                jsonValue.Add(TechData.PropertyToID("techType"), techTypeValue);
            }

            CraftDataPatcher.CustomTechData[techType] = jsonValue;
        }
        /// <summary>
        /// <para>Allows you to add or edit RecipeData for TechTypes.</para>
        /// <para>Can be used for existing TechTypes too.</para>
        /// </summary>
        /// <param name="techType">The TechType whose TechData you want to edit.</param>
        /// <param name="recipeData">The TechData for that TechType.</param>
        /// <seealso cref="RecipeData"/>
        void ICraftDataHandler.SetTechData(TechType techType, RecipeData recipeData)
        {
            var currentTechType = new JsonValue
            {
                { TechData.PropertyToID("techType"), new JsonValue((int)techType) },
                { TechData.PropertyToID("craftAmount"), new JsonValue(recipeData.craftAmount) }
            };

            CraftDataPatcher.CustomTechData[techType] = currentTechType;

            if (recipeData.ingredientCount > 0)
            {
                Main.AddIngredients(techType, recipeData.Ingredients);
            }
            if (recipeData.linkedItemCount > 0)
            {
                Main.AddLinkedItems(techType, recipeData.LinkedItems);
            }
        }
Ejemplo n.º 6
0
 private static void AddJsonProperty(TechType techType, string key, JsonValue newValue)
 {
     if (CraftDataPatcher.CustomTechData.TryGetValue(techType, out JsonValue techData))
     {
         techData[TechData.PropertyToID(key)] = newValue;
     }
     else
     {
         CraftDataPatcher.CustomTechData[techType] = new JsonValue
         {
             {
                 TechData.PropertyToID("techType"),
                 new JsonValue((int)techType)
             },
             {
                 TechData.PropertyToID(key),
                 newValue
             }
         };
     }
 }
        /// <summary>
        /// <para>Allows you to edit Linked Items for TechTypes.</para>
        /// <para>Can be used for existing TechTypes too.</para>
        /// </summary>
        /// <param name="techType">The TechType whose TechData you want to edit.</param>
        /// <param name="linkedItems">The collection of Ingredients for that TechType.</param>
        /// <seealso cref="Ingredient"/>
        void ICraftDataHandler.AddLinkedItems(TechType techType, ICollection <TechType> linkedItems)
        {
            if (!CraftDataPatcher.CustomTechData.TryGetValue(techType, out JsonValue smlJsonValue))
            {
                smlJsonValue = new JsonValue();
                CraftDataPatcher.CustomTechData.Add(techType, smlJsonValue);
            }

            smlJsonValue.Add(TechData.PropertyToID("linkedItems"), new JsonValue(JsonValue.Type.Array));
            JsonValue linkedItemslist = smlJsonValue[TechData.PropertyToID("linkedItems")];
            //int amount = TechData.PropertyToID("amount");
            //int tech = TechData.PropertyToID("techType");
            //int count = linkedItems.Count;
            int current = 0;

            foreach (TechType i in linkedItems)
            {
                linkedItemslist.Add(new JsonValue(current));
                linkedItemslist[current] = new JsonValue((int)i);
                current++;
            }
        }