Upgrade structure of code base

This commit is contained in:
h z
2024-07-03 12:20:08 +08:00
parent d382481cd4
commit 42e06a0d0c
82 changed files with 864 additions and 116 deletions

View 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;
}
}