public static ModuleSelector Load(JToken token) { ModuleSelector filter = Fastest; if (token["ModuleFilterType"] != null) { switch ((String)token["ModuleFilterType"]) { case "Best": filter = Fastest; break; case "None": filter = None; break; case "Most Productive": filter = Productive; break; case "Specific": if (token["Module"] != null) { var moduleKey = (String)token["Module"]; if (DataCache.Modules.ContainsKey(moduleKey)) { filter = new ModuleSpecificFilter(DataCache.Modules[moduleKey]); } } break; } } return(filter); }
private void modulesButton_Click(object sender, EventArgs e) { var optionList = new List <ChooserControl>(); var fastestOption = new ItemChooserControl(null, "Best", "Best"); optionList.Add(fastestOption); var noneOption = new ItemChooserControl(null, "None", "None"); optionList.Add(noneOption); var productivityOption = new ItemChooserControl(null, "Most Productive", "Most Productive"); optionList.Add(productivityOption); var recipeNode = (BaseNode as RecipeNode); var recipe = recipeNode.BaseRecipe; var allowedModules = DataCache.Modules.Values .Where(a => a.Enabled) .Where(a => a.AllowedIn(recipe)); foreach (var module in allowedModules.OrderBy(a => a.FriendlyName)) { var item = DataCache.Items.Values.SingleOrDefault(i => i.Name == module.Name); optionList.Add(new ItemChooserControl(item, module.FriendlyName, module.FriendlyName)); } var chooserPanel = new ChooserPanel(optionList, GraphViewer); Point location = GraphViewer.ScreenToGraph(new Point(GraphViewer.Width / 2, GraphViewer.Height / 2)); chooserPanel.Show(c => { if (c != null) { if (c == fastestOption) { (BaseNode as RecipeNode).NodeModules = ModuleSelector.Fastest; } else if (c == noneOption) { (BaseNode as RecipeNode).NodeModules = ModuleSelector.None; } else if (c == productivityOption) { (BaseNode as RecipeNode).NodeModules = ModuleSelector.Productive; } else { var module = DataCache.Modules.Single(a => a.Key == c.DisplayText).Value; (BaseNode as RecipeNode).NodeModules = ModuleSelector.Specific(module); } updateAssemblerButtons(); GraphViewer.Graph.UpdateNodeValues(); GraphViewer.UpdateNodes(); } }); }
public void LoadFromJson(JObject json) { Graph.Nodes.Clear(); Elements.Clear(); //Has to go first, as all other data depends on which mods are loaded List <String> EnabledMods = json["EnabledMods"].Select(t => (String)t).ToList(); foreach (Mod mod in DataCache.Mods) { mod.Enabled = EnabledMods.Contains(mod.Name); } List <String> enabledMods = DataCache.Mods.Where(m => m.Enabled).Select(m => m.Name).ToList(); using (ProgressForm form = new ProgressForm(enabledMods)) { form.ShowDialog(); } Graph.SelectedAmountType = (AmountType)(int)json["AmountType"]; Graph.SelectedUnit = (RateUnit)(int)json["Unit"]; List <JToken> nodes = json["Nodes"].ToList <JToken>(); foreach (var node in nodes) { ProductionNode newNode = null; switch ((String)node["NodeType"]) { case "Consumer": { String itemName = (String)node["ItemName"]; if (DataCache.Items.ContainsKey(itemName)) { Item item = DataCache.Items[itemName]; newNode = ConsumerNode.Create(item, Graph); } else { Item missingItem = new Item(itemName); missingItem.IsMissingItem = true; newNode = ConsumerNode.Create(missingItem, Graph); } break; } case "Supply": { String itemName = (String)node["ItemName"]; if (DataCache.Items.ContainsKey(itemName)) { Item item = DataCache.Items[itemName]; newNode = SupplyNode.Create(item, Graph); } else { Item missingItem = new Item(itemName); missingItem.IsMissingItem = true; DataCache.Items.Add(itemName, missingItem); newNode = SupplyNode.Create(missingItem, Graph); } break; } case "PassThrough": { String itemName = (String)node["ItemName"]; if (DataCache.Items.ContainsKey(itemName)) { Item item = DataCache.Items[itemName]; newNode = PassthroughNode.Create(item, Graph); } else { Item missingItem = new Item(itemName); missingItem.IsMissingItem = true; DataCache.Items.Add(itemName, missingItem); newNode = PassthroughNode.Create(missingItem, Graph); } break; } case "Recipe": { String recipeName = (String)node["RecipeName"]; if (DataCache.Recipes.ContainsKey(recipeName)) { Recipe recipe = DataCache.Recipes[recipeName]; newNode = RecipeNode.Create(recipe, Graph); } else { Recipe missingRecipe = new Recipe(recipeName, 0f, new Dictionary <Item, float>(), new Dictionary <Item, float>()); missingRecipe.IsMissingRecipe = true; DataCache.Recipes.Add(recipeName, missingRecipe); newNode = RecipeNode.Create(missingRecipe, Graph); } if (node["Assembler"] != null) { var assemblerKey = (String)node["Assembler"]; if (DataCache.Assemblers.ContainsKey(assemblerKey)) { (newNode as RecipeNode).Assembler = DataCache.Assemblers[assemblerKey]; } } (newNode as RecipeNode).NodeModules = ModuleSelector.Load(node); break; } default: { Trace.Fail("Unknown node type: " + node["NodeType"]); break; } } if (newNode != null) { newNode.rateType = (RateType)(int)node["RateType"]; if (newNode.rateType == RateType.Manual) { if (node["DesiredRate"] != null) { newNode.desiredRate = (float)node["DesiredRate"]; } else { // Legacy data format stored desired rate in actual newNode.desiredRate = (float)node["ActualRate"]; } } if (node["SpeedBonus"] != null) { newNode.SpeedBonus = Math.Round((float)node["SpeedBonus"], 4); } if (node["ProductivityBonus"] != null) { newNode.ProductivityBonus = Math.Round((float)node["ProductivityBonus"], 4); } } } List <JToken> nodeLinks = json["NodeLinks"].ToList <JToken>(); foreach (var nodelink in nodeLinks) { ProductionNode supplier = Graph.Nodes[(int)nodelink["Supplier"]]; ProductionNode consumer = Graph.Nodes[(int)nodelink["Consumer"]]; String itemName = (String)nodelink["Item"]; if (!DataCache.Items.ContainsKey(itemName)) { Item missingItem = new Item(itemName); missingItem.IsMissingItem = true; DataCache.Items.Add(itemName, missingItem); } Item item = DataCache.Items[itemName]; NodeLink.Create(supplier, consumer, item); } IEnumerable <String> EnabledAssemblers = json["EnabledAssemblers"].Select(t => (String)t); foreach (Assembler assembler in DataCache.Assemblers.Values) { assembler.Enabled = EnabledAssemblers.Contains(assembler.Name); } IEnumerable <String> EnabledMiners = json["EnabledMiners"].Select(t => (String)t); foreach (Miner miner in DataCache.Miners.Values) { miner.Enabled = EnabledMiners.Contains(miner.Name); } IEnumerable <String> EnabledModules = json["EnabledModules"].Select(t => (String)t); foreach (Module module in DataCache.Modules.Values) { module.Enabled = EnabledModules.Contains(module.Name); } JToken enabledRecipesToken; if (json.TryGetValue("EnabledRecipes", out enabledRecipesToken)) { IEnumerable <String> EnabledRecipes = enabledRecipesToken.Select(t => (String)t); foreach (Recipe recipe in DataCache.Recipes.Values) { recipe.Enabled = EnabledRecipes.Contains(recipe.Name); } } Graph.UpdateNodeValues(); AddRemoveElements(); List <String> ElementLocations = json["ElementLocations"].Select(l => (String)l).ToList(); for (int i = 0; i < ElementLocations.Count; i++) { int[] splitPoint = ElementLocations[i].Split(',').Select(s => Convert.ToInt32(s)).ToArray(); GraphElement element = GetElementForNode(Graph.Nodes[i]); element.Location = new Point(splitPoint[0], splitPoint[1]); } LimitViewToBounds(); }
protected RecipeNode(Recipe baseRecipe, ProductionGraph graph) : base(graph) { BaseRecipe = baseRecipe; NodeModules = ModuleSelector.Fastest; }