2019-04-26 15:51:05 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Content.Shared.Materials;
|
2019-04-26 15:51:05 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2019-04-26 15:51:05 +02:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Lathe
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2022-02-16 00:23:23 -07:00
|
|
|
public abstract class SharedMaterialStorageComponent : Component, IEnumerable<KeyValuePair<string, int>>
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[ViewVariables]
|
|
|
|
|
protected virtual Dictionary<string, int> Storage { get; set; } = new();
|
|
|
|
|
|
2022-01-09 20:10:36 -08:00
|
|
|
public int this[string id]
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2022-01-09 20:10:36 -08:00
|
|
|
if (!Storage.ContainsKey(id))
|
2019-04-26 15:51:05 +02:00
|
|
|
return 0;
|
2022-01-09 20:10:36 -08:00
|
|
|
return Storage[id];
|
2021-03-05 01:08:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int this[MaterialPrototype material]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2022-01-09 20:10:36 -08:00
|
|
|
var id = material.ID;
|
|
|
|
|
if (!Storage.ContainsKey(id))
|
2021-03-05 01:08:38 +01:00
|
|
|
return 0;
|
2022-01-09 20:10:36 -08:00
|
|
|
return Storage[id];
|
2019-04-26 15:51:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The total volume of material stored currently.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables] public int CurrentAmount
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var value = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var amount in Storage.Values)
|
|
|
|
|
{
|
|
|
|
|
value += amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerator<KeyValuePair<string, int>> GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return Storage.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NetSerializable, Serializable]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class MaterialStorageState : ComponentState
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
|
|
|
|
public readonly Dictionary<string, int> Storage;
|
2021-07-12 01:32:10 -07:00
|
|
|
public MaterialStorageState(Dictionary<string, int> storage)
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
|
|
|
|
Storage = storage;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|