Files
tbd-station-14/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs
Víctor Aguilera Puerto fe0414eda7 Lathes (#207)
* Recipe stuff.

* Lathe GUI and stuff

* god dammit

* Lathe menu works, yay.

* EventArgs henk

* Some work

* SS14 -> Robust

* More SS14 -> Robust

* Lathe materials

* Lathe works, Lathe GUI, Queue GUI, etc

too many changes to name them here

* Remove materials button, add ViewVariables and update lathe on connect

* Add Autolathe RSI

* Adds new recipes, fixes a few bugs.

* Remove unused ScrollContainers

* Use same delegate for spawn.

* Removes client-side LatheComponent in favor of BoundUserInterface

* Remove GetMaterial and TryGetMaterial

* Use auto-properties in a few places.

* Adds LatheDatabase, and a bunch of other changes

* Remove useless log.

* Remove lathetype from prototypes.

* Turns Storage, Lathe and Database into autoproperties

* Remove Hacked property from LatheRecipePrototype

* Remove unneeded dependency injection from components

* Refactors LatheDatabaseComponent to use ComponentState

* Refactors MaterialStorageComponent to use ComponentState

* Oopsie

* Another oopsie

* Last oopsie, I hope

* Fix missing Close call.
2019-04-26 15:51:05 +02:00

88 lines
2.7 KiB
C#

using System.Collections.Generic;
using Content.Shared.Materials;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.GameObjects.Components.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>
public class MaterialComponent : Component
{
public const string SerializationCache = "mat";
public override string Name => "Material";
public Dictionary<object, Material> MaterialTypes => _materialTypes;
private Dictionary<object, Material> _materialTypes;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
// TODO: Writing.
if (!serializer.Reading)
{
return;
}
if (serializer.TryGetCacheData(SerializationCache, out Dictionary<object, Material> cached))
{
_materialTypes = cached.ShallowClone();
return;
}
_materialTypes = new Dictionary<object, Material>();
if (serializer.TryReadDataField("materials", out List<MaterialDataEntry> list))
{
var protoMan = IoCManager.Resolve<IPrototypeManager>();
int index = 0;
foreach (var entry in list)
{
var proto = protoMan.Index<MaterialPrototype>(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<IReflectionManager>();
Value = serializer.ReadDataField<string>("mat");
var key = serializer.ReadDataField<string>("key");
if (refl.TryParseEnumReference(key, out var @enum))
{
Key = @enum;
return;
}
Key = key;
}
}
}
public enum MaterialKeys
{
Stack,
}
}