mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
Update EcsWorldConfig.cs
This commit is contained in:
parent
181f0ecde9
commit
71464421a4
@ -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<T>(string valueName);
|
||||
bool TryGet<T>(string valueName, out T value);
|
||||
}
|
||||
public interface IEcsWorldConfigWriter
|
||||
{
|
||||
void Set<T>(string valueName, T value);
|
||||
bool Has(string valueName);
|
||||
T Get<T>(string valueName);
|
||||
bool TryGet<T>(string valueName, out T value);
|
||||
void Remove(string valueName);
|
||||
}
|
||||
public class EcsWorldConfig : IEcsWorldConfig
|
||||
public class EcsWorldConfig : IEcsWorldConfigWriter, IEcsWorldConfig
|
||||
{
|
||||
private Dictionary<string, object> _storage = new Dictionary<string, object>();
|
||||
private bool _isLocked = false;
|
||||
public bool IsLocked { get { return _isLocked; } }
|
||||
public void Lock()
|
||||
{
|
||||
_isLocked = true;
|
||||
}
|
||||
|
||||
public T Get<T>(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<T>(string valueName, T value)
|
||||
{
|
||||
if (_isLocked)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
_storage[valueName] = value;
|
||||
}
|
||||
public bool TryGet<T>(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<TConfig>(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<TConfig>(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<TConfig>(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<TConfig>(this TConfig self, int value)
|
||||
where TConfig : IEcsWorldConfig
|
||||
where TConfig : IEcsWorldConfigWriter
|
||||
{
|
||||
self.Set(POOL_RECYCLED_COMPONENTS_CAPACITY, value);
|
||||
return self;
|
||||
|
Loading…
Reference in New Issue
Block a user