Rewrite recipe prototype.

Fix comparer in microwavecomponent.
This commit is contained in:
FL-OZ
2020-04-27 00:27:25 -05:00
parent 7e4d4bb1d4
commit 24842418c3
2 changed files with 29 additions and 21 deletions

View File

@@ -67,11 +67,16 @@ namespace Content.Server.GameObjects.Components.Kitchen
return 0; return 0;
} }
if(x.Ingredients.Count < y.Ingredients.Count) if (x.Ingredients.Count < y.Ingredients.Count)
{ {
return 1; return 1;
} }
if (x.Ingredients.Count > y.Ingredients.Count)
{
return -1;
}
return 0; return 0;
} }
} }
@@ -109,7 +114,9 @@ namespace Content.Server.GameObjects.Components.Kitchen
{ {
var outputFromRecipe = r.OutPutPrototype; var outputFromRecipe = r.OutPutPrototype;
_entityManager.SpawnEntity(outputFromRecipe, Owner.Transform.GridPosition); _entityManager.SpawnEntity(outputFromRecipe, Owner.Transform.GridPosition);
return;
} }
} }
} }
@@ -119,13 +126,14 @@ namespace Content.Server.GameObjects.Components.Kitchen
{ {
var ingName = ingredient.Key.ToString(); var ingName = ingredient.Key.ToString();
var ingQuantity = ingredient.Value; var ingQuantity = ingredient.Value;
if (!_contents.ContainsReagent(ingName, out var amt) && amt != ingQuantity) return false; if (_contents.ContainsReagent(ingName, out var amt) && amt >= ingQuantity)
_contents.TryRemoveReagent(ingName, ReagentUnit.New(ingQuantity)); {
_contents.TryRemoveReagent(ingName, ReagentUnit.New(ingQuantity));
//This doesnt work. return true;
}
} }
return true; return false;
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel; using YamlDotNet.RepresentationModel;
@@ -17,25 +18,24 @@ namespace Content.Shared.Kitchen
public class MicrowaveMealRecipePrototype : IPrototype, IIndexedPrototype public class MicrowaveMealRecipePrototype : IPrototype, IIndexedPrototype
{ {
public string ID {get; private set;} private string _id;
public string Name {get; private set;} private string _name;
private string _output;
private Dictionary<string, int> _ingredients;
public string ID => _id;
public string Name => Loc.GetString(_name);
public string OutPutPrototype => _output;
public IReadOnlyDictionary<string, int> Ingredients => _ingredients;
public string OutPutPrototype { get; private set; }
public Dictionary<string,int> Ingredients {get; private set;}
public void LoadFrom(YamlMappingNode mapping) public void LoadFrom(YamlMappingNode mapping)
{ {
ID = mapping.GetNode("id").ToString(); var serializer = YamlObjectSerializer.NewReader(mapping);
Name = Loc.GetString(mapping.GetNode("name").ToString());
OutPutPrototype = mapping.GetNode("output").ToString();
if(mapping.TryGetNode("ingredients", out YamlMappingNode ingDict))
{
Ingredients = new Dictionary<string, int>();
foreach (var kvp in ingDict.Children)
{
Ingredients.Add(kvp.Key.ToString(), kvp.Value.AsInt());
}
}
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<string, int>());
} }
} }
} }