add: Patchable items and frames

This commit is contained in:
h z
2025-03-04 11:58:14 +00:00
parent 684763f0cc
commit 93fbe0869b
18 changed files with 163 additions and 26 deletions

View File

@@ -1,18 +1,18 @@
using Godot;
using Polonium.Interfaces;
using Polonium.MessageManager;
using Polonium.Resources;
using Polonium.Resources.FramePatches;
namespace Polonium.Agents;
public abstract partial class Knowledge : Node, IMessageClient
{
public abstract void UpdateKnowledge(KnowledgePatch update);
public abstract void UpdateKnowledge(FramePatch update);
public string PostCode { get; set; }
public virtual void ReceiveMessage(PoloniumMessage msg)
{
if(msg is KnowledgePatch update)
if(msg is FramePatch update)
UpdateKnowledge(update);
}

View File

@@ -1,17 +1,16 @@
using Godot;
using Polonium.Interfaces;
using Polonium.MessageManager;
using Polonium.Resources;
using Polonium.Resources.FramePatches;
namespace Polonium.Agents;
public abstract partial class KnowledgeRender : Node, IMessageClient
{
public abstract void RenderKnowledgePatch(KnowledgePatch update);
public abstract void RenderKnowledgePatch(FramePatch update);
public string PostCode { get; set; }
public virtual void ReceiveMessage(PoloniumMessage msg)
{
if(msg is KnowledgePatch p)
if(msg is FramePatch p)
RenderKnowledgePatch(p);
}

View File

@@ -0,0 +1,6 @@
namespace Polonium.Attributes;
[AttributeUsage(AttributeTargets.Interface)]
public class AutoPatch : Attribute
{
}

View File

@@ -0,0 +1,6 @@
namespace Polonium.Attributes;
[AttributeUsage(AttributeTargets.Property)]
public class PatchableProperty : Attribute
{
}

View File

@@ -0,0 +1,31 @@
using System.Collections;
namespace Polonium.DataStructures.PatchableItems;
public class PatchableDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
{
public Dictionary<TKey, TValue> Data { get; set; } = new();
public int Count => Data.Count;
public void Add(TKey key, TValue value) => Data.Add(key, value);
public void Remove(TKey key) => Data.Remove(key);
public void Clear() => Data.Clear();
public bool ContainsKey(TKey key) => Data.ContainsKey(key);
public bool TryGetValue(TKey key, out TValue value) => Data.TryGetValue(key, out value);
public bool ContainsValue(TValue value) => Data.ContainsValue(value);
public TValue this[TKey key]
{
get => Data[key];
set => Data[key] = value;
}
public IEnumerable<TKey> Keys => Data.Keys;
public IEnumerable<TValue> Values => Data.Values;
public UpdateMethods UpdateMethod { get; set; } = UpdateMethods.Update;
public delegate void CustomUpdatedEventHandler(Dictionary<TKey, TValue> set);
public event CustomUpdatedEventHandler CustomUpdated;
public void CustomUpdate(Dictionary<TKey, TValue> set) => CustomUpdated?.Invoke(set);
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() => Data.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

View File

@@ -0,0 +1,23 @@
using System.Collections;
namespace Polonium.DataStructures.PatchableItems;
public class PatchableHashSet<T> : IEnumerable<T>
{
public HashSet<T> Data { get; set; } = new();
public void Add(T item) => Data.Add(item);
public void Remove(T item) => Data.Remove(item);
public void Clear() => Data.Clear();
public bool Contains(T item) => Data.Contains(item);
public int Count => Data.Count;
public UpdateMethods UpdateMethod { get; set; } = UpdateMethods.Update;
public delegate void CustomUpdatedEventHandler(HashSet<T> set);
public event CustomUpdatedEventHandler CustomUpdated;
public void CustomUpdate(HashSet<T> set) => CustomUpdated?.Invoke(set);
public IEnumerator<T> GetEnumerator() => Data.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

View File

@@ -0,0 +1,9 @@
namespace Polonium.DataStructures.PatchableItems;
public enum UpdateMethods
{
None = 0,
Update = 1,
Replace = 2,
Custom = 3,
}

View File

@@ -0,0 +1,6 @@
namespace Polonium.Interfaces;
public interface IKnowledge : IPatchableFrame
{
}

View File

@@ -0,0 +1,5 @@
namespace Polonium.Interfaces;
public interface IPatchableFrame
{
}

View File

@@ -1,9 +0,0 @@
using Godot;
namespace Polonium.Resources;
public abstract partial class ActionBody : Resource
{
public StringName ActionName { get; set; }
}

View File

@@ -0,0 +1,9 @@
using Polonium.Interfaces;
using Polonium.MessageManager;
namespace Polonium.Resources.FramePatches;
public abstract partial class FramePatch : PoloniumMessage
{
public abstract void Patch(IPatchableFrame receiver);
}

View File

@@ -0,0 +1,13 @@
using Polonium.Interfaces;
namespace Polonium.Resources.FramePatches;
public partial class FramePatchCollection : FramePatches.FramePatch
{
public HashSet<FramePatches.FramePatch> Updates { get; set; } = new();
public override void Patch(IPatchableFrame receiver)
{
foreach (FramePatches.FramePatch p in Updates)
p.Patch(receiver);
}
}

View File

@@ -0,0 +1,21 @@
namespace Polonium.Resources.FramePatches.Generic;
public abstract partial class DictionaryFramePatch<TKey, TValue> : FramePatch
{
public Dictionary<TKey, TValue> Updates { get; set; } = new ();
public Dictionary<TKey, TValue> Filter(HashSet<TKey> filter)
{
Dictionary<TKey, TValue> res = new();
foreach (TKey key in filter)
{
if (!Updates.ContainsKey(key))
continue;
res[key] = Updates[key];
}
return res;
}
}

View File

@@ -0,0 +1,7 @@
namespace Polonium.Resources.FramePatches.Generic;
public abstract partial class FramePatch<TUpdate> : FramePatch
{
public TUpdate Updates { get; set; } = default(TUpdate);
}

View File

@@ -0,0 +1,6 @@
namespace Polonium.Resources.FramePatches.Generic;
public abstract partial class HashSetFramePatch<TUpdate> : FramePatch
{
public HashSet<TUpdate> Updates { get; set; } = new ();
}

View File

@@ -0,0 +1,14 @@
using Polonium.Interfaces;
namespace Polonium.Resources.FramePatches;
public partial class IndexedFramePatchCollection<TKey> : FramePatches.FramePatch
{
public Dictionary<TKey, FramePatches.FramePatch> Updates { get; set; } = new();
public override void Patch(IPatchableFrame receiver)
{
foreach (FramePatches.FramePatch p in Updates.Values)
p.Patch(receiver);
}
}

View File

@@ -1,8 +0,0 @@
using Polonium.MessageManager;
namespace Polonium.Resources;
public abstract partial class KnowledgePatch : PoloniumMessage
{
}