* lathe and material storage refactor * materialStorage ECS it kinda sus tho * beginning the lathe shitcode dive * couple lathe visuals and lathe system * lathe changes and such * dynamic lathe databases * rewrote internal logic on to ui * da newI * material display clientside * misc ui changes * component state handling and various other things * moar * Update Content.Shared/Lathe/LatheComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * first volley of sloth review * more fixes * losin' my mind * all da changes * test fix and other review Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
43 lines
1.6 KiB
C#
43 lines
1.6 KiB
C#
using System.Linq;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
|
|
|
namespace Content.Shared.Materials
|
|
{
|
|
/// <summary>
|
|
/// Component to store data such as "this object is made out of steel".
|
|
/// This is not a storage system for say smelteries.
|
|
/// </summary>
|
|
[RegisterComponent, NetworkedComponent]
|
|
public sealed class MaterialComponent : Component
|
|
{
|
|
[ViewVariables]
|
|
[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}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|