-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugLogger.cs
More file actions
129 lines (111 loc) · 4.12 KB
/
DebugLogger.cs
File metadata and controls
129 lines (111 loc) · 4.12 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
117
118
119
120
121
122
123
124
125
126
127
128
129
using MelonLoader;
namespace MelatoninAccess
{
/// <summary>
/// Centralized debug logging with categories.
/// All logging goes through here so it can be filtered and controlled.
///
/// Usage:
/// DebugLogger.Log(LogCategory.Input, "Tab pressed");
/// DebugLogger.Log(LogCategory.State, "Inventory opened");
/// DebugLogger.Log(LogCategory.Handler, "InventoryHandler", "Navigated to item 3");
///
/// Categories help when reading logs:
/// [SR] Screenreader output - what the user hears
/// [INPUT] Key presses and input events
/// [STATE] Screen/menu state changes
/// [HANDLER] Handler decisions and actions
/// [GAME] Values read from game (positions, stats, etc.)
/// </summary>
public static class DebugLogger
{
/// <summary>
/// Log a debug message with category.
/// Only logs when Main.DebugMode is true.
/// </summary>
/// <param name="category">The log category</param>
/// <param name="message">The message to log</param>
public static void Log(LogCategory category, string message)
{
if (!MelatoninAccessMod.DebugMode) return;
string prefix = GetPrefix(category);
MelonLogger.Msg($"{prefix} {message}");
}
/// <summary>
/// Log a debug message with category and source.
/// Useful for handler logs to identify which handler logged.
/// </summary>
/// <param name="category">The log category</param>
/// <param name="source">Source identifier (e.g. handler name)</param>
/// <param name="message">The message to log</param>
public static void Log(LogCategory category, string source, string message)
{
if (!MelatoninAccessMod.DebugMode) return;
string prefix = GetPrefix(category);
MelonLogger.Msg($"{prefix} [{source}] {message}");
}
/// <summary>
/// Log screenreader output. Called automatically by ScreenReader.Say().
/// </summary>
public static void LogScreenReader(string text)
{
if (!MelatoninAccessMod.DebugMode) return;
MelonLogger.Msg($"[SR] {text}");
}
/// <summary>
/// Log a key press event.
/// </summary>
public static void LogInput(string keyName, string action = null)
{
if (!MelatoninAccessMod.DebugMode) return;
string msg = action != null
? $"{keyName} -> {action}"
: keyName;
MelonLogger.Msg($"[INPUT] {msg}");
}
/// <summary>
/// Log a state change (screen opened/closed, mode changed).
/// </summary>
public static void LogState(string description)
{
if (!MelatoninAccessMod.DebugMode) return;
MelonLogger.Msg($"[STATE] {description}");
}
/// <summary>
/// Log a game value that was read (for debugging data extraction).
/// </summary>
public static void LogGameValue(string name, object value)
{
if (!MelatoninAccessMod.DebugMode) return;
MelonLogger.Msg($"[GAME] {name} = {value}");
}
private static string GetPrefix(LogCategory category)
{
return category switch
{
LogCategory.ScreenReader => "[SR]",
LogCategory.Input => "[INPUT]",
LogCategory.State => "[STATE]",
LogCategory.Handler => "[HANDLER]",
LogCategory.Game => "[GAME]",
_ => "[DEBUG]"
};
}
}
/// <summary>
/// Categories for debug logging.
/// </summary>
public enum LogCategory
{
/// <summary>What the screenreader announces</summary>
ScreenReader,
/// <summary>Key presses and input events</summary>
Input,
/// <summary>Screen/menu state changes</summary>
State,
/// <summary>Handler decisions and processing</summary>
Handler,
/// <summary>Values read from the game</summary>
Game
}
}