From 71464421a4121d59c72fd1e0df5c5ca95b52b772 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:00:30 +0800 Subject: [PATCH] Update EcsWorldConfig.cs --- src/EcsWorldConfig.cs | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/EcsWorldConfig.cs b/src/EcsWorldConfig.cs index 1a1e269..17c619d 100644 --- a/src/EcsWorldConfig.cs +++ b/src/EcsWorldConfig.cs @@ -1,27 +1,25 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace DCFApixels.DragonECS { public interface IEcsWorldConfig { - bool IsLocked { get; } - void Lock(); + bool Has(string valueName); + T Get(string valueName); + bool TryGet(string valueName, out T value); + } + public interface IEcsWorldConfigWriter + { void Set(string valueName, T value); bool Has(string valueName); T Get(string valueName); bool TryGet(string valueName, out T value); void Remove(string valueName); } - public class EcsWorldConfig : IEcsWorldConfig + public class EcsWorldConfig : IEcsWorldConfigWriter, IEcsWorldConfig { private Dictionary _storage = new Dictionary(); - private bool _isLocked = false; - public bool IsLocked { get { return _isLocked; } } - public void Lock() - { - _isLocked = true; - } + public T Get(string valueName) { return (T)_storage[valueName]; @@ -32,18 +30,10 @@ namespace DCFApixels.DragonECS } public void Remove(string valueName) { - if (_isLocked) - { - throw new InvalidOperationException(); - } _storage.Remove(valueName); } public void Set(string valueName, T value) { - if (_isLocked) - { - throw new InvalidOperationException(); - } _storage[valueName] = value; } public bool TryGet(string valueName, out T value) @@ -67,7 +57,7 @@ namespace DCFApixels.DragonECS private const string ENTITIES_CAPACITY = nameof(ENTITIES_CAPACITY); private const int ENTITIES_CAPACITY_DEFAULT = 512; public static TConfig Set_EntitiesCapacity(this TConfig self, int value) - where TConfig : IEcsWorldConfig + where TConfig : IEcsWorldConfigWriter { self.Set(ENTITIES_CAPACITY, value); return self; @@ -90,7 +80,7 @@ namespace DCFApixels.DragonECS private const string POOLS_CAPACITY = nameof(POOLS_CAPACITY); private const int POOLS_CAPACITY_DEFAULT = 512; public static TConfig Set_PoolsCapacity(this TConfig self, int value) - where TConfig : IEcsWorldConfig + where TConfig : IEcsWorldConfigWriter { self.Set(POOLS_CAPACITY, value); return self; @@ -103,7 +93,7 @@ namespace DCFApixels.DragonECS private const string COMPONENT_POOL_CAPACITY = nameof(COMPONENT_POOL_CAPACITY); private const int COMPONENT_POOL_CAPACITY_DEFAULT = 512; public static TConfig Set_PoolComponentsCapacity(this TConfig self, int value) - where TConfig : IEcsWorldConfig + where TConfig : IEcsWorldConfigWriter { self.Set(COMPONENT_POOL_CAPACITY, value); return self; @@ -115,7 +105,7 @@ namespace DCFApixels.DragonECS private const string POOL_RECYCLED_COMPONENTS_CAPACITY = nameof(POOL_RECYCLED_COMPONENTS_CAPACITY); public static TConfig Set_PoolRecycledComponentsCapacity(this TConfig self, int value) - where TConfig : IEcsWorldConfig + where TConfig : IEcsWorldConfigWriter { self.Set(POOL_RECYCLED_COMPONENTS_CAPACITY, value); return self;