MaterialComponent cleanup (#13326)

This commit is contained in:
Leon Friedrich
2023-01-08 11:36:32 +13:00
committed by GitHub
parent 89301629f5
commit 1f5bae751f
12 changed files with 70 additions and 75 deletions

View File

@@ -1,6 +1,4 @@
using System.Linq;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
namespace Content.Shared.Materials
@@ -13,29 +11,6 @@ namespace Content.Shared.Materials
public sealed class MaterialComponent : Component
{
[DataField("materials", customTypeSerializer:typeof(PrototypeIdDictionarySerializer<int, MaterialPrototype>))]
// ReSharper disable once CollectionNeverUpdated.Local
public readonly Dictionary<string, int> _materials = new();
public List<string> MaterialIds => _materials.Keys.ToList();
/// <summary>
/// Returns all materials which make up this entity.
/// This property has an IoC resolve and is generally slow, so be sure to cache the results if needed.
/// </summary>
[ViewVariables]
public IEnumerable<MaterialPrototype> Materials
{
get
{
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in MaterialIds)
{
if(prototypeManager.TryIndex<MaterialPrototype>(id, out var material))
yield return material;
else
Logger.Error($"Material prototype {id} does not exist! Entity: {Owner}");
}
}
}
public readonly Dictionary<string, int> Materials = new();
}
}