using System.Collections; using Content.Shared.Materials; using Robust.Shared.GameStates; using Robust.Shared.Serialization; namespace Content.Shared.Lathe { [NetworkedComponent()] public abstract class SharedMaterialStorageComponent : Component, IEnumerable> { [ViewVariables] protected virtual Dictionary Storage { get; set; } = new(); public int this[string id] { get { if (!Storage.ContainsKey(id)) return 0; return Storage[id]; } } public int this[MaterialPrototype material] { get { var id = material.ID; if (!Storage.ContainsKey(id)) return 0; return Storage[id]; } } /// /// The total volume of material stored currently. /// [ViewVariables] public int CurrentAmount { get { var value = 0; foreach (var amount in Storage.Values) { value += amount; } return value; } } public IEnumerator> GetEnumerator() { return Storage.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } [NetSerializable, Serializable] public sealed class MaterialStorageState : ComponentState { public readonly Dictionary Storage; public MaterialStorageState(Dictionary storage) { Storage = storage; } } }