Skip to content

Commit

Permalink
Merge pull request #10 from BigBang1112/dev
Browse files Browse the repository at this point in the history
Randomizer TMF 1.1.0
  • Loading branch information
BigBang1112 authored Feb 10, 2023
2 parents 87ac9d6 + 687c041 commit 581a684
Show file tree
Hide file tree
Showing 83 changed files with 7,334 additions and 1,904 deletions.
9 changes: 9 additions & 0 deletions RandomizerTMF.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Položky řešení", "Polo
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{EF5000F9-46AE-451F-A50A-7E69DB05360E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RandomizerTMF.Logic.Tests", "Tests\RandomizerTMF.Logic.Tests\RandomizerTMF.Logic.Tests.csproj", "{5F783679-AC15-4941-BBE6-0038A15DF187}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -29,13 +33,18 @@ Global
{A1DFC07E-66E3-418B-AB19-2435FA2E3A42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1DFC07E-66E3-418B-AB19-2435FA2E3A42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1DFC07E-66E3-418B-AB19-2435FA2E3A42}.Release|Any CPU.Build.0 = Release|Any CPU
{5F783679-AC15-4941-BBE6-0038A15DF187}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F783679-AC15-4941-BBE6-0038A15DF187}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F783679-AC15-4941-BBE6-0038A15DF187}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F783679-AC15-4941-BBE6-0038A15DF187}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CB7687F3-9485-44C6-A751-F63FCE8C8D23} = {C7477BCC-8CD0-47CF-9DCE-397A4D65FAC3}
{A1DFC07E-66E3-418B-AB19-2435FA2E3A42} = {C7477BCC-8CD0-47CF-9DCE-397A4D65FAC3}
{5F783679-AC15-4941-BBE6-0038A15DF187} = {EF5000F9-46AE-451F-A50A-7E69DB05360E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F3B68FA-C841-400A-AAFE-0701C43ED400}
Expand Down
9 changes: 9 additions & 0 deletions Src/RandomizerTMF.Logic/CompiledRegex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.RegularExpressions;

namespace RandomizerTMF.Logic;

internal static partial class CompiledRegex
{
[GeneratedRegex("[^a-zA-Z0-9_.]+")]
public static partial Regex SpecialCharRegex();
}
15 changes: 15 additions & 0 deletions Src/RandomizerTMF.Logic/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,20 @@ public static class Constants
public const string Skipped = "Skipped";
public const string DefaultReplayFileFormat = "{0}_{1}_{2}.Replay.Gbx";
public const string OfficialBlocksYml = "OfficialBlocks.yml";
public const string MapSizesYml = "MapSizes.yml";
public const string Replays = "Replays";
public const string Tracks = "Tracks";
public const string Autosaves = "Autosaves";
public const string Challenges = "Challenges";
public const string Downloaded = "Downloaded";

public const string AlpineCar = "AlpineCar";
public const string SnowCar = "SnowCar";
public const string American = "American";
public const string SpeedCar = "SpeedCar";
public const string DesertCar = "DesertCar";
public const string Rally = "Rally";
public const string RallyCar = "RallyCar";
public const string SportCar = "SportCar";
public const string IslandCar = "IslandCar";
}
7 changes: 7 additions & 0 deletions Src/RandomizerTMF.Logic/DiscordRichPresenceConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace RandomizerTMF.Logic;

public class DiscordRichPresenceConfig
{
public bool Disable { get; set; }
public bool DisableMapThumbnail { get; set; }
}
44 changes: 44 additions & 0 deletions Src/RandomizerTMF.Logic/DiscordRpcLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.Extensions.Logging;

namespace RandomizerTMF.Logic;

internal class DiscordRpcLogger : DiscordRPC.Logging.ILogger
{
private readonly ILogger logger;

public DiscordRpcLogger(ILogger logger)
{
this.logger = logger;
}

public DiscordRPC.Logging.LogLevel Level { get; set; } = DiscordRPC.Logging.LogLevel.Info;

public void Error(string message, params object[] args)
{
using var _ = CreateScope();
logger.LogError(message, args);
}

public void Info(string message, params object[] args)
{
using var _ = CreateScope();
logger.LogInformation(message, args);
}

public void Trace(string message, params object[] args)
{
// using var _ = CreateScope();
// logger.LogTrace(message, args);
}

public void Warning(string message, params object[] args)
{
using var _ = CreateScope();
logger.LogWarning(message, args);
}

private IDisposable? CreateScope()
{
return logger.BeginScope("Discord RPC");
}
}
9 changes: 4 additions & 5 deletions Src/RandomizerTMF.Logic/ISessionMap.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace RandomizerTMF.Logic
namespace RandomizerTMF.Logic;

public interface ISessionMap
{
public interface ISessionMap
{
TimeSpan? LastTimestamp { get; set; }
}
TimeSpan? LastTimestamp { get; set; }
}
51 changes: 41 additions & 10 deletions Src/RandomizerTMF.Logic/LoggerToFile.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
using Microsoft.Extensions.Logging;
using System.Collections.Immutable;
using System.Text;

namespace RandomizerTMF.Logic;

public class LoggerToFile : ILogger
{
private readonly IList<StreamWriter> writers;

internal LogScope? CurrentScope { get; set; }

public LoggerToFile(params StreamWriter[] writers)
public ImmutableArray<StreamWriter> Writers { get; private set; }

public LoggerToFile(StreamWriter writer)
{
this.writers = writers;
Writers = ImmutableArray.Create(writer);
}

public LoggerToFile(StreamWriter writer)
public void SetSessionWriter(StreamWriter writer)
{
writers = new List<StreamWriter> { writer };
Writers = ImmutableArray.Create(Writers[0], writer);
}

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

public IDisposable BeginScope<TState>(TState state) where TState : notnull
Expand Down Expand Up @@ -56,13 +63,37 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except

// CurrentScope is not utilized

foreach (var writer in writers)
var builder = new StringBuilder("[");
builder.Append(DateTime.Now.ToString());
builder.Append(", ");
builder.Append(logLevel);
builder.Append("] ");

var scope = CurrentScope;

while (scope is not null)
{
writer.WriteLine($"[{DateTime.Now}, {logLevel}] {message}");
builder.Append(scope);
builder.Append(" => ");
scope = scope.Parent;
}

if (exception is not null)
builder.Append(message);

foreach (var writer in Writers)
{
try
{
writer.WriteLine(builder);

if (exception is not null)
{
writer.WriteLine(exception);
}
}
catch
{
writer.WriteLine(exception);
// usually writer of ended session
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions Src/RandomizerTMF.Logic/MapSizes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Rally:
- [10, 18, 150]
- [20, 18, 60]
- [30, 18, 30]
- [32, 12, 32]
- [45, 18, 45]
Island:
- [36, 36, 36]
- [45, 36, 45]
Speed:
- [10, 18, 150]
- [20, 18, 60]
- [30, 18, 30]
- [32, 12, 32]
- [45, 18, 45]
Stadium:
- [32, 32, 32]
Coast:
- [36, 36, 36]
- [45, 36, 45]
Alpine:
- [10, 18, 150]
- [20, 18, 60]
- [30, 18, 30]
- [32, 12, 32]
- [45, 18, 45]
Bay:
- [36, 36, 36]
- [45, 36, 45]
8 changes: 5 additions & 3 deletions Src/RandomizerTMF.Logic/NadeoIni.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
namespace RandomizerTMF.Logic;
using System.IO.Abstractions;

namespace RandomizerTMF.Logic;

public class NadeoIni
{
public required string UserSubDir { get; init; }

public static NadeoIni Parse(string nadeoIniFilePath)
public static NadeoIni Parse(string nadeoIniFilePath, IFileSystem fileSystem)
{
var userSubDir = "TmForever";

foreach (var line in File.ReadLines(nadeoIniFilePath))
foreach (var line in fileSystem.File.ReadLines(nadeoIniFilePath))
{
if (line.Length == 0 || line[0] is '#' or ';' or '[')
{
Expand Down
23 changes: 0 additions & 23 deletions Src/RandomizerTMF.Logic/RandomizerConfig.cs

This file was deleted.

Loading

0 comments on commit 581a684

Please sign in to comment.