51 lines
1.2 KiB
C#
Raw Normal View History

2022-01-18 01:46:41 -08:00
using Mirror;
using OWML.Common;
using QSB.Player.TransformSync;
2020-09-16 17:51:58 +01:00
using System.Diagnostics;
using System.Linq;
namespace QSB.Utility
2020-02-15 20:48:02 +01:00
{
2020-12-02 21:23:01 +00:00
public static class DebugLog
{
2020-12-20 18:16:23 +00:00
public static void ToConsole(string message, MessageType type = MessageType.Message)
2022-01-18 01:46:41 -08:00
{
if (NetworkClient.localPlayer != null)
{
message = $"[{NetworkClient.localPlayer.netId}] " + message;
}
QSBCore.Helper.Console.WriteLine(message, type, GetCallingType(new StackTrace()));
}
2020-12-02 21:23:01 +00:00
public static void ToHud(string message)
{
if (Locator.GetPlayerBody() == null)
{
return;
}
2021-06-18 22:38:32 +01:00
2020-12-02 21:23:01 +00:00
var data = new NotificationData(NotificationTarget.Player, message.ToUpper());
NotificationManager.SharedInstance.PostNotification(data);
}
2020-02-15 20:48:02 +01:00
2020-12-02 21:23:01 +00:00
public static void ToAll(string message, MessageType type = MessageType.Message)
{
ToConsole(message, type);
ToHud(message);
}
2020-08-10 18:17:54 +02:00
2020-12-02 21:23:01 +00:00
public static void DebugWrite(string message, MessageType type = MessageType.Message)
{
2020-12-14 16:24:52 +00:00
if (QSBCore.DebugMode)
2020-12-02 21:23:01 +00:00
{
ToConsole(message, type);
}
}
2020-08-22 20:21:13 +01:00
2021-12-26 20:42:07 -08:00
private static string GetCallingType(StackTrace frame) =>
frame.GetFrames()!
.Select(x => x.GetMethod().DeclaringType!.Name)
2022-01-06 12:16:02 +00:00
.First(x => x != nameof(DebugLog));
2020-12-02 21:23:01 +00:00
}
2020-12-03 08:28:05 +00:00
}