public static void CreateRecipeFiles() { if (SceneManager.GetActiveScene().name != "main") { return; } wasBlank = false; foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if (recipe.m_item == null) { continue; } Logger.Log($"Generated Recipe '{recipe.m_item.name}'"); JRecipe jr = new JRecipe(); jr.recipe_id = recipe.name; jr.result_item_id = recipe.m_item.gameObject.name; jr.result_amount = recipe.m_amount; if (recipe.m_craftingStation != null) { jr.CraftingStation = recipe.m_craftingStation.m_name; } if (recipe.m_repairStation != null) { jr.RepairStation = recipe.m_repairStation.m_name; } jr.minStationLevel = recipe.m_minStationLevel; jr.ingredients = new JIngredients[recipe.m_resources.Length]; for (int i = 0; i < recipe.m_resources.Length; i++) { jr.ingredients[i] = new JIngredients(); jr.ingredients[i].amount = recipe.m_resources[i].m_amount; jr.ingredients[i].id = recipe.m_resources[i].m_resItem.gameObject.name; jr.ingredients[i].amountPerLevel = recipe.m_resources[i].m_amountPerLevel; } string json = TinyJson.JSONWriter.ToJson(jr); json = JsonFormatter.Format(json, !OpenDatabase.showZerosInJSON.Value); File.WriteAllText(OpenDatabase.recipeFolder + "/" + recipe.name + ".json", json); } }
public static void LoadRecipes() { CheckIntegrity(); recipes = new List <JRecipe>(); string[] files = Directory.GetFiles(OpenDatabase.recipeFolder); foreach (string f in files) { if (!f.EndsWith(".json")) { continue; } string content = File.ReadAllText(f); JRecipe jRecipe = content.FromJson <JRecipe>(); jRecipe.recipe_id = Path.GetFileNameWithoutExtension(f); recipes.Add(jRecipe); } }
public static void ReloadRecipes() { JSONHandler.LoadRecipes(); if (craftingStations == null) { craftingStations = new Dictionary <string, CraftingStation>(); foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if (recipe.m_craftingStation != null && !craftingStations.ContainsKey(recipe.m_craftingStation.m_name)) { craftingStations.Add(recipe.m_craftingStation.m_name, recipe.m_craftingStation); } if (recipe.m_repairStation != null && !craftingStations.ContainsKey(recipe.m_repairStation.m_name)) { craftingStations.Add(recipe.m_repairStation.m_name, recipe.m_repairStation); } } Logger.Log($"Found {craftingStations.Count} Crafting/Repair-Stations. [{string.Join(", ", craftingStations.Select(x => x.Key).ToArray())}]"); } foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if (recipe.m_item == null) { continue; } JRecipe jRecipe = JSONHandler.GetJRecipeById(recipe.name); if (jRecipe != null) { Logger.Log($"Loaded {jRecipe.result_item_id} with {jRecipe.ingredients.Length} ingredients"); recipe.m_amount = jRecipe.result_amount; recipe.m_resources = new Piece.Requirement[jRecipe.ingredients.Length]; recipe.m_minStationLevel = jRecipe.minStationLevel; if (jRecipe.CraftingStation != null && jRecipe.CraftingStation != "") { CraftingStation station = craftingStations[jRecipe.CraftingStation]; if (station != null) { recipe.m_craftingStation = station; } else { Logger.LogError($"Couldn't find CraftingStation {jRecipe.CraftingStation}"); } } else { recipe.m_craftingStation = null; } if (jRecipe.RepairStation != null && jRecipe.RepairStation != "") { CraftingStation station = craftingStations[jRecipe.RepairStation]; if (station != null) { recipe.m_repairStation = station; } else { Logger.LogError($"Couldn't find RepairStation {jRecipe.RepairStation}"); } } else { recipe.m_repairStation = null; } for (int i = 0; i < jRecipe.ingredients.Length; i++) { ItemDrop _drop = getItemById(jRecipe.ingredients[i].id); recipe.m_resources[i] = new Piece.Requirement(); recipe.m_resources[i].m_amount = jRecipe.ingredients[i].amount; recipe.m_resources[i].m_resItem = _drop; recipe.m_resources[i].m_amountPerLevel = jRecipe.ingredients[i].amountPerLevel; } } } }