public override bool TryDeleteCell(RecipeRow row) { row.SetWorkUnits(null); return(true); }
private void LoadRecipesForJob(string jobAlias) { string modName = jobAlias.Split(':')[0]; int index = jobAlias.IndexOf(':'); string jobKey = jobAlias.Substring(index + 1); char sep = System.IO.Path.DirectorySeparatorChar; string recipeFileDataKey = modName + sep + "aliases" + sep + jobKey + sep + "recipes"; JsonFileData recipesIndex = ModuleDataManager.GetInstance().GetSelectedFileData(recipeFileDataKey) as JsonFileData; // Non-crafter jobs will not have recipes if (recipesIndex == null) { return; } Dictionary <string, FileData> recipeFileData = recipesIndex.LinkedFileData; foreach (KeyValuePair <string, FileData> recipe in recipeFileData) { JsonFileData jsonFileData = recipe.Value as JsonFileData; JObject recipeJson = jsonFileData.Json; JArray ingredientArray = recipeJson["ingredients"] as JArray; JArray productArray = recipeJson["produces"] as JArray; foreach (JToken product in productArray) { RecipeRow row = mDataTable.NewRecipeRow(); row.RecipeList = recipesIndex; row.Recipe = jsonFileData; JToken lvlReq = recipeJson["level_requirement"]; JToken effort = recipeJson["effort"]; JToken workUnits = recipeJson["work_units"]; JToken appeal = recipeJson.SelectToken("entity_data.stonehearth:appeal.appeal"); row.SetLevelRequired(lvlReq == null ? null : lvlReq.ToObject <int?>()); row.SetEffort(effort == null ? null : effort.ToObject <int?>()); row.SetWorkUnits(workUnits == null ? null : workUnits.ToObject <int?>()); row.SetCrafter(jobAlias); JToken item = product["item"]; if (item != null) { string alias = item.ToString(); // Check aliases linked by recipe file JsonFileData itemFileData = FindLinkedJsonMatchingAlias(jsonFileData, alias) ?? jsonFileData; SetRowDataForItem(row, alias, itemFileData); } foreach (JToken ingredient in ingredientArray) { JToken uri = ingredient["uri"]; JToken material = ingredient["material"]; JToken count = ingredient["count"]; Ingredient ingredientData = row.AddNewIngredient(); ingredientData.Amount = count.ToObject <int>(); if (material != null) { ingredientData.Name = material.ToString(); } else if (uri != null) { JsonFileData ingrJsonFileData = FindLinkedJsonMatchingAlias(jsonFileData, uri.ToString()); if (ingrJsonFileData == null) { MessageBox.Show("Could not find ingredient \"" + uri + "\" in the manifest for recipe \"" + jsonFileData.FileName + "\""); continue; } ingredientData.Name = ingrJsonFileData.GetModuleFile().FullAlias; } else { throw new Exception("Recipe " + jsonFileData.GetModuleFile().FullAlias + " has invalid ingredient with no uri/material field"); } } mDataTable.Rows.Add(row); } } }