Skip to content

Commit

Permalink
Merge pull request #17 from BigBang1112/dev
Browse files Browse the repository at this point in the history
Randomizer TMF 1.1.2
  • Loading branch information
BigBang1112 authored Jun 14, 2024
2 parents 5b93753 + f0822fa commit 386c7a1
Show file tree
Hide file tree
Showing 45 changed files with 1,294 additions and 618 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ jobs:
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
run: dotnet build -c Release --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test -c Release --no-build --verbosity normal --no-build --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
if: matrix.os == 'ubuntu-latest'
with:
filename: coverage/**/coverage.cobertura.xml
badge: true
fail_below_min: true
format: text
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/BigBang1112/randomizer-tmf?include_prereleases&style=for-the-badge)](https://github.com/BigBang1112/randomizer-tmf/releases)
[![GitHub all releases](https://img.shields.io/github/downloads/BigBang1112/randomizer-tmf/total?style=for-the-badge)](https://github.com/BigBang1112/randomizer-tmf/releases)
![GitHub all releases](https://img.shields.io/badge/Code%20Coverage-63%25-yellow?style=for-the-badge)
[![Code Coverage](https://img.shields.io/badge/Code%20Coverage-65%25-yellow?style=for-the-badge)](https://github.com/BigBang1112/randomizer-tmf)

**Randomizer TMF - Random Map Challenge for TMNF/TMUF** is a project (inspired from the Flink's Random Map Challenge) that ports random map picking experience to TMNF and TMUF games.

Expand Down
2 changes: 2 additions & 0 deletions Src/RandomizerTMF.Logic/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public static class Constants
public const string RallyCar = "RallyCar";
public const string SportCar = "SportCar";
public const string IslandCar = "IslandCar";

public const string SessionBin = "Session.bin";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace RandomizerTMF.Logic.Exceptions;

[Serializable]
public class AutosaveScannerException : Exception
{
public AutosaveScannerException() { }
public AutosaveScannerException(string message) : base(message) { }
public AutosaveScannerException(string message, Exception inner) : base(message, inner) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ public class ImportantPropertyNullException : Exception
public ImportantPropertyNullException() { }
public ImportantPropertyNullException(string message) : base(message) { }
public ImportantPropertyNullException(string message, Exception inner) : base(message, inner) { }
protected ImportantPropertyNullException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
3 changes: 0 additions & 3 deletions Src/RandomizerTMF.Logic/Exceptions/InvalidSessionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ public class InvalidSessionException : Exception
public InvalidSessionException() { }
public InvalidSessionException(string message) : base(message) { }
public InvalidSessionException(string message, Exception inner) : base(message, inner) { }
protected InvalidSessionException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
3 changes: 0 additions & 3 deletions Src/RandomizerTMF.Logic/Exceptions/MapValidationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ public class MapValidationException : Exception
public MapValidationException() { }
public MapValidationException(string message) : base(message) { }
public MapValidationException(string message, Exception inner) : base(message, inner) { }
protected MapValidationException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
3 changes: 0 additions & 3 deletions Src/RandomizerTMF.Logic/Exceptions/RuleValidationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ public class RuleValidationException : Exception
public RuleValidationException() { }
public RuleValidationException(string message) : base(message) { }
public RuleValidationException(string message, Exception inner) : base(message, inner) { }
protected RuleValidationException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
6 changes: 3 additions & 3 deletions Src/RandomizerTMF.Logic/LoggerToFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public class LoggerToFile : ILogger

public LoggerToFile(StreamWriter writer)
{
Writers = ImmutableArray.Create(writer);
Writers = [writer];
}

public void SetSessionWriter(StreamWriter writer)
{
Writers = ImmutableArray.Create(Writers[0], writer);
Writers = [Writers[0], writer];
}

public void RemoveSessionWriter()
{
Writers = ImmutableArray.Create(Writers[0]);
Writers = [Writers[0]];
}

public IDisposable BeginScope<TState>(TState state) where TState : notnull
Expand Down
14 changes: 14 additions & 0 deletions Src/RandomizerTMF.Logic/RandomizerRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@ public class RandomizerRules
PrimaryType = EPrimaryType.Race,
AuthorTimeMax = TimeInt32.FromMinutes(3)
};

public void Serialize(BinaryWriter writer)
{
writer.Write(TimeLimit.Ticks);
writer.Write(NoUnlimiter);
RequestRules.Serialize(writer);
}

public void Deserialize(BinaryReader r)
{
TimeLimit = TimeSpan.FromTicks(r.ReadInt64());
NoUnlimiter = r.ReadBoolean();
RequestRules.Deserialize(r);
}
}
16 changes: 8 additions & 8 deletions Src/RandomizerTMF.Logic/RandomizerTMF.Logic.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.1.1</Version>
<TargetFramework>net7.0</TargetFramework>
<Version>1.1.2</Version>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -12,12 +12,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DiscordRichPresence" Version="1.1.3.18" />
<PackageReference Include="GBX.NET" Version="1.2.0" />
<PackageReference Include="GBX.NET.LZO" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="System.IO.Abstractions" Version="19.2.29" />
<PackageReference Include="YamlDotNet" Version="13.1.0" />
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageReference Include="GBX.NET" Version="2.0.4" />
<PackageReference Include="GBX.NET.LZO" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="System.IO.Abstractions" Version="21.0.2" />
<PackageReference Include="YamlDotNet" Version="15.1.6" />
</ItemGroup>

<ItemGroup>
Expand Down
168 changes: 165 additions & 3 deletions Src/RandomizerTMF.Logic/RequestRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class RequestRules
{
private static readonly ESite[] siteValues = Enum.GetValues<ESite>();
private static readonly EEnvironment[] envValues = Enum.GetValues<EEnvironment>();
private static readonly EEnvironment[] sunriseEnvValues = new [] { EEnvironment.Island, EEnvironment.Bay, EEnvironment.Coast };
private static readonly EEnvironment[] originalEnvValues = new [] { EEnvironment.Desert, EEnvironment.Snow, EEnvironment.Rally };
private static readonly EEnvironment[] sunriseEnvValues = [EEnvironment.Island, EEnvironment.Bay, EEnvironment.Coast];
private static readonly EEnvironment[] originalEnvValues = [EEnvironment.Desert, EEnvironment.Snow, EEnvironment.Rally];

// Custom rules that are not part of the official API

Expand Down Expand Up @@ -207,7 +207,7 @@ private static EEnvironment GetRandomEnvironment(IRandomGenerator random, HashSe

private static HashSet<EEnvironment> GetRandomEnvironmentThroughSet(IRandomGenerator random, HashSet<EEnvironment>? container, ESite site)
{
return new HashSet<EEnvironment>() { GetRandomEnvironment(random, container, site) };
return [GetRandomEnvironment(random, container, site)];
}

private static ESite GetRandomSite(IRandomGenerator random, ESite[] matchingSites)
Expand Down Expand Up @@ -267,4 +267,166 @@ private static void AppendValue(StringBuilder b, Type type, object val, Type? ge
b.Append(val);
}
}

public void Serialize(BinaryWriter writer)
{
writer.Write((int)Site);
writer.Write(EqualEnvironmentDistribution);
writer.Write(EqualVehicleDistribution);
writer.Write(Author ?? string.Empty);
writer.Write(Environment?.Count ?? 0);
if (Environment is not null)
{
foreach (var env in Environment)
{
writer.Write((int)env);
}
}
writer.Write(Name ?? string.Empty);
writer.Write(Vehicle?.Count ?? 0);
if (Vehicle is not null)
{
foreach (var veh in Vehicle)
{
writer.Write((int)veh);
}
}
writer.Write(PrimaryType.HasValue ? (int)PrimaryType.Value : -1);
writer.Write(Tag.HasValue ? (int)Tag.Value : -1);
writer.Write(Mood?.Count ?? 0);
if (Mood is not null)
{
foreach (var mood in Mood)
{
writer.Write((int)mood);
}
}
writer.Write(Difficulty?.Count ?? 0);
if (Difficulty is not null)
{
foreach (var diff in Difficulty)
{
writer.Write((int)diff);
}
}
writer.Write(Routes?.Count ?? 0);
if (Routes is not null)
{
foreach (var route in Routes)
{
writer.Write((int)route);
}
}
writer.Write(LbType.HasValue ? (int)LbType.Value : -1);
writer.Write(InBeta.HasValue ? Convert.ToByte(InBeta.Value) : (byte)255);
writer.Write(InPlayLater.HasValue ? Convert.ToByte(InPlayLater.Value) : (byte)255);
writer.Write(InFeatured.HasValue ? Convert.ToByte(InFeatured.Value) : (byte)255);
writer.Write(InSupporter.HasValue ? Convert.ToByte(InSupporter.Value) : (byte)255);
writer.Write(InFavorite.HasValue ? Convert.ToByte(InFavorite.Value) : (byte)255);
writer.Write(InDownloads.HasValue ? Convert.ToByte(InDownloads.Value) : (byte)255);
writer.Write(InReplays.HasValue ? Convert.ToByte(InReplays.Value) : (byte)255);
writer.Write(InEnvmix.HasValue ? Convert.ToByte(InEnvmix.Value) : (byte)255);
writer.Write(InHasRecord.HasValue ? Convert.ToByte(InHasRecord.Value) : (byte)255);
writer.Write(InLatestAuthor.HasValue ? Convert.ToByte(InLatestAuthor.Value) : (byte)255);
writer.Write(InLatestAwardedAuthor.HasValue ? Convert.ToByte(InLatestAwardedAuthor.Value) : (byte)255);
writer.Write(InScreenshot.HasValue ? Convert.ToByte(InScreenshot.Value) : (byte)255);
writer.Write(UploadedBefore?.ToString("yyyy-MM-dd") ?? string.Empty);
writer.Write(UploadedAfter?.ToString("yyyy-MM-dd") ?? string.Empty);
writer.Write(AuthorTimeMin?.TotalMilliseconds ?? 0);
writer.Write(AuthorTimeMax?.TotalMilliseconds ?? 0);
}

public void Deserialize(BinaryReader r)
{
Site = (ESite)r.ReadInt32();
EqualEnvironmentDistribution = r.ReadBoolean();
EqualVehicleDistribution = r.ReadBoolean();
var author = r.ReadString();
Author = string.IsNullOrEmpty(author) ? null : author;
var envCount = r.ReadInt32();
if (envCount > 0)
{
Environment = [];
for (var i = 0; i < envCount; i++)
{
Environment.Add((EEnvironment)r.ReadInt32());
}
}
var name = r.ReadString();
Name = string.IsNullOrEmpty(name) ? null : name;
var vehCount = r.ReadInt32();
if (vehCount > 0)
{
Vehicle = [];
for (var i = 0; i < vehCount; i++)
{
Vehicle.Add((EEnvironment)r.ReadInt32());
}
}
var primaryType = r.ReadInt32();
PrimaryType = primaryType == -1 ? null : (EPrimaryType)primaryType;
var tag = r.ReadInt32();
Tag = tag == -1 ? null : (ETag)tag;
var moodCount = r.ReadInt32();
if (moodCount > 0)
{
Mood = [];
for (var i = 0; i < moodCount; i++)
{
Mood.Add((EMood)r.ReadInt32());
}
}
var diffCount = r.ReadInt32();
if (diffCount > 0)
{
Difficulty = [];
for (var i = 0; i < diffCount; i++)
{
Difficulty.Add((EDifficulty)r.ReadInt32());
}
}
var routeCount = r.ReadInt32();
if (routeCount > 0)
{
Routes = [];
for (var i = 0; i < routeCount; i++)
{
Routes.Add((ERoutes)r.ReadInt32());
}
}
var lbType = r.ReadInt32();
LbType = lbType == -1 ? null : (ELbType)lbType;
var inBeta = r.ReadByte();
InBeta = inBeta == 255 ? null : Convert.ToBoolean(inBeta);
var inPlayLater = r.ReadByte();
InPlayLater = inPlayLater == 255 ? null : Convert.ToBoolean(inPlayLater);
var inFeatured = r.ReadByte();
InFeatured = inFeatured == 255 ? null : Convert.ToBoolean(inFeatured);
var inSupporter = r.ReadByte();
InSupporter = inSupporter == 255 ? null : Convert.ToBoolean(inSupporter);
var inFavorite = r.ReadByte();
InFavorite = inFavorite == 255 ? null : Convert.ToBoolean(inFavorite);
var inDownloads = r.ReadByte();
InDownloads = inDownloads == 255 ? null : Convert.ToBoolean(inDownloads);
var inReplays = r.ReadByte();
InReplays = inReplays == 255 ? null : Convert.ToBoolean(inReplays);
var inEnvmix = r.ReadByte();
InEnvmix = inEnvmix == 255 ? null : Convert.ToBoolean(inEnvmix);
var inHasRecord = r.ReadByte();
InHasRecord = inHasRecord == 255 ? null : Convert.ToBoolean(inHasRecord);
var inLatestAuthor = r.ReadByte();
InLatestAuthor = inLatestAuthor == 255 ? null : Convert.ToBoolean(inLatestAuthor);
var inLatestAwardedAuthor = r.ReadByte();
InLatestAwardedAuthor = inLatestAwardedAuthor == 255 ? null : Convert.ToBoolean(inLatestAwardedAuthor);
var inScreenshot = r.ReadByte();
InScreenshot = inScreenshot == 255 ? null : Convert.ToBoolean(inScreenshot);
var uploadedBefore = r.ReadString();
UploadedBefore = string.IsNullOrEmpty(uploadedBefore) ? null : DateOnly.Parse(uploadedBefore);
var uploadedAfter = r.ReadString();
UploadedAfter = string.IsNullOrEmpty(uploadedAfter) ? null : DateOnly.Parse(uploadedAfter);
var authorTimeMin = r.ReadInt32();
AuthorTimeMin = authorTimeMin == 0 ? null : TimeInt32.FromMilliseconds(authorTimeMin);
var authorTimeMax = r.ReadInt32();
AuthorTimeMax = authorTimeMax == 0 ? null : TimeInt32.FromMilliseconds(authorTimeMax);
}
}
Loading

0 comments on commit 386c7a1

Please sign in to comment.