2018-07-27 17:11:58 +02:00
|
|
|
using System.Collections.Generic;
|
2019-04-26 15:51:05 +02:00
|
|
|
using Content.Shared.Materials;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Reflection;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Serialization;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-05-08 03:47:53 +02:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2018-07-27 17:11:58 +02:00
|
|
|
|
2019-04-26 15:51:05 +02:00
|
|
|
namespace Content.Shared.GameObjects.Components.Materials
|
2018-07-27 17:11:58 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Component to store data such as "this object is made out of steel".
|
|
|
|
|
/// This is not a storage system for say smelteries.
|
|
|
|
|
/// </summary>
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2021-03-05 01:08:38 +01:00
|
|
|
public class MaterialComponent : Component, ISerializationHooks
|
2018-07-27 17:11:58 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
|
2018-07-27 17:11:58 +02:00
|
|
|
public const string SerializationCache = "mat";
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2018-07-27 17:11:58 +02:00
|
|
|
public override string Name => "Material";
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("materials")] private List<MaterialDataEntry> _materials = new();
|
2018-07-27 17:11:58 +02:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
public IEnumerable<KeyValuePair<object, MaterialPrototype>> MaterialTypes
|
2018-07-27 17:11:58 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
get
|
2018-07-27 17:11:58 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
foreach (var entry in _materials)
|
2018-07-27 17:11:58 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
var prototype = _prototypeManager.Index<MaterialPrototype>(entry.Value);
|
|
|
|
|
|
|
|
|
|
yield return new KeyValuePair<object, MaterialPrototype>(entry.Key, prototype);
|
2018-07-27 17:11:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataDefinition]
|
|
|
|
|
public class MaterialDataEntry : ISerializationHooks
|
2018-07-27 17:11:58 +02:00
|
|
|
{
|
2021-03-15 21:55:49 +01:00
|
|
|
public object Key = default!;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-03-15 21:55:49 +01:00
|
|
|
[DataField("key", required: true)]
|
|
|
|
|
public string StringKey = default!;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-05-08 03:47:53 +02:00
|
|
|
[DataField("mat", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<MaterialPrototype>))]
|
2021-03-15 21:55:49 +01:00
|
|
|
public string Value = default!;
|
2018-07-27 17:11:58 +02:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
void ISerializationHooks.AfterDeserialization()
|
2018-07-27 17:11:58 +02:00
|
|
|
{
|
|
|
|
|
var refl = IoCManager.Resolve<IReflectionManager>();
|
2021-03-05 01:08:38 +01:00
|
|
|
|
|
|
|
|
if (refl.TryParseEnumReference(StringKey, out var @enum))
|
2018-07-27 17:11:58 +02:00
|
|
|
{
|
|
|
|
|
Key = @enum;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-05 01:08:38 +01:00
|
|
|
|
|
|
|
|
Key = StringKey;
|
2018-07-27 17:11:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-02 08:29:55 +02:00
|
|
|
|
|
|
|
|
public enum MaterialKeys
|
|
|
|
|
{
|
|
|
|
|
Stack,
|
|
|
|
|
}
|
2018-07-27 17:11:58 +02:00
|
|
|
}
|