Merged branches

This commit is contained in:
2024-05-04 18:23:13 +01:00
15 changed files with 507 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
+91
View File
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="6b52b9f1-b404-4a10-9897-29dd4898988d" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/.idea.OmegaLeo.HelperLib/.idea/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/.idea.OmegaLeo.HelperLib/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/.idea.OmegaLeo.HelperLib/.idea/indexLayout.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/.idea.OmegaLeo.HelperLib/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/OmegaLeo.HelperLib.sln" afterDir="false" />
<change afterPath="$PROJECT_DIR$/OmegaLeo.HelperLib/Extensions/ArrayExtensions.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/OmegaLeo.HelperLib/OmegaLeo.HelperLib.csproj" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 1
}]]></component>
<component name="ProjectId" id="2fMhw8Y43gWIBw4kFtKrFbJT2JO" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_ADD_EXTERNAL_FILES": "true",
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "preferences.pluginManager",
"vue.rearranger.settings.migration": "true"
},
"keyToStringList": {
"rider.external.source.directories": [
"C:\\Users\\OmegaLeo\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache",
"C:\\Users\\OmegaLeo\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache",
"C:\\Users\\OmegaLeo\\AppData\\Local\\Symbols\\src"
]
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="6b52b9f1-b404-4a10-9897-29dd4898988d" name="Changes" comment="" />
<created>1713617089947</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1713617089947</updated>
<workItem from="1713617091068" duration="2145000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
</component>
</project>
+13
View File
@@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/modules.xml
/.idea.GameDevLibrary.iml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+1
View File
@@ -0,0 +1 @@
OmegaLeo.HelperLib
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+16
View File
@@ -0,0 +1,16 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmegaLeo.HelperLib", "OmegaLeo.HelperLib\OmegaLeo.HelperLib.csproj", "{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
@@ -0,0 +1,19 @@
using UnityFlow.DocumentationHelper.Library.Attributes;
namespace GameDevLibrary.Extensions
{
[Documentation("Array Extensions", "Set of extension methods to help with Arrays.")]
public static class ArrayExtensions
{
// Idea obtained from TaroDev's video on things to do in Unity - https://youtu.be/Ic5ux-tpkCE?t=302
[Documentation("Next", @"Method to obtain the next object in the array by passing the current index.
Note: Idea obtained from TaroDev's video on things to do in Unity - https://youtu.be/Ic5ux-tpkCE?t=302", new []
{
"CurrentIndex - The index we're currently on inside the array passed as reference so we can automatically assign to it the next index"
})]
public static T Next<T>(this T[] array, ref int currentIndex)
{
return array[currentIndex++ % array.Length];
}
}
}
@@ -0,0 +1,17 @@
using System;
namespace GameDevLibrary.Extensions
{
public static class FloatExtensions
{
public static float Round(this float value, int digits = 2)
{
return MathF.Round(value, digits);
}
public static int RoundToInt(this float value)
{
return (int)value.Round(0);
}
}
}
@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace GameDevLibrary.Extensions
{
public static class IListExtensions
{
/// <summary>
/// Swaps the position of 2 elements inside of a List
/// </summary>
/// <param name="list"></param>
/// <param name="indexA"></param>
/// <param name="indexB"></param>
/// <typeparam name="T"></typeparam>
/// <returns>List with swapped elements</returns>
public static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB)
{
(list[indexA], list[indexB]) = (list[indexB], list[indexA]);
return list;
}
/// <summary>
/// Swaps the position of 2 elements inside of a List
/// </summary>
/// <param name="list"></param>
/// <param name="itemA"></param>
/// <param name="itemB"></param>
/// <typeparam name="T"></typeparam>
/// <returns>List with swapped elements</returns>
public static IList<T> Swap<T>(this IList<T> list, T itemA, T itemB)
{
return list.Swap(list.IndexOf(itemA), list.IndexOf(itemB));
}
/// <summary>
/// Replace an element inside a list with a different element
/// </summary>
/// <param name="list"></param>
/// <param name="originalValue"></param>
/// <param name="valueToReplace"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static IList<T> Replace<T>(this IList<T> list, T originalValue, T valueToReplace)
{
var index = list.IndexOf(originalValue);
if (index != -1)
{
list[index] = valueToReplace;
}
return list;
}
/// <summary>
/// Method to obtain a random element from inside a list
/// </summary>
/// <param name="list"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T Random<T>(this IList<T> list)
{
if (list.Count == 0) return default;
// Updated based on Robin King's tip about random items https://twitter.com/quoxel/status/1729137730607841755/photo/1
int seed = (int)DateTime.Now.Ticks;
var r = new Random(seed);
var randomIndex = r.Next(0, list.Count);
var returnValue = list[randomIndex];
return returnValue ?? list[0];
}
/// <summary>
/// Method to obtain <paramref name="count"/> elements from inside a list
/// </summary>
/// <param name="list"></param>
/// <param name="count"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static List<T> Random<T>(this IList<T> list, int count = 1)
{
if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count));
List<T> values = new List<T>();
for (int i = 0; i < count; i++)
{
values.Add(list.Where(x => !values.Contains(x)).ToList().Random());
}
return values;
}
public static IEnumerable<TSource> DistinctBy<TSource, TKey>
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
// Idea obtained from TaroDev's video on things to do in Unity - https://youtu.be/Ic5ux-tpkCE?t=302
public static T Next<T>(this List<T> array, ref int currentIndex)
{
return array[currentIndex++ % array.Count];
}
}
}
@@ -0,0 +1,38 @@
using System.Collections.Generic;
using System.Linq;
namespace GameDevLibrary.Extensions
{
public static class MathExtensions
{
/// <summary>
/// Calculate the average value based on a list of values
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public static int AverageWithNullValidation(this IEnumerable<int> list)
{
return list.Any() ? (int)list.Average() : 0;
}
/// <summary>
/// Calculate the average value based on a list of values
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public static double AverageWithNullValidation(this IEnumerable<double> list)
{
return list.Any() ? list.Average() : 0.0;
}
/// <summary>
/// Calculate the average value based on a list of values
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public static float AverageWithNullValidation(this IEnumerable<float> list)
{
return list.Any() ? list.Average() : 0.0f;
}
}
}
@@ -0,0 +1,69 @@
using System;
namespace GameDevLibrary.Extensions
{
public static class StringExtensions
{
/// <summary>
/// Cut off a string once it reaches a <paramref name="maxChars"/> amount of characters and add '...' to the end of the string
/// </summary>
/// <param name="value"></param>
/// <param name="maxChars"></param>
/// <returns></returns>
public static string Truncate(this string value, int maxChars)
{
return value.Length <= maxChars ? value : value.Substring(0, maxChars) + "...";
}
/// <summary>
/// Identify if a string is null or empty
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool IsNullOrEmpty(this string str)
{
return String.IsNullOrEmpty(str);
}
/// <summary>
/// Identify if a string is <b>not</b> null or empty
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool IsNotNullOrEmpty(this string str)
{
return !str.IsNullOrEmpty();
}
/// <summary>
/// Check if the string matches any of the search parameters
/// </summary>
/// <param name="str"></param>
/// <param name="search"></param>
/// <returns></returns>
public static bool AnyMatch(this string str, params string[] search)
{
foreach (string s in search)
{
if (s.Equals(str, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
/// <summary>
/// Reverses a given string
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Reverse(this string str)
{
char[] charArray = str.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
}
}
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace GameDevLibrary.Models
{
// Inspiration: https://www.youtube.com/watch?v=x-ejym1WdjE
[Serializable]
public class NeoDictionary<TKey,TValue>
{
public List<NeoDictionaryItem<TKey, TValue>> Items = new List<NeoDictionaryItem<TKey, TValue>>();
public Dictionary<TKey, TValue> ToDictionary() => (Items.Any())
? Items.ToDictionary(x => x.Key, x => x.Value)
: new Dictionary<TKey, TValue>();
public bool TryGetValue(TKey key, out TValue value)
{
var item = Items.FirstOrDefault(x => x.Key.Equals(key));
if (item != null)
{
value = item.Value;
return true;
}
value = default;
return false;
}
public bool TryGetValueFromIndex(int index, out TValue value)
{
if (index < Items.Count)
{
var item = Items[index];
if (item != null)
{
value = item.Value;
return true;
}
}
value = default;
return false;
}
public void Add(TKey key, TValue value)
{
Items.Add(new NeoDictionaryItem<TKey, TValue>(key, value));
}
public void AddRange(NeoDictionary<TKey, TValue> values)
{
Items.AddRange(values.Items);
}
public void AddRange(IEnumerable<NeoDictionaryItem<TKey, TValue>> values)
{
Items.AddRange(values);
}
public bool Any() => Items.Any();
public bool Any(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) => Items.Any(predicate);
}
[Serializable]
public class NeoDictionaryItem<TKey,TValue>
{
public TKey Key;
public TValue Value;
public NeoDictionaryItem(TKey key, TValue value)
{
Key = key;
Value = value;
}
}
}
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>GameDevLibrary</RootNamespace>
<Version>0.0.2</Version>
<Title>Omega Leo's Helper Library</Title>
<Authors>Nuno "Omega Leo" Diogo</Authors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="UnityFlow.DocumentationHelper.Library" Version="1.1.2" />
</ItemGroup>
</Project>