-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCitlog.cs
More file actions
198 lines (162 loc) · 5.37 KB
/
Citlog.cs
File metadata and controls
198 lines (162 loc) · 5.37 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using Epic.OnlineServices;
using HarmonyLib;
using Landfall.Network;
using Unity.Collections;
using Unity.Networking.Transport;
using UnityEngine;
namespace CitrusLib
{
//logging changes and stuff
public static partial class Citrus
{
//my logger for Citruslib debugging. dont use it! make your own CitLog!
internal static CitLog log = new CitLog("CitrusLib", ConsoleColor.Cyan);
internal static bool landLogSupressed = false;
//takes over landfall's logger to have it's format match mine.
internal static CitLog landLog = new CitLog("LandLog", ConsoleColor.Gray);
}
/// <summary>
/// A Class for prettier debug logging.
/// </summary>
public class CitLog
{
string modName;
ConsoleColor modColor;
static string lastMessage = "";
static int combo = 1;
/// <summary>
/// Makes a new CitLog for logging stuff in your mod!
/// </summary>
/// <param name="n">The name of your mod, or a sub-name if your mod has multiple seperate parts</param>
/// <param name="c">The color of the name.</param>
public CitLog(string n, ConsoleColor c = ConsoleColor.White)
{
modName = n;
modColor = c;
}
/// <summary>
/// Logs a message to the console
/// </summary>
/// <param name="text">The message to display</param>
/// <param name="error">Whether the message is an error.</param>
public void Log(string text, bool error = false)
{
if (this == Citrus.landLog & Citrus.landLogSupressed)
{
return;
}
if (Compare(text, lastMessage) / Mathf.Max(1f, Mathf.Max(text.Length, lastMessage.Length)) < 0.15f)
{
ClearLastLine();
combo++;
}
else
{
combo = 1;
}
Console.ForegroundColor = ConsoleColor.White;
Console.Write("[");
Console.ForegroundColor = modColor;
Console.Write(modName);
Console.ForegroundColor = ConsoleColor.White;
Console.Write("] - ");
Console.ForegroundColor = error ? ConsoleColor.Red : ConsoleColor.Gray;
{
Console.Write(text);
}
if (combo > 1)
{
Console.ForegroundColor = ConsoleColor.Magenta;
if (combo < 10)
{
Console.ForegroundColor = ConsoleColor.White;
}
else if (combo < 25)
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
else if (combo < 50)
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
}
else if (combo < 100)
{
Console.ForegroundColor = ConsoleColor.Red;
}
else if (combo < 500)
{
Console.ForegroundColor = ConsoleColor.DarkRed;
}
else
{
Console.ForegroundColor = combo % 2 == 0 ? ConsoleColor.DarkRed : ConsoleColor.Yellow;
//holy moly
}
Console.Write(string.Format(" (COMBO: {0})", combo));
}
if (error)
{
Debug.LogError("");
}
else
{
Console.WriteLine("");
}
lastMessage = text;
}
/// <summary>
/// logs an error to the console.
/// </summary>
/// <param name="text">the message to display.</param>
public void LogError(string text)
{
Log(text, true);
}
static void ClearLastLine()
{
Console.SetCursorPosition(0, Console.CursorTop - 1);
Console.Write(new string(' ', Console.BufferWidth));
Console.SetCursorPosition(0, Console.CursorTop - 1);
}
static int Compare(string s, string t)
{
if (string.IsNullOrEmpty(s))
{
if (string.IsNullOrEmpty(t))
return 0;
return t.Length;
}
if (string.IsNullOrEmpty(t))
{
return s.Length;
}
int n = s.Length;
int m = t.Length;
int[,] d = new int[n + 1, m + 1];
// initialize the top and right of the table to 0, 1, 2, ...
for (int i = 0; i <= n; d[i, 0] = i++) ;
for (int j = 1; j <= m; d[0, j] = j++) ;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
int cost = (t[j - 1] == s[i - 1]) ? 0 : 1;
int min1 = d[i - 1, j] + 1;
int min2 = d[i, j - 1] + 1;
int min3 = d[i - 1, j - 1] + cost;
d[i, j] = Math.Min(Math.Min(min1, min2), min3);
}
}
return d[n, m];
}
}
}