using System; using System.Collections; using System.Collections.Generic; namespace DCFApixels.DragonECS { public interface IEcsPipelineConfig : IConfig { } public interface IEcsPipelineConfigWriter : IConfigWriter { IEcsPipelineConfig GetPipelineConfig(); } [Serializable] public class EcsPipelineConfig : IEcsPipelineConfigWriter, IEcsPipelineConfig, IEnumerable> { public static readonly IEcsWorldConfig Empty = new EmptyConfig(); private Dictionary _storage = new Dictionary(); public EcsPipelineConfig() { } public EcsPipelineConfig(IEnumerable> range) { _storage = new Dictionary(); foreach (var item in range) { _storage.Add(item.Key, item.Value); } } public EcsPipelineConfig(params KeyValuePair[] range) { _storage = new Dictionary(); foreach (var item in range) { _storage.Add(item.Key, item.Value); } } public int Count { get { return _storage.Count; } } public T Get(string valueName) { return (T)_storage[valueName]; } public bool Has(string valueName) { return _storage.ContainsKey(valueName); } public void Remove(string valueName) { _storage.Remove(valueName); } public void Set(string valueName, T value) { _storage[valueName] = value; } public void Add(string key, object value) { _storage.Add(key, value); } public void Add(KeyValuePair pair) { _storage.Add(pair.Key, pair.Value); } public bool TryGet(string valueName, out T value) { bool result = _storage.TryGetValue(valueName, out object rawValue); value = rawValue == null ? default : (T)rawValue; return result; } public IEnumerable> GetAllConfigs() { return _storage; } public IEnumerator> GetEnumerator() { return GetAllConfigs().GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetAllConfigs().GetEnumerator(); } public IEcsPipelineConfig GetPipelineConfig() { return this; } private class EmptyConfig : IEcsWorldConfig { public int Count { get { return 0; } } public T Get(string valueName) { return default; } public IEnumerable> GetAllConfigs() { return Array.Empty>(); } public bool Has(string valueName) { return false; } public bool TryGet(string valueName, out T value) { value = default; return false; } } } }