Skip to content

Commit

Permalink
net8.0 upgrade
Browse files Browse the repository at this point in the history
- upgraded .net version of all projects
- upgraded all nuget packages to latest versions
- added some extra test cases
- small api changes required for .net 8
- added nerdbank gitversioning for assembly version management
- corrected classification of all projects for <IsPackable>
- added a github workflow to pack all packable projects and publish them to nuget.org
- started work on a custom client, it's in the baby stages atm
  • Loading branch information
Sichii committed Dec 11, 2023
1 parent bf1b1bb commit 4b8c245
Show file tree
Hide file tree
Showing 28 changed files with 377 additions and 70 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ name: Build and Publish to NuGet
on:
push:
branches:
- release/v*
- stop
pull_request:
branches:
- release/v*
- stop

jobs:
build-and-publish:
if: github.repository == 'Sichii/Chaos-Server'
runs-on: windows-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x' # Set your .NET Core version here
Expand All @@ -25,5 +23,5 @@ jobs:

- name: Publish to NuGet
run: |
dotnet nuget push "nupkgs/**/*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push "nupkgs/**/*.snupkg" --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push "nupkgs/**/*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
dotnet nuget push "nupkgs/**/*.snupkg" --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
1 change: 1 addition & 0 deletions Chaos.Client/Chaos.Client/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Chaos.Client.Controls;

namespace Chaos.Client;

Expand Down
14 changes: 7 additions & 7 deletions Chaos.Client/Chaos.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ namespace Chaos.Client;

internal class Program
{
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseSkia();

// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
=> BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseSkia();
}
4 changes: 2 additions & 2 deletions Chaos.Client/Chaos.Client/Rendering/RenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class RenderContext
{
private static readonly IMemoryCache MemoryCache = new MemoryCache(new MemoryCacheOptions());

public static RenderContext Instance { get; } = new();

private RenderContext() { }

public static RenderContext Instance { get; } = new();
}
23 changes: 5 additions & 18 deletions Chaos.Common/Collections/ArgumentCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public ArgumentCollection(IEnumerable<string>? arguments, string? delimiter = nu
arguments ??= Enumerable.Empty<string>();

if (!string.IsNullOrEmpty(delimiter))
arguments = arguments.SelectMany(str => str.Split(delimiter))
.ToList();
arguments = arguments.SelectMany(str => str.Split(delimiter)).ToList();

Arguments = arguments.ToList();
}
Expand All @@ -49,9 +48,7 @@ public ArgumentCollection(string argumentStr)
{
Arguments = new List<string>();

foreach (var match in RegexCache.COMMAND_SPLIT_REGEX
.Matches(argumentStr)
.OfType<Match>())
foreach (var match in RegexCache.COMMAND_SPLIT_REGEX.Matches(argumentStr).OfType<Match>())
{
if (!match.Success)
continue;
Expand All @@ -67,9 +64,7 @@ public ArgumentCollection(string argumentStr)
/// </summary>
/// <param name="argumentStr">A string containing arguments</param>
/// <param name="delimiter">The delimiter used to split the strings into arguments</param>
public ArgumentCollection(string argumentStr, string delimiter)
=> Arguments = argumentStr.Split(delimiter)
.ToList();
public ArgumentCollection(string argumentStr, string delimiter) => Arguments = argumentStr.Split(delimiter).ToList();

/// <summary>
/// Creates an empty <see cref="ArgumentCollection" />
Expand Down Expand Up @@ -103,13 +98,7 @@ public void Add(IEnumerable<string> arguments, string? delimiter = null)
/// <param name="argument">A string containing arguments</param>
/// <param name="delimiter">The delimiter used to split the strings into arguments</param>
[ExcludeFromCodeCoverage(Justification = "Nothing to test, just a shorthand")]
public void Add(string argument, string? delimiter)
=> Add(
new[]
{
argument
},
delimiter);
public void Add(string argument, string? delimiter) => Add(new[] { argument }, delimiter);

/// <summary>
/// Adds a string or argument to the end of the collection. The string will be parsed for arguments using the " " as a
Expand All @@ -119,9 +108,7 @@ public void Add(string argument, string? delimiter)
/// <param name="argument">A string containing arguments</param>
public void Add(string argument)
{
foreach (var match in RegexCache.COMMAND_SPLIT_REGEX
.Matches(argument)
.OfType<Match>())
foreach (var match in RegexCache.COMMAND_SPLIT_REGEX.Matches(argument).OfType<Match>())
{
if (!match.Success)
continue;
Expand Down
8 changes: 4 additions & 4 deletions Chaos.Common/Utilities/IntegerRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public static class IntegerRandomizer
/// <typeparam name="T">The type of object to return</typeparam>
/// <returns>A random element from the specified collection if a choice is taken, otherwise <c>default</c></returns>
[ExcludeFromCodeCoverage(Justification = "Tested by PickRandomWeightedSingleOrDefault<T>(ICollection<KeyValuePair<T, int>>)")]
public static T? PickRandomWeightedSingleOrDefault<T>(this IEnumerable<T> choices, IEnumerable<int> weights)
=> choices.Zip(weights, (choice, weight) => new KeyValuePair<T, int>(choice, weight))
.ToList()
.PickRandomWeightedSingleOrDefault();
public static T? PickRandomWeightedSingleOrDefault<T>(this IEnumerable<T> choices, IEnumerable<int> weights) =>
choices.Zip(weights, (choice, weight) => new KeyValuePair<T, int>(choice, weight))
.ToList()
.PickRandomWeightedSingleOrDefault();

/// <summary>
/// Randomly determins if a roll is successful or not.
Expand Down
1 change: 1 addition & 0 deletions Chaos.Extensions.Common/InterlockedObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Chaos.Common.Abstractions;

namespace Chaos.Extensions.Common;

Expand Down
8 changes: 6 additions & 2 deletions Chaos.Extensions.Common/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Chaos.Common.Abstractions;
using Chaos.Common.Services;
using Microsoft.Extensions.DependencyInjection;

namespace Chaos.Extensions.Common;

Expand All @@ -15,7 +17,8 @@ public static class ServiceCollectionExtensions
/// <param name="argTypes">A collection of types required to construct an instance</param>
/// <typeparam name="T">The type to create</typeparam>
[ExcludeFromCodeCoverage(Justification = "Nothing to test, just a shorthand")]
public static IServiceCollection AddSimpleFactory<T>(this IServiceCollection services, params Type[] argTypes) where T: class
public static IServiceCollection AddSimpleFactory<T>(this IServiceCollection services, params Type[] argTypes)
where T: class
{
var runtimeFactory = ActivatorUtilities.CreateFactory(typeof(T), argTypes);
services.AddSingleton<IFactory<T>, Factory<T>>(sp => new Factory<T>(sp, runtimeFactory));
Expand All @@ -31,7 +34,8 @@ public static IServiceCollection AddSimpleFactory<T>(this IServiceCollection ser
/// <typeparam name="T">The type of the service to return</typeparam>
/// <typeparam name="TImpl">The implementation type of the service to create</typeparam>
[ExcludeFromCodeCoverage(Justification = "Nothing to test, just a shorthand")]
public static IServiceCollection AddSimpleFactory<T, TImpl>(this IServiceCollection services, params Type[] argTypes) where T: class
public static IServiceCollection AddSimpleFactory<T, TImpl>(this IServiceCollection services, params Type[] argTypes)
where T: class
{
var runtimeFactory = ActivatorUtilities.CreateFactory(typeof(TImpl), argTypes);
services.AddSingleton<IFactory<T>, Factory<T>>(sp => new Factory<T>(sp, runtimeFactory));
Expand Down
44 changes: 20 additions & 24 deletions Chaos/Collections/MapEntityCollection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
using System.Diagnostics;
using Chaos.Common.Utilities;
using Chaos.Extensions;
using Chaos.Extensions.Common;
using Chaos.Extensions.Geometry;
using Chaos.Geometry.Abstractions;
using Chaos.Models.World;
using Chaos.Models.World.Abstractions;
using Chaos.Time.Abstractions;
using Microsoft.Extensions.Logging;

namespace Chaos.Collections;

Expand All @@ -11,7 +18,6 @@ public sealed class MapEntityCollection : IDeltaUpdatable
private readonly HashSet<Door> Doors;
private readonly Dictionary<uint, MapEntity> EntityLookup;
private readonly HashSet<GroundEntity> GroundEntities;

// ReSharper disable once NotAccessedField.Local
private readonly ILogger Logger;
private readonly HashSet<Merchant> Merchants;
Expand All @@ -27,7 +33,8 @@ public MapEntityCollection(
ILogger logger,
int mapWidth,
int mapHeight,
int walkableArea)
int walkableArea
)
{
Logger = logger;
EntityLookup = new Dictionary<uint, MapEntity>();
Expand Down Expand Up @@ -59,21 +66,16 @@ public MapEntityCollection(
.Case<GroundEntity>(GroundEntities)
.Case<ReactorTile>(Reactors)
.Case<Door>(Doors)
.Case<Creature>(
() => Aislings.Concat<Creature>(Monsters)
.Concat(Merchants))
.Case<NamedEntity>(
() => Aislings.Concat<NamedEntity>(Monsters)
.Concat(Merchants)
.Concat(GroundEntities))
.Case<Creature>(() => Aislings.Concat<Creature>(Monsters).Concat(Merchants))
.Case<NamedEntity>(() => Aislings.Concat<NamedEntity>(Monsters).Concat(Merchants).Concat(GroundEntities))
.Case<VisibleEntity>(
() => Aislings.Concat<VisibleEntity>(Monsters)
.Concat(Merchants)
.Concat(GroundEntities)
.Concat(Doors))
() => Aislings.Concat<VisibleEntity>(Monsters).Concat(Merchants).Concat(GroundEntities).Concat(Doors))
.Default(EntityLookup.Values);
}

/// <inheritdoc />
public void Update(TimeSpan delta) => Updatables.Update(delta);

public void Add(uint id, MapEntity entity)
{
EntityLookup.Add(id, entity);
Expand Down Expand Up @@ -119,13 +121,11 @@ public void AddToPointLookup(MapEntity mapEntity)
entities.Add(mapEntity);
}

public IEnumerable<T> AtPoint<T>(IPoint point) where T: MapEntity
=> Bounds.Contains(point)
? PointLookup[point.X, point.Y]
.OfType<T>()
: Enumerable.Empty<T>();
public IEnumerable<T> AtPoint<T>(IPoint point) where T: MapEntity =>
Bounds.Contains(point) ? PointLookup[point.X, point.Y].OfType<T>() : Enumerable.Empty<T>();

public IEnumerable<T> AtPoints<T>(IEnumerable<IPoint> points) where T: MapEntity => points.SelectMany(AtPoint<T>);
public IEnumerable<T> AtPoints<T>(IEnumerable<IPoint> points) where T: MapEntity =>
points.SelectMany(AtPoint<T>);

public void Clear()
{
Expand Down Expand Up @@ -217,9 +217,6 @@ public bool TryGetValue<T>(uint id, [NotNullWhen(true)] out T? entity)
return false;
}

/// <inheritdoc />
public void Update(TimeSpan delta) => Updatables.Update(delta);

public IEnumerable<T> Values<T>() where T: MapEntity
{
var result = ValuesCases.Switch<T>();
Expand Down Expand Up @@ -275,8 +272,7 @@ public IEnumerable<T> WithinRange<T>(IPoint point, int range = 15) where T: MapE
yield return t;
}
else //otherwise just check every entity of that type with a distance check
foreach (var entity in Values<T>()
.ThatAreWithinRange(point, range))
foreach (var entity in Values<T>().ThatAreWithinRange(point, range))
yield return entity;
}
}
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<Company>Chaotic Minds</Company>
<NeutralLanguage>en</NeutralLanguage>
<Copyright>Copyright @ Sichi 2018-2023</Copyright>
<PackageProjectUrl>https://docs.chaos-server.net/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Sichii/Chaos-Server</RepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Chaos.Common.Abstractions;
using Chaos.Common.Configuration;
using FluentAssertions;
using Moq;
using Xunit;

namespace Chaos.Common.Tests;

Expand Down
4 changes: 4 additions & 0 deletions Tests/Chaos.Common.Tests/KeyMapperTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System.Numerics;
using Chaos.Common.Abstractions;
using Chaos.Common.Utilities;
using FluentAssertions;
using Moq;
using Xunit;

namespace Chaos.Common.Tests;

Expand Down
2 changes: 2 additions & 0 deletions Tests/Chaos.Common.Tests/TypeSwitchExpressionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Chaos.Common.Utilities;
using FluentAssertions;
using Xunit;

namespace Chaos.Common.Tests;

Expand Down
2 changes: 2 additions & 0 deletions Tests/Chaos.Common.Tests/TypeSwitchTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Chaos.Common.Utilities;
using FluentAssertions;
using Xunit;

namespace Chaos.Common.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using FluentAssertions;
using Xunit;

namespace Chaos.Extensions.Common.Tests;

public sealed class CollectionExtensionsTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using FluentAssertions;
using Xunit;

namespace Chaos.Extensions.Common.Tests;

public sealed class DictionaryExtensionsTests
Expand Down
8 changes: 5 additions & 3 deletions Tests/Chaos.Extensions.Common.Tests/EnumExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Chaos.Common.Definitions;
using Chaos.Testing.Infrastructure.Definitions;
using FluentAssertions;
using Xunit;

namespace Chaos.Extensions.Common.Tests;

Expand Down Expand Up @@ -55,14 +57,14 @@ public void GetFlags_ShouldReturnIndividualFlags()
EquipmentSlot.Accessory3)]
public void ToEquipmentSlots_Should_Return_Correct_EquipmentSlots_For_EquipmentType(
EquipmentType equipmentType,
params EquipmentSlot[] expectedSlots)
params EquipmentSlot[] expectedSlots
)
{
// Act
var equipmentSlots = equipmentType.ToEquipmentSlots();

// Assert
equipmentSlots.Should()
.BeEquivalentTo(expectedSlots);
equipmentSlots.Should().BeEquivalentTo(expectedSlots);
}

[Fact]
Expand Down
Loading

0 comments on commit 4b8c245

Please sign in to comment.