Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit 411864e

Browse files
more encapsulation
1 parent 11318f1 commit 411864e

4 files changed

Lines changed: 22 additions & 21 deletions

File tree

Scripts/Netcode/Common/Utils/Logger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void Dequeue()
7575
Console.ResetColor();
7676

7777
#if CLIENT
78-
GM.GameConsole.AddMessage(text);
78+
GM.LogConsoleMessage(text);
7979
#endif
8080
break;
8181
case LoggerOpcode.LogError:
@@ -91,7 +91,7 @@ public void Dequeue()
9191

9292
#if CLIENT
9393
ErrorNotifier.IncrementErrorCount();
94-
GM.GameConsole.AddMessage(errorText);
94+
GM.LogConsoleMessage(errorText);
9595
#endif
9696
break;
9797
}

Scripts/Scenes/Main/ErrorNotifier.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public class ErrorNotifier : Node
88

99
public static void IncrementErrorCount() => ErrorCount++;
1010

11-
private static GTimer Timer { get; set; }
11+
private static GTimer TimerNotifyErrors { get; set; }
1212

1313
public override void _Ready()
1414
{
15-
Timer = new GTimer(1500);
16-
Timer.Connect(this, nameof(SpawnErrorNotification));
15+
TimerNotifyErrors = new GTimer(1500);
16+
TimerNotifyErrors.Connect(this, nameof(SpawnErrorNotification));
1717
}
1818

1919
private static void SpawnErrorNotification()
@@ -23,7 +23,7 @@ private static void SpawnErrorNotification()
2323

2424
var notifyError = Prefabs.NotifyError.Instance<UINotifyError>();
2525
notifyError.Count = ErrorCount;
26-
GM.GameTree.CurrentScene.AddChild(notifyError);
26+
GM.PersistentTree.CurrentScene.AddChild(notifyError);
2727

2828
ErrorCount = 0;
2929
}

Scripts/Scenes/Main/GM.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ namespace GodotModules
99
public class GM : Node
1010
{
1111
[Export] public readonly NodePath NodePathGameConsole;
12+
1213
public static ModLoader ModLoader { get; set; }
13-
public static UIGameConsole GameConsole { get; set; }
14-
private static GodotCommands GodotCommands { get; set; }
15-
private static Logger Logger { get; set; }
16-
1714
public static string GameName = "Godot Modules";
1815
public static OptionsData Options { get; set; }
19-
public static SceneTree GameTree { get; set; }
16+
public static SceneTree PersistentTree { get; set; }
17+
18+
private static UIGameConsole GameConsole { get; set; }
19+
private static GodotCommands GodotCommands { get; set; }
20+
private static Logger Logger { get; set; }
2021

2122
public override void _Ready()
2223
{
23-
GameTree = GetTree();
24+
PersistentTree = GetTree();
2425
GameConsole = GetNode<UIGameConsole>(NodePathGameConsole);
2526
GodotCommands = new GodotCommands();
2627
Logger = new Logger();
@@ -49,7 +50,7 @@ public override void _Input(InputEvent @event)
4950
public static void SpawnPopupMessage(string message)
5051
{
5152
var popupMessage = Prefabs.PopupMessage.Instance<UIPopupMessage>();
52-
GameTree.CurrentScene.AddChild(popupMessage);
53+
PersistentTree.CurrentScene.AddChild(popupMessage);
5354
popupMessage.Init(message);
5455
popupMessage.PopupCentered();
5556
}
@@ -58,11 +59,15 @@ public static void SpawnPopupError(Exception e)
5859
{
5960
ErrorNotifier.IncrementErrorCount();
6061
var popupError = Prefabs.PopupError.Instance<UIPopupError>();
61-
GameTree.CurrentScene.AddChild(popupError);
62+
PersistentTree.CurrentScene.AddChild(popupError);
6263
popupError.Init(e.Message, e.StackTrace);
6364
popupError.PopupCentered();
6465
}
6566

67+
public static void LogConsoleMessage(string message) => GameConsole.AddMessage(message);
68+
public static void ToggleConsoleVisibility() => GameConsole.ToggleVisibility();
69+
public static bool GameConsoleVisible => GameConsole.Visible;
70+
6671
public static void EnqueueGodotCmd(GodotOpcode opcode, object data = null) => GodotCommands.Enqueue(opcode, data);
6772

6873
public static void Log(object v, ConsoleColor color = ConsoleColor.Gray) => Logger.Log(v, color);
@@ -72,10 +77,6 @@ public static void SpawnPopupError(Exception e)
7277
public static void LogTODO(object v, ConsoleColor color = ConsoleColor.White) => Logger.LogTODO(v, color);
7378
public static void LogMs(Action code) => Logger.LogMs(code);
7479

75-
/// <summary>
76-
/// This should be used instead of GetTree().Quit() has it will handle cleanup and saving options
77-
/// Note that if the console is closed directly then the cleanup will never happen, this should be avoided.
78-
/// </summary>
79-
public static void Exit() => GameTree.Notification(MainLoop.NotificationWmQuitRequest);
80+
public static void Exit() => PersistentTree.Notification(MainLoop.NotificationWmQuitRequest);
8081
}
8182
}

Scripts/Scenes/Main/SceneManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public static void EscapePressed(Action action)
6161
{
6262
if (Input.IsActionJustPressed("ui_cancel"))
6363
{
64-
if (GM.GameConsole.Visible)
64+
if (GM.GameConsoleVisible)
6565
{
66-
GM.GameConsole.ToggleVisibility();
66+
GM.ToggleConsoleVisibility();
6767
return;
6868
}
6969

0 commit comments

Comments
 (0)