Dev Improvements (#4)
* Fixed dependency * Updates to NeoDictionary * Changes to NeoDictionary * Started working on a Git implementation to integrate into Game Engines in the future * Added commit functionality to the git library * New changes * Added select for NeoDictionary.cs * Fixed issue with previous new method * Added a Benchmarking Tool to be used mostly in game engines * Added IndexOf to NeoDictionary.cs * Added new method for BenchmarkUtility.cs * added an instacedobject class * Added a new shuffle method for lists * fixed return type * Added new Changelog generator * Added new Game logic library to assist with game projects * Added Web Project * Added Nuget package configs * Add workflow for publishing game library NuGet package * Add README for OmegaLeo's Helper Library * Updated Website to reflect all libraries * Fixed missing library in Changelog * Added Contributing and Code of Conduct
This commit was merged in pull request #4.
This commit is contained in:
@@ -11,12 +11,9 @@ namespace GameDevLibrary.Helpers
|
||||
|
||||
private static Stopwatch GetStopwatch(string key)
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
Stopwatch stopwatch;
|
||||
|
||||
if (_stopwatches.TryGetValue(key, out stopwatch))
|
||||
{
|
||||
}
|
||||
else
|
||||
if (!_stopwatches.TryGetValue(key, out stopwatch))
|
||||
{
|
||||
stopwatch = new Stopwatch();
|
||||
_stopwatches.Add(key, stopwatch);
|
||||
|
||||
@@ -17,6 +17,11 @@ namespace GameDevLibrary.Models
|
||||
? Items.ToDictionary(x => x.Key, x => x.Value)
|
||||
: new Dictionary<TKey, TValue>();
|
||||
|
||||
public static implicit operator Dictionary<TKey, TValue>(NeoDictionary<TKey, TValue> dict) => (dict.Items.Any())
|
||||
? dict.Items.ToDictionary(x => x.Key, x => x.Value)
|
||||
: new Dictionary<TKey, TValue>();
|
||||
|
||||
[Documentation("TryGetValue", "Tries to get the value from the NeoDictionary for the given key.")]
|
||||
public bool TryGetValue(TKey key, out TValue value)
|
||||
{
|
||||
var item = Items.FirstOrDefault(x => x.Key.Equals(key));
|
||||
@@ -32,6 +37,7 @@ namespace GameDevLibrary.Models
|
||||
return false;
|
||||
}
|
||||
|
||||
[Documentation("TryGetValueFromIndex", "Tries to get the value from the NeoDictionary at the given index.")]
|
||||
public bool TryGetValueFromIndex(int index, out TValue value)
|
||||
{
|
||||
if (index < Items.Count)
|
||||
@@ -50,44 +56,57 @@ namespace GameDevLibrary.Models
|
||||
return false;
|
||||
}
|
||||
|
||||
[Documentation("Add", "Adds a new NeoDictionaryItem to the NeoDictionary.")]
|
||||
public void Add(TKey key, TValue value)
|
||||
{
|
||||
Items.Add(new NeoDictionaryItem<TKey, TValue>(key, value));
|
||||
}
|
||||
|
||||
[Documentation("AddRange", "Adds a range of NeoDictionaryItems from another NeoDictionary to the NeoDictionary.")]
|
||||
public void AddRange(NeoDictionary<TKey, TValue> values)
|
||||
{
|
||||
Items.AddRange(values.Items);
|
||||
}
|
||||
|
||||
[Documentation("AddRange", "Adds a range of NeoDictionaryItems to the NeoDictionary.")]
|
||||
public void AddRange(IEnumerable<NeoDictionaryItem<TKey, TValue>> values)
|
||||
{
|
||||
Items.AddRange(values);
|
||||
}
|
||||
|
||||
[Documentation("Any", "Checks if the NeoDictionary has any items.")]
|
||||
public bool Any() => Items.Any();
|
||||
|
||||
[Documentation("Any", "Checks if any item in the NeoDictionary satisfies a condition.")]
|
||||
public bool Any(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) => Items.Any(predicate);
|
||||
|
||||
[Documentation("Where", "Filters the NeoDictionary items based on a predicate.")]
|
||||
public IEnumerable<NeoDictionaryItem<TKey, TValue>> Where(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) =>
|
||||
Items.Where(predicate);
|
||||
|
||||
[Documentation("FirstOrDefault", "Returns the first item of the NeoDictionary or a default value if the NeoDictionary is empty.")]
|
||||
public NeoDictionaryItem<TKey, TValue>? FirstOrDefault() => Items.FirstOrDefault();
|
||||
|
||||
[Documentation("FirstOrDefault", "Returns the first item of the NeoDictionary that satisfies a condition or a default value if no such item is found.")]
|
||||
public NeoDictionaryItem<TKey, TValue>? FirstOrDefault(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) =>
|
||||
Items.FirstOrDefault(predicate);
|
||||
|
||||
[Documentation("LastOrDefault", "Returns the last item of the NeoDictionary or a default value if the NeoDictionary is empty.")]
|
||||
public NeoDictionaryItem<TKey, TValue>? LastOrDefault() => Items.LastOrDefault();
|
||||
|
||||
[Documentation("LastOrDefault", "Returns the last item of the NeoDictionary that satisfies a condition or a default value if no such item is found.")]
|
||||
public NeoDictionaryItem<TKey, TValue>? LastOrDefault(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) =>
|
||||
Items.LastOrDefault(predicate);
|
||||
|
||||
[Documentation("Select", "Projects each item of the NeoDictionary into a new form.")]
|
||||
public IEnumerable<NeoDictionaryItem<TKey, TValue>> Select(Func<NeoDictionaryItem<TKey, TValue>, NeoDictionaryItem<TKey, TValue>> selector) =>
|
||||
Items.Select(selector);
|
||||
|
||||
[Documentation("IndexOf", "Returns the index of the given NeoDictionaryItem.")]
|
||||
public int IndexOf(NeoDictionaryItem<TKey, TValue> selector) =>
|
||||
Items.IndexOf(selector);
|
||||
|
||||
[Documentation("Remove", "Removes the item with the given key.")]
|
||||
public void Remove(TKey key)
|
||||
{
|
||||
var index = Items.FindIndex(x => x.Key.Equals(key));
|
||||
@@ -95,8 +114,10 @@ namespace GameDevLibrary.Models
|
||||
Items.RemoveAt(index);
|
||||
}
|
||||
|
||||
[Documentation("RemoveAt", "Removes the item at the given index.")]
|
||||
public void RemoveAt(int index) => Items.RemoveAt(index);
|
||||
|
||||
[Documentation("Replace", "Replaces the value for the given key if it exists.")]
|
||||
public void Replace(TKey key, TValue value)
|
||||
{
|
||||
if (HasKey(key))
|
||||
@@ -105,6 +126,7 @@ namespace GameDevLibrary.Models
|
||||
}
|
||||
}
|
||||
|
||||
[Documentation("HasKey", "Checks if the NeoDictionary contains the given key.")]
|
||||
public bool HasKey(TKey key) => Items.Any(x => x.Key.Equals(key));
|
||||
|
||||
public TValue this[TKey key]
|
||||
@@ -143,7 +165,93 @@ namespace GameDevLibrary.Models
|
||||
}
|
||||
}
|
||||
|
||||
public NeoDictionaryItem<TKey, TValue> this[int index]
|
||||
{
|
||||
get => Items[index];
|
||||
set => Items[index] = value;
|
||||
}
|
||||
|
||||
[Documentation("Clear", "Clears all items from the NeoDictionary.")]
|
||||
public void Clear() => Items.Clear();
|
||||
|
||||
[Documentation("Sort", "Sorts the NeoDictionary items using the given comparison.")]
|
||||
public void Sort(Comparison<NeoDictionaryItem<TKey, TValue>> comparison) => Items.Sort(comparison);
|
||||
|
||||
[Documentation("Count", "Returns the number of items in the NeoDictionary.")]
|
||||
public int Count() => Items.Count;
|
||||
|
||||
[Documentation("ForEach", "Performs the given action on each item in the NeoDictionary.")]
|
||||
public void ForEach(Action<NeoDictionaryItem<TKey, TValue>> action) => Items.ForEach(action);
|
||||
|
||||
[Documentation("ToList", "Converts the NeoDictionary items to a List.")]
|
||||
public List<NeoDictionaryItem<TKey, TValue>> ToList() => Items.ToList();
|
||||
|
||||
[Documentation("Clone", "Creates a shallow copy of the NeoDictionary.")]
|
||||
public NeoDictionary<TKey, TValue> Clone()
|
||||
{
|
||||
var newDict = new NeoDictionary<TKey, TValue>();
|
||||
newDict.Items = new List<NeoDictionaryItem<TKey, TValue>>(Items);
|
||||
return newDict;
|
||||
}
|
||||
|
||||
[Documentation("Reverse", "Reverses the order of the items in the NeoDictionary.")]
|
||||
public void Reverse() => Items.Reverse();
|
||||
|
||||
[Documentation("Insert", "Inserts an item at the given index.")]
|
||||
public void Insert(int index, TKey key, TValue value) =>
|
||||
Items.Insert(index, new NeoDictionaryItem<TKey, TValue>(key, value));
|
||||
|
||||
[Documentation("InsertRange", "Inserts a range of items starting from the given index.")]
|
||||
public void InsertRange(int index, IEnumerable<NeoDictionaryItem<TKey, TValue>> values) =>
|
||||
Items.InsertRange(index, values);
|
||||
|
||||
[Documentation("RemoveRange", "Removes a range of items starting from the given index.")]
|
||||
public void RemoveRange(int index, int count) =>
|
||||
Items.RemoveRange(index, count);
|
||||
|
||||
[Documentation("RemoveAll", "Removes all items matching the given predicate.")]
|
||||
public void RemoveAll(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) =>
|
||||
Items.RemoveAll(new Predicate<NeoDictionaryItem<TKey, TValue>>(predicate));
|
||||
|
||||
[Documentation("FindIndex", "Finds the index of the first item matching the given predicate.")]
|
||||
public int FindIndex(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) =>
|
||||
Items.FindIndex(new Predicate<NeoDictionaryItem<TKey, TValue>>(predicate));
|
||||
|
||||
[Documentation("Find", "Finds the first item matching the given predicate.")]
|
||||
public NeoDictionaryItem<TKey, TValue> Find(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) =>
|
||||
Items.Find(new Predicate<NeoDictionaryItem<TKey, TValue>>(predicate));
|
||||
|
||||
[Documentation("FindAll", "Finds all items matching the given predicate.")]
|
||||
public IEnumerable<NeoDictionaryItem<TKey, TValue>> FindAll(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) =>
|
||||
Items.FindAll(new Predicate<NeoDictionaryItem<TKey, TValue>>(predicate));
|
||||
|
||||
[Documentation("Merge", "Merges another NeoDictionary into this one, ignoring duplicate keys.")]
|
||||
public void Merge(NeoDictionary<TKey, TValue> other)
|
||||
{
|
||||
foreach (var item in other.Items)
|
||||
{
|
||||
if (!HasKey(item.Key))
|
||||
{
|
||||
Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Documentation("ToDictionarySafe", "Converts the NeoDictionary to a standard Dictionary while safely handling duplicate keys by ignoring them.")]
|
||||
public Dictionary<TKey, TValue> ToDictionarySafe()
|
||||
{
|
||||
var dict = new Dictionary<TKey, TValue>();
|
||||
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (!dict.ContainsKey(item.Key))
|
||||
{
|
||||
dict.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageProjectUrl>https://github.com/omegaleo/HelperLib</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/omegaleo/HelperLib</RepositoryUrl>
|
||||
<PackageLicenseUrl>https://github.com/omegaleo/HelperLib/blob/main/LICENSE</PackageLicenseUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user