Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
18107 committed Apr 28, 2021
1 parent cc4e1ce commit e0438a7
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions PulsarPluginLoader/Chat/Extensions/HarmonyNetworkUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class HarmonyNetworkUpdate
{
private static string currentChatText;

private static bool textModified = false;

private static long lastTimePaste = long.MaxValue;
private static long lastTimeDelete = long.MaxValue;
private static long lastTimeUndo = long.MaxValue;
Expand Down Expand Up @@ -72,7 +70,6 @@ static void Prefix(PLNetworkManager __instance)
currentChatText = currentChatText.Remove(currentChatText.Length - cursorPos - 1, 1);
}
}
textModified = true;
}
else if (c == Environment.NewLine[0] || c == "\r"[0])
{
Expand All @@ -86,7 +83,6 @@ static void Prefix(PLNetworkManager __instance)
}
ChatHelper.UpdateTypingHistory(currentChatText, true);
currentChatText = currentChatText.Insert(currentChatText.Length - cursorPos, c.ToString());
textModified = true;
}
}
if (Input.GetKeyDown(KeyCode.Delete))
Expand All @@ -103,15 +99,13 @@ static void Prefix(PLNetworkManager __instance)
currentChatText = currentChatText.Remove(currentChatText.Length - cursorPos, 1);
cursorPos--;
}
textModified = true;
}
if (Input.GetKey(KeyCode.Delete) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeDelete)
{
ChatHelper.UpdateTypingHistory(currentChatText, false);
lastTimeDelete += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
currentChatText = currentChatText.Remove(currentChatText.Length - cursorPos, 1);
cursorPos--;
textModified = true;
}

if (Input.GetKeyDown(KeyCode.Tab))
Expand All @@ -122,7 +116,6 @@ static void Prefix(PLNetworkManager __instance)
if (chatText != currentChatText)
{
ChatHelper.UpdateTypingHistory(currentChatText, true, true);
textModified = true;
currentChatText = chatText;
cursorPos2 = -1;
}
Expand All @@ -135,7 +128,6 @@ static void Prefix(PLNetworkManager __instance)
if (chatText != currentChatText)
{
ChatHelper.UpdateTypingHistory(currentChatText, true, true);
textModified = true;
currentChatText = chatText;
cursorPos2 = -1;
}
Expand Down Expand Up @@ -165,13 +157,11 @@ static void Postfix(PLNetworkManager __instance)
{
lastTimeRedo = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250;
ChatHelper.Redo(ref currentChatText);
textModified = true;
}
if (Input.GetKey(KeyCode.Z) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeRedo)
{
lastTimeRedo += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
ChatHelper.Redo(ref currentChatText);
textModified = true;
}
}
else
Expand All @@ -180,26 +170,22 @@ static void Postfix(PLNetworkManager __instance)
{
lastTimeUndo = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250;
ChatHelper.Undo(ref currentChatText);
textModified = true;
}
if (Input.GetKey(KeyCode.Z) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeUndo)
{
lastTimeUndo += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
ChatHelper.Undo(ref currentChatText);
textModified = true;
}
}
if (Input.GetKeyDown(KeyCode.Y))
{
lastTimeRedo = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250;
ChatHelper.Redo(ref currentChatText);
textModified = true;
}
if (Input.GetKey(KeyCode.Y) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeRedo)
{
lastTimeRedo += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
ChatHelper.Redo(ref currentChatText);
textModified = true;
}

if (Input.GetKeyDown(KeyCode.V))
Expand All @@ -211,15 +197,13 @@ static void Postfix(PLNetworkManager __instance)
DeleteSelected();
}
currentChatText = currentChatText.Insert(currentChatText.Length - cursorPos, GUIUtility.systemCopyBuffer);
textModified = true;
ChatHelper.UpdateTypingHistory(currentChatText, true, true);
}
if (Input.GetKey(KeyCode.V) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimePaste)
{
ChatHelper.UpdateTypingHistory(currentChatText, true, true);
lastTimePaste += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
currentChatText = currentChatText.Insert(currentChatText.Length - cursorPos, GUIUtility.systemCopyBuffer);
textModified = true;
ChatHelper.UpdateTypingHistory(currentChatText, true, true);
}
if (Input.GetKeyDown(KeyCode.C) && cursorPos2 != -1 && cursorPos2 != cursorPos)
Expand Down Expand Up @@ -255,7 +239,6 @@ static void Postfix(PLNetworkManager __instance)
}
GUIUtility.systemCopyBuffer = currentChatText.Substring(pos, length);
DeleteSelected();
textModified = true;
ChatHelper.UpdateTypingHistory(currentChatText, false, true);
}
if (Input.GetKeyDown(KeyCode.A))
Expand All @@ -265,11 +248,7 @@ static void Postfix(PLNetworkManager __instance)
}
}

if (textModified)
{
textModified = false;
__instance.CurrentChatText = currentChatText;
}
__instance.CurrentChatText = currentChatText;

if (Input.GetKeyDown(KeyCode.UpArrow))
{
Expand Down

0 comments on commit e0438a7

Please sign in to comment.