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

Commit ef95f0f

Browse files
Remove another static
1 parent 3898cf4 commit ef95f0f

4 files changed

Lines changed: 25 additions & 21 deletions

File tree

Scripts/Scenes/Main/GameManager.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ public override void _Ready()
2121
GameTree = GetTree();
2222
GameConsole = GetNode<UIGameConsole>(NodePathGameConsole);
2323
GodotCommands = new GodotCommands();
24-
ModLoader = new ModLoader();
25-
ModLoader.Init();
26-
ModLoader.LoadMods();
2724
}
2825

2926
public override async void _Process(float delta)

Scripts/Scenes/Menu/ModLoader.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public class ModLoader
1515
public string PathMods { get; set; }
1616
public Script Script { get; set; }
1717
public string LuaScriptsPath = "";
18+
public UIModLoader UIModLoader { get; set; }
19+
20+
public ModLoader(UIModLoader uiModLoader)
21+
{
22+
UIModLoader = uiModLoader;
23+
}
1824

1925
public void Init()
2026
{
@@ -59,7 +65,7 @@ public void SortMods()
5965

6066
public void LoadMods()
6167
{
62-
UIModLoader.Instance.ClearLog();
68+
UIModLoader.ClearLog();
6369

6470
//if (Script != null)
6571
//DebugServer.Detach(Script);
@@ -80,7 +86,7 @@ public void LoadMods()
8086
.ForEach(mod => LoadMod(mod, ref modLoadedCount));
8187

8288
if (modLoadedCount > 0)
83-
UIModLoader.Instance.Log($"{modLoadedCount} mods have loaded successfully");
89+
UIModLoader.Log($"{modLoadedCount} mods have loaded successfully");
8490
}
8591

8692
private void DisableModsWithLackingDependencies()
@@ -110,7 +116,7 @@ private void CheckAllDependenciesEnabled(ModInfo firstMod, ModInfo modInfo, List
110116
{
111117
if (!modsToDisable.Contains(firstMod))
112118
modsToDisable.Add(firstMod);
113-
UIModLoader.Instance.Log($"{firstMod.Name} requires dependency {dependency} to be enabled");
119+
UIModLoader.Log($"{firstMod.Name} requires dependency {dependency} to be enabled");
114120
}
115121
checkedMods.Add(dependency);
116122
CheckAllDependenciesEnabled(firstMod, ModInfo[dependency].ModInfo, checkedMods, ref modsToDisable);
@@ -125,7 +131,7 @@ public void Call(string v, params object[] args)
125131
}
126132
catch (ScriptRuntimeException e)
127133
{
128-
UIModLoader.Instance.Log($"{e.DecoratedMessage}");
134+
UIModLoader.Log($"{e.DecoratedMessage}");
129135
Logger.LogErr(e, $"[ModLoader]: ");
130136
}
131137
}
@@ -155,7 +161,7 @@ public void GetModsEnabled()
155161
private void Log(object obj)
156162
{
157163
Logger.Log($"[ModLoader]: {obj}");
158-
UIModLoader.Instance.Log($"{obj}");
164+
UIModLoader.Log($"{obj}");
159165
}
160166

161167
private void LoadLuaScripts(string directory)
@@ -175,7 +181,7 @@ private void LoadLuaScripts(string directory)
175181
Script.DoString(luaScript.GetAsText());
176182
else
177183
{
178-
UIModLoader.Instance.Log($"Could not open file: {absolutePath}");
184+
UIModLoader.Log($"Could not open file: {absolutePath}");
179185
Logger.LogWarning($"Could not open file: {absolutePath}");
180186
}
181187
}
@@ -244,13 +250,13 @@ private void LoadMod(Mod mod, ref int modLoadedCount)
244250
try
245251
{
246252
Script.DoFile(mod.PathScript);
247-
UIModLoader.Instance.Log($"Loaded {mod.ModInfo.Name}");
253+
UIModLoader.Log($"Loaded {mod.ModInfo.Name}");
248254
modLoadedCount++;
249255
}
250256
catch (ScriptRuntimeException e)
251257
{
252258
// Mod script did not run right
253-
UIModLoader.Instance.Log($"{e.DecoratedMessage}");
259+
UIModLoader.Log($"{e.DecoratedMessage}");
254260
Logger.LogErr(e, "[ModLoader]: ");
255261
}
256262
}

Scripts/Scenes/Menu/UIModInfo.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public void SetColor(Color color)
3737
BtnModEnabled.AddColorOverride("font_color", color);
3838
}
3939

40+
public UIModLoader UIModLoader { get; set; }
41+
4042
private void _on_Enabled_pressed()
4143
{
4244
Enabled = !BtnModEnabled.Pressed;
@@ -46,12 +48,12 @@ private void _on_Enabled_pressed()
4648
GameManager.ModLoader.ModInfo[modName].ModInfo.Enabled = Enabled;
4749

4850
if (DisplayedInDependencies)
49-
UIModLoader.Instance.ModInfoList[modName].SetModEnabled(Enabled);
51+
UIModLoader.ModInfoList[modName].SetModEnabled(Enabled);
5052
else
51-
if (UIModLoader.Instance.ModInfoDependencyList.ContainsKey(modName))
52-
UIModLoader.Instance.ModInfoDependencyList[modName].SetModEnabled(Enabled);
53+
if (UIModLoader.ModInfoDependencyList.ContainsKey(modName))
54+
UIModLoader.ModInfoDependencyList[modName].SetModEnabled(Enabled);
5355
}
5456

55-
private void _on_Mod_pressed() => UIModLoader.Instance.UpdateModInfo(BtnMod.Text);
57+
private void _on_Mod_pressed() => UIModLoader.UpdateModInfo(BtnMod.Text);
5658
}
5759
}

Scripts/Scenes/Menu/UIModLoader.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ namespace GodotModules
66
{
77
public class UIModLoader : Control
88
{
9-
public static UIModLoader Instance { get; set; }
10-
119
[Export] public readonly NodePath NodePathModList;
1210
[Export] public readonly NodePath NodePathModName;
1311
[Export] public readonly NodePath NodePathModGameVersions;
@@ -31,9 +29,8 @@ public class UIModLoader : Control
3129
// logger
3230
private RichTextLabel Logger { get; set; }
3331

34-
public override async void _Ready()
32+
public override void _Ready()
3533
{
36-
Instance = this;
3734
ModList = GetNode<VBoxContainer>(NodePathModList);
3835
ModName = GetNode<Label>(NodePathModName);
3936
ModGameVersions = GetNode<Label>(NodePathModGameVersions);
@@ -46,8 +43,9 @@ public override async void _Ready()
4643
ModDescription.Text = "";
4744
Logger.Clear();
4845

49-
while (GameManager.ModLoader == null) // this is ugly
50-
await Task.Delay(1);
46+
GameManager.ModLoader = new ModLoader(this);
47+
GameManager.ModLoader.Init();
48+
GameManager.ModLoader.LoadMods();
5149

5250
DisplayMods();
5351
}
@@ -100,6 +98,7 @@ public void DisplayMods()
10098
private UIModInfo CreateModInfoInstance(string modName)
10199
{
102100
var instance = Prefabs.ModInfo.Instance<UIModInfo>();
101+
instance.UIModLoader = this;
103102
instance.SetModName(modName);
104103

105104
if (GameManager.ModLoader.ModInfo[modName].ModInfo.Enabled)

0 commit comments

Comments
 (0)