Skip to content

Commit b468c26

Browse files
Darker main theme, remove visual UI artifacts, fix translations, fixed many issues with credits and more (#189)
1 parent cd31ae6 commit b468c26

20 files changed

+346
-178
lines changed

Framework/Autoloads/AudioManager.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@ public class AudioManager : IDisposable
2424
/// </summary>
2525
public AudioManager(Autoloads autoloads)
2626
{
27-
_autoloads = autoloads;
28-
_options = Game.Options.GetOptions();
29-
30-
_musicPlayer = new AudioStreamPlayer();
31-
autoloads.AddChild(_musicPlayer);
32-
33-
_sfxPool = new GodotNodePool<AudioStreamPlayer2D>(autoloads,
34-
() => new AudioStreamPlayer2D());
27+
SetupFields(autoloads);
28+
SetupSfxPool();
29+
SetupMusicPlayer();
3530
}
3631

3732
/// <summary>
@@ -116,6 +111,24 @@ public void SetSFXVolume(float volume)
116111
}
117112
}
118113

114+
private void SetupFields(Autoloads autoloads)
115+
{
116+
_autoloads = autoloads;
117+
_options = Game.Options.GetOptions();
118+
}
119+
120+
private void SetupSfxPool()
121+
{
122+
_sfxPool = new GodotNodePool<AudioStreamPlayer2D>(_autoloads,
123+
() => new AudioStreamPlayer2D());
124+
}
125+
126+
private void SetupMusicPlayer()
127+
{
128+
_musicPlayer = new AudioStreamPlayer();
129+
_autoloads.AddChild(_musicPlayer);
130+
}
131+
119132
/// <summary>
120133
/// Generates a random pitch between min and max, avoiding values too similar to the previous sound.
121134
/// </summary>

Framework/Autoloads/Autoloads.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public partial class Autoloads : Node
4242
public override void _EnterTree()
4343
{
4444
if (Instance != null)
45-
throw new InvalidOperationException("Global has been initialized already");
45+
throw new InvalidOperationException($"{nameof(Autoloads)} has been initialized already");
4646

4747
Instance = this;
4848
ComponentManager = GetNode<ComponentManager>("ComponentManager");

Framework/Autoloads/SceneManager.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,21 @@ public class SceneManager
1515

1616
public const int DefaultSceneFadeDuration = 2;
1717

18+
public Node CurrentScene => _currentScene;
19+
1820
private MenuScenes _menuScenes;
1921
private SceneTree _tree;
2022
private Autoloads _autoloads;
2123
private Node _currentScene;
2224

2325
public SceneManager(Autoloads autoloads, MenuScenes scenes)
2426
{
25-
_autoloads = autoloads;
26-
_menuScenes = scenes;
27-
_tree = autoloads.GetTree();
28-
29-
Window root = _tree.Root;
30-
31-
_currentScene = root.GetChild(root.GetChildCount() - 1);
27+
SetupFields(autoloads, scenes);
3228

3329
// Gradually fade out all SFX whenever the scene is changed
3430
PreSceneChanged += OnPreSceneChanged;
3531
}
3632

37-
public Node GetCurrentScene()
38-
{
39-
return _currentScene;
40-
}
41-
4233
public void Dispose()
4334
{
4435
PreSceneChanged -= OnPreSceneChanged;
@@ -111,6 +102,17 @@ public void DeferredSwitchScene(string rawName, Variant transTypeVariant)
111102
}
112103
}
113104

105+
private void SetupFields(Autoloads autoloads, MenuScenes scenes)
106+
{
107+
_autoloads = autoloads;
108+
_menuScenes = scenes;
109+
_tree = autoloads.GetTree();
110+
111+
Window root = _tree.Root;
112+
113+
_currentScene = root.GetChild(root.GetChildCount() - 1);
114+
}
115+
114116
private void OnPreSceneChanged(string scene) => Game.Audio.FadeOutSFX();
115117

116118
private void ChangeScene(string scenePath, TransType transType)

Framework/Game.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
11
using __TEMPLATE__.Debugging;
22
using __TEMPLATE__.UI;
33
using __TEMPLATE__.UI.Console;
4+
using System;
45

56
namespace __TEMPLATE__;
67

78
public static class Game
89
{
10+
#if DEBUG
11+
/// <summary>
12+
/// Check if the autoloads singleton is not null. If it is null then show an error explaining
13+
/// that the developer cannot access the autoloads singleton just yet and it needs time to
14+
/// setup.
15+
/// </summary>
16+
private static T IsAutoloadsSetup<T>(Func<Autoloads, T> getPropertyFrom, string propertyName) where T : class
17+
{
18+
Autoloads autoloads = Autoloads.Instance;
19+
20+
if (autoloads == null)
21+
{
22+
string errMsg = $"Game.{propertyName} was accessed before _EnterTree or _Ready.";
23+
24+
#if NETCODE_ENABLED
25+
// Show a friendly optional error message if netcode is enabled.
26+
// Since Autoloads is null we can make our own temporary Logger.
27+
Logger logger = new();
28+
logger.LogDebug(errMsg + " (see exception in errors for stack trace)");
29+
logger.Update();
30+
#endif
31+
throw new InvalidOperationException(errMsg);
32+
}
33+
34+
return getPropertyFrom(autoloads)!; // Assumes the field may be null, but we are not checking it here
35+
}
36+
37+
public static MetricsOverlay Metrics => IsAutoloadsSetup(a => a.MetricsOverlay, nameof(Metrics));
38+
public static OptionsManager Options => IsAutoloadsSetup(a => a.OptionsManager, nameof(Options));
39+
public static AudioManager Audio => IsAutoloadsSetup(a => a.AudioManager, nameof(Audio));
40+
public static SceneManager Scene => IsAutoloadsSetup(a => a.SceneManager, nameof(Scene));
41+
public static GameConsole Console => IsAutoloadsSetup(a => a.GameConsole, nameof(Console));
42+
public static Profiler Profiler => IsAutoloadsSetup(a => a.Profiler, nameof(Profiler));
43+
public static Services Services => IsAutoloadsSetup(a => a.Services, nameof(Services));
44+
public static Logger Logger => IsAutoloadsSetup(a => a.Logger, nameof(Logger));
45+
#else
46+
// The games release will not have the slow debugging checks
947
public static MetricsOverlay Metrics => Autoloads.Instance.MetricsOverlay;
1048
public static OptionsManager Options => Autoloads.Instance.OptionsManager;
1149
public static AudioManager Audio => Autoloads.Instance.AudioManager;
@@ -14,4 +52,5 @@ public static class Game
1452
public static Profiler Profiler => Autoloads.Instance.Profiler;
1553
public static Services Services => Autoloads.Instance.Services;
1654
public static Logger Logger => Autoloads.Instance.Logger;
17-
}
55+
#endif
56+
}

Framework/Localisation/text.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ DIFFICULTY,Difficulty,Difficulté,困難
5252
ANTIALIASING,Antialiasing,Anticrénelage,アンチエイリアシング
5353
MODS,Mods,Mods,Mods
5454
RESOLUTION,Resolution,Résolution,解像度
55-
MOUSE\_SENSITIVITY,Mouse Sensitivity,Sensibilité de la souris,マウス感度
55+
MOUSE_SENSITIVITY,Mouse Sensitivity,Sensibilité de la souris,マウス感度
5656
GLOW,Glow,Lueur,グロー
57-
AMBIENT\_OCCLUSION,Ambient Occlusion,Oclusion ambiante,アンビエントオクルージョン
58-
INDIRECT\_LIGHTING,Indirect Lighting,Éclairage indirect,間接照明
57+
AMBIENT_OCCLUSION,Ambient Occlusion,Oclusion ambiante,アンビエントオクルージョン
58+
INDIRECT_LIGHTING,Indirect Lighting,Éclairage indirect,間接照明
5959
REFLECTIONS,Reflections,Reflets,反射
60-
RESTART,Restart,Redémarrer,再起動
60+
RESTART,Restart,Redémarrer,再起動

Framework/Scenes/MainMenuNav.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ public partial class MainMenuNav : Node
66
{
77
[Export] private PackedScene _gameScene;
88

9-
private SceneManager _scene = Game.Scene;
9+
private SceneManager _scene;
1010

1111
public override void _Ready()
1212
{
13+
_scene = Game.Scene;
1314
GetNode<Button>("Play").GrabFocus();
1415
}
1516

0 commit comments

Comments
 (0)