add: Patchable items and frames
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
6
src/Attributes/AutoPatch.cs
Normal file
6
src/Attributes/AutoPatch.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Polonium.Attributes;
|
||||
[AttributeUsage(AttributeTargets.Interface)]
|
||||
public class AutoPatch : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
6
src/Attributes/PatchableProperty.cs
Normal file
6
src/Attributes/PatchableProperty.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Polonium.Attributes;
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class PatchableProperty : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
31
src/DataStructures/PatchableItems/PatchableDictionary.cs
Normal file
31
src/DataStructures/PatchableItems/PatchableDictionary.cs
Normal 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();
|
||||
}
|
||||
23
src/DataStructures/PatchableItems/PatchableHashSet.cs
Normal file
23
src/DataStructures/PatchableItems/PatchableHashSet.cs
Normal 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();
|
||||
}
|
||||
9
src/DataStructures/PatchableItems/UpdateMethods.cs
Normal file
9
src/DataStructures/PatchableItems/UpdateMethods.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Polonium.DataStructures.PatchableItems;
|
||||
|
||||
public enum UpdateMethods
|
||||
{
|
||||
None = 0,
|
||||
Update = 1,
|
||||
Replace = 2,
|
||||
Custom = 3,
|
||||
}
|
||||
6
src/Interfaces/IKnowledge.cs
Normal file
6
src/Interfaces/IKnowledge.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Polonium.Interfaces;
|
||||
|
||||
public interface IKnowledge : IPatchableFrame
|
||||
{
|
||||
|
||||
}
|
||||
5
src/Interfaces/IPatchableFrame.cs
Normal file
5
src/Interfaces/IPatchableFrame.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace Polonium.Interfaces;
|
||||
|
||||
public interface IPatchableFrame
|
||||
{
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace Polonium.Resources;
|
||||
|
||||
public abstract partial class ActionBody : Resource
|
||||
{
|
||||
public StringName ActionName { get; set; }
|
||||
|
||||
}
|
||||
9
src/Resources/FramePatches/FramePatch.cs
Normal file
9
src/Resources/FramePatches/FramePatch.cs
Normal 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);
|
||||
}
|
||||
13
src/Resources/FramePatches/FramePatchCollection.cs
Normal file
13
src/Resources/FramePatches/FramePatchCollection.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
21
src/Resources/FramePatches/Generic/DictionaryFramePatch.cs
Normal file
21
src/Resources/FramePatches/Generic/DictionaryFramePatch.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
7
src/Resources/FramePatches/Generic/FramePatch.cs
Normal file
7
src/Resources/FramePatches/Generic/FramePatch.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Polonium.Resources.FramePatches.Generic;
|
||||
|
||||
public abstract partial class FramePatch<TUpdate> : FramePatch
|
||||
{
|
||||
public TUpdate Updates { get; set; } = default(TUpdate);
|
||||
|
||||
}
|
||||
6
src/Resources/FramePatches/Generic/HashSetFramePatch.cs
Normal file
6
src/Resources/FramePatches/Generic/HashSetFramePatch.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Polonium.Resources.FramePatches.Generic;
|
||||
|
||||
public abstract partial class HashSetFramePatch<TUpdate> : FramePatch
|
||||
{
|
||||
public HashSet<TUpdate> Updates { get; set; } = new ();
|
||||
}
|
||||
14
src/Resources/FramePatches/IndexedFramePatchCollection.cs
Normal file
14
src/Resources/FramePatches/IndexedFramePatchCollection.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using Polonium.MessageManager;
|
||||
|
||||
namespace Polonium.Resources;
|
||||
|
||||
public abstract partial class KnowledgePatch : PoloniumMessage
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user