MaterialComponent cleanup (#13326)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user