CrabUI
Loading...
Searching...
No Matches
CUI Logging.cs
1using System;
2using System.Reflection;
3using System.Runtime.CompilerServices;
4using System.Collections.Generic;
5using System.Collections.Immutable;
6using System.Linq;
7
8using Barotrauma;
9using HarmonyLib;
10using Microsoft.Xna.Framework;
11using System.IO;
12
13namespace CrabUI
14{
15 public partial class CUI
16 {
17 /// <summary>
18 /// $"‖color:{color}‖{msg}‖end‖"
19 /// </summary>
20 public static string WrapInColor(object msg, string color)
21 {
22 return $"‖color:{color}‖{msg}‖end‖";
23 }
24
25 //HACK too lazy to make good name
26 /// <summary>
27 /// Serializes the array
28 /// </summary>
29 public static string ArrayToString(IEnumerable<object> array)
30 {
31 return $"[{String.Join(", ", array.Select(o => o.ToString()))}]";
32 }
33
34 /// <summary>
35 /// Prints a message to console
36 /// </summary>
37 public static void Log(object msg, Color? color = null, [CallerFilePath] string source = "", [CallerLineNumber] int lineNumber = 0)
38 {
39 color ??= Color.Cyan;
40
41 // var fi = new FileInfo(source);
42 // LuaCsLogger.LogMessage($"{fi.Directory.Name}/{fi.Name}:{lineNumber}", color * 0.6f, color * 0.6f);
43
44 LuaCsLogger.LogMessage($"{msg ?? "null"}", color * 0.8f, color);
45 }
46
47 public static void Warning(object msg, Color? color = null, [CallerFilePath] string source = "", [CallerLineNumber] int lineNumber = 0)
48 {
49 color ??= Color.Yellow;
50 // var fi = new FileInfo(source);
51 // LuaCsLogger.LogMessage($"{fi.Directory.Name}/{fi.Name}:{lineNumber}", color * 0.6f, color * 0.6f);
52 LuaCsLogger.LogMessage($"{msg ?? "null"}", color * 0.8f, color);
53 }
54
55
56 /// <summary>
57 /// xd
58 /// </summary>
59 /// <param name="source"> This should be injected by compiler, don't set </param>
60 public static string GetCallerFolderPath([CallerFilePath] string source = "") => Path.GetDirectoryName(source);
61
62 /// <summary>
63 /// Prints debug message with source path
64 /// Works only if debug is true
65 /// </summary>
66 public static void Info(object msg, [CallerFilePath] string source = "", [CallerLineNumber] int lineNumber = 0)
67 {
68 if (Debug == true)
69 {
70 var fi = new FileInfo(source);
71
72 Log($"{fi.Directory.Name}/{fi.Name}:{lineNumber}", Color.Yellow * 0.5f);
73 Log(msg, Color.Yellow);
74 }
75 }
76 }
77}
static bool Debug
This affects logging.
Definition CUI.cs:113
static string GetCallerFolderPath([CallerFilePath] string source="")
xd
static void Log(object msg, Color? color=null, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
Prints a message to console.
static string ArrayToString(IEnumerable< object > array)
Serializes the array.
static string WrapInColor(object msg, string color)
$"‖color:{color}‖{msg}‖end‖"
static void Info(object msg, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
Prints debug message with source path Works only if debug is true.