Skip to content

Commit

Permalink
IAsType support
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr committed Sep 22, 2024
1 parent 4d1d77f commit da8894c
Showing 1 changed file with 26 additions and 56 deletions.
82 changes: 26 additions & 56 deletions Content.Shared/Administration/Logs/LogStringHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Robust.Shared.Player;
using Robust.Shared.Toolshed.TypeParsers;

namespace Content.Shared.Administration.Logs;

Expand All @@ -24,7 +25,7 @@ public LogStringHandler(int literalLength, int formattedCount, ISharedAdminLogMa

_handler = new DefaultInterpolatedStringHandler(literalLength, formattedCount);

// TODO LOGGING Array pool?
// TODO LOGGING Dictionary pool?
Values = new Dictionary<string, object?>(formattedCount);
Logger = logger;
}
Expand Down Expand Up @@ -180,83 +181,52 @@ public void AppendFormatted(ICommonSession? value, int alignment, string? format
}
#endregion

#region Entity<T>

// TODO LOGGING
// Make Entity<T1,T2,T3> etc implement some entity uid fetching interface.
// I CBF writing variants for all the generic combinations
public void AppendFormatted<T>(Entity<T> value, [CallerArgumentExpression("value")] string? argument = null)
where T : IComponent?
{
AppendFormatted(value.Owner, argument);
}

public void AppendFormatted<T>(Entity<T> value, string? format, [CallerArgumentExpression("value")] string? argument = null)
where T : IComponent?
{
AppendFormatted(value.Owner, format, argument);
}

public void AppendFormatted<T>(Entity<T> value, int alignment, [CallerArgumentExpression("value")] string? argument = null)
where T : IComponent?
{
AppendFormatted(value.Owner, alignment, argument);
}

public void AppendFormatted<T>(Entity<T> value, int alignment, string? format, [CallerArgumentExpression("value")] string? argument = null)
where T : IComponent?
{
AppendFormatted(value.Owner, alignment, format, argument);
}

public void AppendFormatted<T>(Entity<T>? value, [CallerArgumentExpression("value")] string? argument = null)
where T : IComponent?
{
AppendFormatted(value?.Owner, argument);
}

public void AppendFormatted<T>(Entity<T>? value, string? format, [CallerArgumentExpression("value")] string? argument = null)
where T : IComponent?
{
AppendFormatted(value?.Owner, format, argument);
}

public void AppendFormatted<T>(Entity<T>? value, int alignment, [CallerArgumentExpression("value")] string? argument = null)
where T : IComponent?
{
AppendFormatted(value?.Owner, alignment, argument);
}

public void AppendFormatted<T>(Entity<T>? value, int alignment, string? format, [CallerArgumentExpression("value")] string? argument = null)
where T : IComponent?
{
AppendFormatted(value?.Owner, alignment, format, argument);
}

#endregion

#region Generic

public void AppendFormatted<T>(T value, [CallerArgumentExpression("value")] string? argument = null)
{
if (value is IAsType<EntityUid> ent)
{
AppendFormatted(ent.AsType(), argument);
return;
}

AddFormat(null, value, argument);
_handler.AppendFormatted(value);
}

public void AppendFormatted<T>(T value, string? format, [CallerArgumentExpression("value")] string? argument = null)
{
if (value is IAsType<EntityUid> ent)
{
AppendFormatted(ent.AsType(), format, argument);
return;
}

AddFormat(format, value, argument);
_handler.AppendFormatted(value, format);
}

public void AppendFormatted<T>(T value, int alignment, [CallerArgumentExpression("value")] string? argument = null)
{
if (value is IAsType<EntityUid> ent)
{
AppendFormatted(ent.AsType(), alignment, argument);
return;
}

AddFormat(null, value, argument);
_handler.AppendFormatted(value, alignment);
}

public void AppendFormatted<T>(T value, int alignment, string? format, [CallerArgumentExpression("value")] string? argument = null)
{
if (value is IAsType<EntityUid> ent)
{
AppendFormatted(ent.AsType(), alignment, format, argument);
return;
}

AddFormat(format, value, argument);
_handler.AppendFormatted(value, alignment, format);
}
Expand Down

0 comments on commit da8894c

Please sign in to comment.