-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalController.cs
More file actions
116 lines (104 loc) · 3.47 KB
/
GlobalController.cs
File metadata and controls
116 lines (104 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
namespace Krassheiten.SystemGameManager.Functions;
using System;
using System.Collections;
using System.Reflection;
using Microsoft.Data.Sqlite;
class GlobalFunctions
{
private static int clogCount = 0;
public static void ConsoleLog(string message)
{
Console.WriteLine(message);
}
public static void ConsoleError(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(message);
Console.ResetColor();
}
public static void die(string? message = null)
{
if (message != null)
{
ConsoleError(message);
}
Environment.Exit(0);
}
/// <summary>
/// Gibt eine Trennlinie in der Konsole aus, um Debug-Logs oder wichtige Informationen hervorzuheben.
/// Nützlich, um die Übersicht in der Konsole zu verbessern und wichtige Abschnitte zu markieren.
/// "S" steht hierbei für short, da es nur eine einfache Trennlinie ohne zusätzliche Informationen ist.
/// </summary>
public static void slog()
{
Console.WriteLine("======== Debug Log ============");
}
/// <summary>
/// Zählt die Anzahl der Aufrufe dieser Funktion und gibt sie in der Konsole aus.
/// Nützlich für Debugging-Zwecke, um zu sehen, wie oft eine Funktion aufgerufen wird.
/// "c" steht hierbei für count, da es die Anzahl der Aufrufe zählt und anzeigt.
/// </summary>
public static void clog()
{
clogCount++;
Console.WriteLine($"======== Debug Log: {clogCount} ============");
}
/// <summary>
/// Gibt eine benutzerdefinierte Nachricht zusammen mit einem Debug-Log aus.
/// Nützlich, um spezifische Informationen oder Kontext in den Debug-Logs zu haben.
/// "m" steht hierbei für message, da es eine benutzerdefinierte Nachricht in den Debug-Log integriert.
/// </summary>
public static void mlog(string message)
{
Console.WriteLine($"======== Debug Log: {message} ============");
}
public static void dump(object? obj, int indent = 0)
{
string indentStr = new string(' ', indent);
if (obj == null)
{
Console.WriteLine($"{indentStr}null");
return;
}
Type type = obj.GetType();
// 🔹 Primitive / einfache Typen
if (type.IsPrimitive || obj is string || obj is decimal)
{
Console.WriteLine($"{indentStr}{obj}");
return;
}
// 🔹 IEnumerable (Arrays, Listen, etc.)
if (obj is IEnumerable enumerable)
{
Console.WriteLine($"{indentStr}[");
foreach (var item in enumerable)
{
dump(item, indent + 2);
}
Console.WriteLine($"{indentStr}]");
return;
}
// 🔹 Objekte / Records
Console.WriteLine($"{indentStr}{type.Name} {{");
var properties = type.GetProperties();
foreach (var prop in properties)
{
object? value = prop.GetValue(obj);
Console.Write($"{indentStr} {prop.Name}: ");
if (value == null)
{
Console.WriteLine("null");
}
else if (prop.PropertyType.IsPrimitive || value is string)
{
Console.WriteLine(value);
}
else
{
Console.WriteLine();
dump(value, indent + 4);
}
}
Console.WriteLine($"{indentStr}}}");
}
}