Dev #7

Merged
omegaleo merged 47 commits from dev into main 2025-12-23 16:46:44 +00:00
13 changed files with 103 additions and 11 deletions
Showing only changes of commit 9fb87079a3 - Show all commits
@@ -25,7 +25,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.2" />
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.3" />
</ItemGroup>
</Project>
@@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\OmegaLeo.HelperLib.Changelog\OmegaLeo.HelperLib.Changelog.csproj" />
<ProjectReference Include="..\OmegaLeo.HelperLib.Game\OmegaLeo.HelperLib.Game.csproj" />
<ProjectReference Include="..\OmegaLeo.HelperLib\OmegaLeo.HelperLib.csproj" />
</ItemGroup>
@@ -14,6 +14,7 @@ var changelogs = new Dictionary<string, Assembly>()
{
{Path.Join(root, "OmegaLeo.HelperLib.Changelog", "CHANGELOG.md"), typeof(Changelog).Assembly},
{Path.Join(root, "OmegaLeo.HelperLib", "CHANGELOG.md"), typeof(BenchmarkUtility).Assembly},
{Path.Join(root, "OmegaLeo.HelperLib.Game", "CHANGELOG.md"), typeof(OmegaLeo.HelperLib.Game.Models.ConsoleCommand).Assembly},
};
foreach (var changelog in changelogs)
@@ -1,10 +1,21 @@
using System.Collections.Generic;
using NetFlow.DocumentationHelper.Library.Attributes;
using OmegaLeo.HelperLib.Game.Models;
namespace OmegaLeo.HelperLib.Game.Extensions
{
public static class ListExtensions
{
[Documentation(nameof(Shuffle),
"Shuffles the elements of the list in place using the provided RandomNumberGenerator.",
null,
@"```csharp
var list = new List<int> { 1, 2, 3, 4};
var rng = new RandomNumberGenerator();
// List before: [1, 2, 3, 4]
list.Shuffle(rng);
// List after: [3, 1, 4, 2] (example output)
```")]
public static void Shuffle<T>(this IList<T> list, RandomNumberGenerator rng)
{
for (int i = list.Count - 1; i > 0; i--)
@@ -1,7 +1,12 @@
using NetFlow.DocumentationHelper.Library.Attributes;
using OmegaLeo.HelperLib.Game.Models;
namespace OmegaLeo.HelperLib.Game.Handlers
{
[Documentation(nameof(DelayedActionHandler), "Handler for managing delayed actions, allowing cancellation and status checking.", null, @"```csharp
var action = new DelayedAction(...);
var handler = new DelayedActionHandler(action);
```")]
public class DelayedActionHandler
{
private readonly DelayedAction _action;
@@ -11,6 +16,9 @@ namespace OmegaLeo.HelperLib.Game.Handlers
_action = action;
}
[Documentation(nameof(Cancel), "Cancels the delayed action if it has not yet executed.", null, @"```csharp
handler.Cancel();
```")]
public void Cancel()
{
if (_action != null)
@@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.30.0"/>
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.2"/>
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.3" />
</ItemGroup>
<ItemGroup>
@@ -15,7 +15,8 @@
<ItemGroup>
<PackageReference Include="Markdig" Version="0.40.0" />
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.2" />
<PackageReference Include="MarkdigExtensions.SyntaxHighlighting" Version="1.0.3" />
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.3" />
</ItemGroup>
</Project>
@@ -1,8 +1,16 @@
@* File: `OmegaLeo.HelperLib.Web/Views/Home/Library.cshtml` *@
@using ColorCode.Styling
@using GameDevLibrary.Extensions
@using Markdig
@model OmegaLeo.HelperLib.Web.Models.LibraryDocumentationViewModel
@{
ViewData["Title"] = Model.LibraryName;
var groupedByNamespace = Model.Documentation.GroupBy(d => d.AssemblyName).OrderBy(g => g.Key);
var pipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.UseSyntaxHighlighting(StyleDictionary.DefaultDark)
.Build();
}
<div class="container-fluid mt-4">
@@ -75,7 +83,14 @@
{
<tr>
<td><code>@desc.Title</code></td>
<td>@Html.Raw(desc.Description)</td>
<td>@Html.Raw(desc.Description)<br/>
@if (desc.CodeExample.IsNotNullOrEmpty())
{
<strong>Example:</strong><br/>
<div class="example-code mb-2">
@Html.Raw(Markdig.Markdown.ToHtml(desc.CodeExample, pipeline))
</div>
}</td>
</tr>
}
</tbody>
@@ -34,6 +34,14 @@
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Library" asp-route-id="game">Game Dev</a>
</li>
</ul>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="https://github.com/omegaleo/HelperLib" target="_blank" rel="noopener noreferrer" aria-label="GitHub repository">
<i class="bi bi-github" style="font-size:1.25rem;"></i> View on Github
</a>
</li>
</ul>
</div>
</div>
</nav>
@@ -42,12 +50,6 @@
@RenderBody()
</main>
<footer class="border-top footer text-muted">
<div class="container">
&copy; @DateTime.Now.Year - OmegaLeo Helper Libraries
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@@ -19,4 +19,22 @@ html {
body {
margin-bottom: 60px;
}
pre {
overflow: auto;
padding: 1rem;
background-color: #495057;
position: relative;
color: #f2f2f2;
}
code {
background-color: transparent !important;
}
.example-code > div {
border-radius: 0.5rem !important;
background-color: #495057 !important;
}
+1
View File
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADocumentationDescription_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fhome_003Fomegaleo_003F_002Econfig_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe7ce68ea4d3540e4bc8ef1bd962ca30b3a00_003F46_003F1f9d3ace_003FDocumentationDescription_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fhome_003Fomegaleo_003F_002Econfig_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fbf9021a960b74107a7e141aa06bc9d8a0a53c929178c2fb95b1597be8af8dc_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMonitor_002ECoreCLR_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fhome_003Fomegaleo_003F_002Econfig_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FSourcesCache_003F9ee76fb4aded5e9da6e66cc2dcb127fac08d3ec5ac84fc6db9d4ee1d2e38_003FMonitor_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASafeFileHandle_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fhome_003Fomegaleo_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fc21672d0d37542808f219d7d1f059dc1b2e000_003Faf_003Fbed3a9b4_003FSafeFileHandle_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
@@ -1,14 +1,22 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using NetFlow.DocumentationHelper.Library.Attributes;
namespace GameDevLibrary.Helpers
{
[Documentation(nameof(BenchmarkUtility), "Utility class for benchmarking code execution time.", null, @"```csharp
BenchmarkUtility.Start(""MyBenchmark"");
// Code to benchmark
BenchmarkUtility.Stop(""MyBenchmark"");
var results = BenchmarkUtility.GetResults(""MyBenchmark"");
```")]
public class BenchmarkUtility
{
private static Dictionary<string, List<long>> _benchmarks = new Dictionary<string, List<long>>();
private static Dictionary<string, Stopwatch> _stopwatches = new Dictionary<string, Stopwatch>();
[Documentation("GetStopwatch", "Retrieves or creates a Stopwatch instance for the given key.", null, null)]
private static Stopwatch GetStopwatch(string key)
{
Stopwatch stopwatch;
@@ -22,6 +30,14 @@ namespace GameDevLibrary.Helpers
return stopwatch;
}
[Documentation("Record", "Records the execution time of the provided action and returns the elapsed time in milliseconds.", null, @"```csharp
var time = BenchmarkUtility.Record(() =>
{
// Code to benchmark
});
Console.WriteLine($""Elapsed time: {time} ms"");
```")]
public static long Record(Action actionToRecord)
{
var stopwatch = new Stopwatch();
@@ -33,6 +49,19 @@ namespace GameDevLibrary.Helpers
return stopwatch.ElapsedMilliseconds;
}
[Documentation("RecordAndSaveToResults", "Records the execution time of the provided action, saves it under the given key, and returns the elapsed time in milliseconds.", null, @"```csharp
var time = BenchmarkUtility.RecordAndSaveToResults(""MyBenchmark"", () =>
{
// Code to benchmark
});
Console.WriteLine($""Elapsed time: {time} ms"");
var results = BenchmarkUtility.GetResults(""MyBenchmark"");
var averageTime = results.Average();
Console.WriteLine($""Average time: {averageTime} ms"");
```")]
public static long RecordAndSaveToResults(string key, Action actionToRecord)
{
var stopwatch = new Stopwatch();
@@ -52,11 +81,13 @@ namespace GameDevLibrary.Helpers
return stopwatch.ElapsedMilliseconds;
}
[Documentation("Start", "Starts or restarts the stopwatch for the given key.", null, null)]
public static void Start(string key)
{
GetStopwatch(key).Restart();
}
[Documentation("Stop", "Stops the stopwatch for the given key and records the elapsed time.", null, null)]
public static void Stop(string key)
{
if (!_benchmarks.ContainsKey(key))
@@ -68,16 +99,19 @@ namespace GameDevLibrary.Helpers
_benchmarks[key].Add(GetStopwatch(key).ElapsedMilliseconds);
}
[Documentation("GetResults", "Retrieves the list of recorded times for the given key.", null, null)]
public static List<long> GetResults(string key)
{
return _benchmarks.ContainsKey(key) ? _benchmarks[key] : new List<long>();
}
[Documentation("ClearResults", "Clears all recorded benchmark results.", null, null)]
public static void ClearResults()
{
_benchmarks.Clear();
}
[Documentation("GetAllResults", "Retrieves all recorded benchmark results.", null, null)]
public static Dictionary<string, List<long>> GetAllResults()
{
return new Dictionary<string, List<long>>(_benchmarks);
+1 -1
View File
@@ -14,7 +14,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.2" />
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.3" />
</ItemGroup>
<ItemGroup>