Upgrade structure of code base
This commit is contained in:
44
src/DataStructures/DataCache.cs
Normal file
44
src/DataStructures/DataCache.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Godot;
|
||||
using Nocturnis.GlobalManagement.Providers;
|
||||
using Skeleton.DataStructure;
|
||||
|
||||
namespace Nocturnis.DataStructures;
|
||||
|
||||
public class DataCache : CacheItem<IData>
|
||||
{
|
||||
public new static DataCache Null => new DataCache(x => (0, ""));
|
||||
public DataCache(Func<CacheItem?, IData> rec) : base(rec) => throw new Exception("CONSTRUCTION NOT ALLOWED");
|
||||
|
||||
public DataCache(Func<CacheItem?, (object, StringName)> rec)
|
||||
{
|
||||
Value = GlobalProvider.DataStructureProvider!.NewData(0, "");
|
||||
ProxyCalculator = rec;
|
||||
}
|
||||
|
||||
private new Func<CacheItem, (object, StringName)> ProxyCalculator { get; set; }
|
||||
|
||||
public override IData? Get
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Expired)
|
||||
{
|
||||
(object val, StringName type) = ProxyCalculator(this);
|
||||
Value!.Type = type;
|
||||
Value.Data = val;
|
||||
}
|
||||
|
||||
return Value;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCalculation(Func<CacheItem, (object, StringName)> rec)
|
||||
{
|
||||
Expire();
|
||||
foreach (CacheItem item in Dependencies)
|
||||
item.References.Remove(this);
|
||||
Dependencies = new HashSet<CacheItem>();
|
||||
ProxyCalculator = rec;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user