58 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using OWML.Common;
namespace QSB.Utility
2020-02-15 20:48:02 +01:00
{
2020-08-20 14:10:37 +01:00
public static class DebugLog
2020-02-15 20:48:02 +01:00
{
public static void ToConsole(string message, MessageType type = MessageType.Message)
{
QSB.Helper.Console.WriteLine(message, type);
}
public static void ToHud(string message)
2020-02-15 20:48:02 +01:00
{
if (Locator.GetPlayerBody() == null)
{
return;
}
var data = new NotificationData(NotificationTarget.Player, message);
2020-07-28 15:59:24 +02:00
NotificationManager.SharedInstance.PostNotification(data);
}
2020-02-15 20:48:02 +01:00
public static void ToAll(string message, MessageType type = MessageType.Message)
2020-03-04 21:46:16 +01:00
{
ToConsole(message, type);
ToHud(message);
2020-03-04 21:46:16 +01:00
}
2020-08-10 18:17:54 +02:00
2020-08-19 22:29:53 +02:00
public static string GenerateTable(List<string> columnsData, List<string> rowData)
2020-08-10 18:17:54 +02:00
{
2020-08-19 22:29:53 +02:00
var longestKey = columnsData.OrderByDescending(s => s.Length).First();
var longestValue = rowData.OrderByDescending(s => s.Length).First();
var longestObject = (longestKey.Length > longestValue.Length) ? longestKey : longestValue;
2020-08-19 22:29:53 +02:00
var columns = "|";
var data = "|";
foreach (var item in columnsData)
{
columns += $" {item.PadRight(longestObject.Length)} |";
}
foreach (var item in rowData)
{
data += $" {item.PadRight(longestObject.Length)} |";
}
2020-08-19 22:29:53 +02:00
return columns + Environment.NewLine + data;
2020-08-10 18:17:54 +02:00
}
2020-08-20 14:47:44 +01:00
public static void LogState(string name, bool state)
2020-08-20 14:47:44 +01:00
{
var status = state ? "OK" : "FAIL";
var messageType = state ? MessageType.Success : MessageType.Error;
ToConsole($"* {name} {status}", messageType);
2020-08-20 14:47:44 +01:00
}
}
}