From eabfbae92d460cf034af6847208b7aef3a9d1a49 Mon Sep 17 00:00:00 2001 From: "Nuno \"Omega Leo\" Diogo" Date: Wed, 3 Jul 2024 17:24:23 +0100 Subject: [PATCH 1/3] Fixed dependency --- OmegaLeo.HelperLib/Extensions/ArrayExtensions.cs | 2 +- OmegaLeo.HelperLib/OmegaLeo.HelperLib.csproj | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/OmegaLeo.HelperLib/Extensions/ArrayExtensions.cs b/OmegaLeo.HelperLib/Extensions/ArrayExtensions.cs index 00ad8a4..fc4a942 100644 --- a/OmegaLeo.HelperLib/Extensions/ArrayExtensions.cs +++ b/OmegaLeo.HelperLib/Extensions/ArrayExtensions.cs @@ -1,4 +1,4 @@ -using UnityFlow.DocumentationHelper.Library.Attributes; +using NetFlow.DocumentationHelper.Library.Attributes; namespace GameDevLibrary.Extensions { diff --git a/OmegaLeo.HelperLib/OmegaLeo.HelperLib.csproj b/OmegaLeo.HelperLib/OmegaLeo.HelperLib.csproj index 1e91962..cd876f5 100644 --- a/OmegaLeo.HelperLib/OmegaLeo.HelperLib.csproj +++ b/OmegaLeo.HelperLib/OmegaLeo.HelperLib.csproj @@ -7,10 +7,12 @@ 0.0.2 Omega Leo's Helper Library Nuno "Omega Leo" Diogo + https://github.com/omegaleo/HelperLib + https://github.com/omegaleo/HelperLib - + -- 2.52.0 From e6b57bb346f6a0aa1f186f761d250e60191d95ff Mon Sep 17 00:00:00 2001 From: "Nuno \"Omega Leo\" Diogo" Date: Wed, 3 Jul 2024 21:56:33 +0100 Subject: [PATCH 2/3] Updates to NeoDictionary --- OmegaLeo.HelperLib/Models/NeoDictionary.cs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/OmegaLeo.HelperLib/Models/NeoDictionary.cs b/OmegaLeo.HelperLib/Models/NeoDictionary.cs index af3ba14..12861fb 100644 --- a/OmegaLeo.HelperLib/Models/NeoDictionary.cs +++ b/OmegaLeo.HelperLib/Models/NeoDictionary.cs @@ -2,11 +2,13 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using NetFlow.DocumentationHelper.Library.Attributes; namespace GameDevLibrary.Models { // Inspiration: https://www.youtube.com/watch?v=x-ejym1WdjE [Serializable] + [Documentation("NeoDictionary", "Dictionary like class created to make it easier to display dictionaries in game engines like Unity")] public class NeoDictionary { public List> Items = new List>(); @@ -66,6 +68,28 @@ namespace GameDevLibrary.Models public bool Any() => Items.Any(); public bool Any(Func, bool> predicate) => Items.Any(predicate); + + public IEnumerable> Where(Func, bool> predicate) => + Items.Where(predicate); + + public NeoDictionaryItem? FirstOrDefault() => Items.FirstOrDefault(); + + public NeoDictionaryItem? FirstOrDefault(Func, bool> predicate) => + Items.FirstOrDefault(predicate); + + public NeoDictionaryItem? LastOrDefault() => Items.LastOrDefault(); + + public NeoDictionaryItem? LastOrDefault(Func, bool> predicate) => + Items.LastOrDefault(predicate); + + public void Remove(TKey key) + { + var index = Items.FindIndex(x => x.Key.Equals(key)); + + Items.RemoveAt(index); + } + + public void RemoveAt(int index) => Items.RemoveAt(index); } [Serializable] -- 2.52.0 From 5c9c75e5eaf7c3120645b694766cb2d5dbc89acd Mon Sep 17 00:00:00 2001 From: "Nuno \"Omega Leo\" Diogo" Date: Sat, 27 Jul 2024 10:50:18 +0100 Subject: [PATCH 3/3] Changes to NeoDictionary --- OmegaLeo.HelperLib/Models/NeoDictionary.cs | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/OmegaLeo.HelperLib/Models/NeoDictionary.cs b/OmegaLeo.HelperLib/Models/NeoDictionary.cs index 12861fb..fbcbec9 100644 --- a/OmegaLeo.HelperLib/Models/NeoDictionary.cs +++ b/OmegaLeo.HelperLib/Models/NeoDictionary.cs @@ -90,6 +90,54 @@ namespace GameDevLibrary.Models } public void RemoveAt(int index) => Items.RemoveAt(index); + + public void Replace(TKey key, TValue value) + { + if (HasKey(key)) + { + this[key] = value; + } + } + + public bool HasKey(TKey key) => Items.Any(x => x.Key.Equals(key)); + + public TValue this[TKey key] + { + get + { + if (Items == null) + { + Items = new List>(); + Items.Add(new NeoDictionaryItem(key, (TValue)Activator.CreateInstance(typeof(TValue)))); + } + + try + { + var value = Items.FirstOrDefault(x => EqualityComparer.Default.Equals(x.Key, key))!.Value; + + return value ?? (TValue)Activator.CreateInstance(typeof(TValue)); + } + catch (Exception e) + { + return (TValue)Activator.CreateInstance(typeof(TValue)); + } + } + set + { + if (HasKey(key)) + { + var item = Items.FirstOrDefault(x => EqualityComparer.Default.Equals(x.Key, key)); + var index = Items.IndexOf(item); + Items[index] = new NeoDictionaryItem(key, value); + } + else + { + Items.Add(new NeoDictionaryItem(key, value)); + } + } + } + + public void Clear() => Items.Clear(); } [Serializable] -- 2.52.0