From 24842418c326d4427e0cbe43b4eb526a1bc281ea Mon Sep 17 00:00:00 2001 From: FL-OZ Date: Mon, 27 Apr 2020 00:27:25 -0500 Subject: [PATCH] Rewrite recipe prototype. Fix comparer in microwavecomponent. --- .../Kitchen/KitchenMicrowaveComponent.cs | 20 +++++++++---- .../Kitchen/MicrowaveMealRecipePrototype.cs | 30 +++++++++---------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs index 13f2c36411..e120a3e43e 100644 --- a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs @@ -67,11 +67,16 @@ namespace Content.Server.GameObjects.Components.Kitchen return 0; } - if(x.Ingredients.Count < y.Ingredients.Count) + if (x.Ingredients.Count < y.Ingredients.Count) { return 1; } + if (x.Ingredients.Count > y.Ingredients.Count) + { + return -1; + } + return 0; } } @@ -109,7 +114,9 @@ namespace Content.Server.GameObjects.Components.Kitchen { var outputFromRecipe = r.OutPutPrototype; _entityManager.SpawnEntity(outputFromRecipe, Owner.Transform.GridPosition); + return; } + } } @@ -119,13 +126,14 @@ namespace Content.Server.GameObjects.Components.Kitchen { var ingName = ingredient.Key.ToString(); var ingQuantity = ingredient.Value; - if (!_contents.ContainsReagent(ingName, out var amt) && amt != ingQuantity) return false; - _contents.TryRemoveReagent(ingName, ReagentUnit.New(ingQuantity)); - - //This doesnt work. + if (_contents.ContainsReagent(ingName, out var amt) && amt >= ingQuantity) + { + _contents.TryRemoveReagent(ingName, ReagentUnit.New(ingQuantity)); + return true; + } } - return true; + return false; } diff --git a/Content.Shared/Kitchen/MicrowaveMealRecipePrototype.cs b/Content.Shared/Kitchen/MicrowaveMealRecipePrototype.cs index c0804a7530..7b93cbbb3e 100644 --- a/Content.Shared/Kitchen/MicrowaveMealRecipePrototype.cs +++ b/Content.Shared/Kitchen/MicrowaveMealRecipePrototype.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Robust.Shared.Localization; using Robust.Shared.Prototypes; +using Robust.Shared.Serialization; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -17,25 +18,24 @@ namespace Content.Shared.Kitchen public class MicrowaveMealRecipePrototype : IPrototype, IIndexedPrototype { - public string ID {get; private set;} - public string Name {get; private set;} + private string _id; + private string _name; + private string _output; + private Dictionary _ingredients; + + public string ID => _id; + public string Name => Loc.GetString(_name); + public string OutPutPrototype => _output; + public IReadOnlyDictionary Ingredients => _ingredients; - public string OutPutPrototype { get; private set; } - public Dictionary Ingredients {get; private set;} public void LoadFrom(YamlMappingNode mapping) { - ID = mapping.GetNode("id").ToString(); - Name = Loc.GetString(mapping.GetNode("name").ToString()); - OutPutPrototype = mapping.GetNode("output").ToString(); - if(mapping.TryGetNode("ingredients", out YamlMappingNode ingDict)) - { - Ingredients = new Dictionary(); - foreach (var kvp in ingDict.Children) - { - Ingredients.Add(kvp.Key.ToString(), kvp.Value.AsInt()); - } - } + var serializer = YamlObjectSerializer.NewReader(mapping); + serializer.DataField(ref _id, "id", string.Empty); + serializer.DataField(ref _name, "name", string.Empty); + serializer.DataField(ref _output, "output", string.Empty); + serializer.DataField(ref _ingredients, "ingredients", new Dictionary()); } } }