using System.Collections.Generic; using Content.Server.Materials; using SS14.Shared.GameObjects; using SS14.Shared.Interfaces.Reflection; using SS14.Shared.Interfaces.Serialization; using SS14.Shared.IoC; using SS14.Shared.Prototypes; using SS14.Shared.Serialization; using SS14.Shared.Utility; namespace Content.Server.GameObjects.Components.Materials { /// /// Component to store data such as "this object is made out of steel". /// This is not a storage system for say smelteries. /// public class MaterialComponent : Component { public const string SerializationCache = "mat"; public override string Name => "Material"; Dictionary MaterialTypes; public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); // TODO: Writing. if (!serializer.Reading) { return; } if (serializer.TryGetCacheData(SerializationCache, out Dictionary cached)) { MaterialTypes = cached.ShallowClone(); return; } MaterialTypes = new Dictionary(); if (serializer.TryReadDataField("materials", out List list)) { var protoMan = IoCManager.Resolve(); int index = 0; foreach (var entry in list) { var proto = protoMan.Index(entry.Value); MaterialTypes[entry.Key] = proto.Material; index++; } } serializer.SetCacheData(SerializationCache, MaterialTypes.ShallowClone()); } class MaterialDataEntry : IExposeData { public object Key; public string Value; public void ExposeData(ObjectSerializer serializer) { if (!serializer.Reading) { return; } var refl = IoCManager.Resolve(); Value = serializer.ReadDataField("mat"); var key = serializer.ReadDataField("key"); if (refl.TryParseEnumReference(key, out var @enum)) { Key = @enum; return; } Key = key; } } } public enum MaterialKeys { Stack, } }