refactor: implement singleton pattern for key managers and improve resource access
This commit is contained in:
@@ -4,6 +4,8 @@ namespace Mr.BrickAdventures.Autoloads;
|
|||||||
|
|
||||||
public partial class ConfigFileHandler : Node
|
public partial class ConfigFileHandler : Node
|
||||||
{
|
{
|
||||||
|
public static ConfigFileHandler Instance { get; private set; }
|
||||||
|
|
||||||
private ConfigFile _settingsConfig = new();
|
private ConfigFile _settingsConfig = new();
|
||||||
public const string SettingsPath = "user://settings.ini";
|
public const string SettingsPath = "user://settings.ini";
|
||||||
|
|
||||||
@@ -11,6 +13,7 @@ public partial class ConfigFileHandler : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
Instance = this;
|
||||||
if (!FileAccess.FileExists(SettingsPath))
|
if (!FileAccess.FileExists(SettingsPath))
|
||||||
{
|
{
|
||||||
var err = _settingsConfig.Save(SettingsPath);
|
var err = _settingsConfig.Save(SettingsPath);
|
||||||
@@ -24,4 +27,9 @@ public partial class ConfigFileHandler : Node
|
|||||||
GD.PushError($"Failed to load settings file at {SettingsPath}: {err}");
|
GD.PushError($"Failed to load settings file at {SettingsPath}: {err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
if (Instance == this) Instance = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ public partial class SaveSystem : Node
|
|||||||
var skills = new List<SkillData>();
|
var skills = new List<SkillData>();
|
||||||
if (skillNames == null) return skills;
|
if (skillNames == null) return skills;
|
||||||
|
|
||||||
var skillManager = GetNodeOrNull<SkillManager>(Constants.SkillManagerPath);
|
var skillManager = SkillManager.Instance;
|
||||||
if (skillManager == null)
|
if (skillManager == null)
|
||||||
{
|
{
|
||||||
GD.PrintErr("SaveSystem: SkillManager not available to resolve skill names.");
|
GD.PrintErr("SaveSystem: SkillManager not available to resolve skill names.");
|
||||||
|
|||||||
@@ -4,8 +4,20 @@ namespace Mr.BrickAdventures.Autoloads;
|
|||||||
|
|
||||||
public partial class UIManager : Node
|
public partial class UIManager : Node
|
||||||
{
|
{
|
||||||
|
public static UIManager Instance { get; private set; }
|
||||||
|
|
||||||
private readonly System.Collections.Generic.List<Control> UiStack = new();
|
private readonly System.Collections.Generic.List<Control> UiStack = new();
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
if (Instance == this) Instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
[Signal] public delegate void ScreenPushedEventHandler(Control screen);
|
[Signal] public delegate void ScreenPushedEventHandler(Control screen);
|
||||||
[Signal] public delegate void ScreenPoppedEventHandler(Control screen);
|
[Signal] public delegate void ScreenPoppedEventHandler(Control screen);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Godot.NET.Sdk/4.6.0">
|
<Project Sdk="Godot.NET.Sdk/4.6.1">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ point_count = 2
|
|||||||
[sub_resource type="CurveTexture" id="CurveTexture_7b7mt"]
|
[sub_resource type="CurveTexture" id="CurveTexture_7b7mt"]
|
||||||
curve = SubResource("Curve_82d6e")
|
curve = SubResource("Curve_82d6e")
|
||||||
|
|
||||||
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_85ofa"]
|
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_sktot"]
|
||||||
resource_local_to_scene = true
|
resource_local_to_scene = true
|
||||||
lifetime_randomness = 1.0
|
lifetime_randomness = 1.0
|
||||||
particle_flag_disable_z = true
|
particle_flag_disable_z = true
|
||||||
@@ -114,7 +114,7 @@ script = ExtResource("13_sktot")
|
|||||||
metadata/_custom_type_script = "uid://6foetukqmyoe"
|
metadata/_custom_type_script = "uid://6foetukqmyoe"
|
||||||
|
|
||||||
[node name="HitParticles" parent="Brick Player" index="23"]
|
[node name="HitParticles" parent="Brick Player" index="23"]
|
||||||
process_material = SubResource("ParticleProcessMaterial_85ofa")
|
process_material = SubResource("ParticleProcessMaterial_sktot")
|
||||||
|
|
||||||
[connection signal="Death" from="Brick Player/HealthComponent" to="UI Layer/DeathScreen" method="OnPlayerDeath"]
|
[connection signal="Death" from="Brick Player/HealthComponent" to="UI Layer/DeathScreen" method="OnPlayerDeath"]
|
||||||
[connection signal="Death" from="Brick Player/HealthComponent" to="UI Layer/GameOverScreen" method="OnPlayerDeath"]
|
[connection signal="Death" from="Brick Player/HealthComponent" to="UI Layer/GameOverScreen" method="OnPlayerDeath"]
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Mr.BrickAdventures;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.Events;
|
namespace Mr.BrickAdventures.scripts.Events;
|
||||||
@@ -7,17 +6,18 @@ namespace Mr.BrickAdventures.scripts.Events;
|
|||||||
[GlobalClass]
|
[GlobalClass]
|
||||||
public partial class SpeedRunEventHandler : Node
|
public partial class SpeedRunEventHandler : Node
|
||||||
{
|
{
|
||||||
private SpeedRunManager _speedRunManager;
|
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_speedRunManager = GetNode<SpeedRunManager>(Constants.SpeedRunManagerPath);
|
|
||||||
|
|
||||||
EventBus.Instance.LevelCompleted += OnLevelCompleted;
|
EventBus.Instance.LevelCompleted += OnLevelCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
EventBus.Instance.LevelCompleted -= OnLevelCompleted;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
|
private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
|
||||||
{
|
{
|
||||||
_speedRunManager.Split();
|
SpeedRunManager.Instance?.Split();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Mr.BrickAdventures;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -12,13 +11,11 @@ public partial class AudioSettings : Control
|
|||||||
[Export] public Control AudioSettingsControl { get; set; }
|
[Export] public Control AudioSettingsControl { get; set; }
|
||||||
[Export] public float MuteThreshold { get; set; } = -20f;
|
[Export] public float MuteThreshold { get; set; } = -20f;
|
||||||
|
|
||||||
private UIManager _uiManager;
|
private UIManager UIManager => UIManager.Instance;
|
||||||
private ConfigFileHandler _configFileHandler;
|
private ConfigFileHandler ConfigFileHandler => ConfigFileHandler.Instance;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
|
||||||
_configFileHandler = GetNode<ConfigFileHandler>(Constants.ConfigFileHandlerPath);
|
|
||||||
Initialize();
|
Initialize();
|
||||||
MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged;
|
MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged;
|
||||||
MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged;
|
MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged;
|
||||||
@@ -35,10 +32,10 @@ public partial class AudioSettings : Control
|
|||||||
public override void _UnhandledInput(InputEvent @event)
|
public override void _UnhandledInput(InputEvent @event)
|
||||||
{
|
{
|
||||||
if (!@event.IsActionReleased("ui_cancel")) return;
|
if (!@event.IsActionReleased("ui_cancel")) return;
|
||||||
if (!_uiManager.IsScreenOnTop(AudioSettingsControl)) return;
|
if (!UIManager.IsScreenOnTop(AudioSettingsControl)) return;
|
||||||
|
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
_uiManager.PopScreen();
|
UIManager.PopScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSfxVolumeChanged(double value)
|
private void OnSfxVolumeChanged(double value)
|
||||||
@@ -84,7 +81,7 @@ public partial class AudioSettings : Control
|
|||||||
|
|
||||||
private void SaveSettings()
|
private void SaveSettings()
|
||||||
{
|
{
|
||||||
var settingsConfig = _configFileHandler.SettingsConfig;
|
var settingsConfig = ConfigFileHandler.SettingsConfig;
|
||||||
settingsConfig.SetValue("audio_settings", "master_volume", MasterVolumeSlider.Value);
|
settingsConfig.SetValue("audio_settings", "master_volume", MasterVolumeSlider.Value);
|
||||||
settingsConfig.SetValue("audio_settings", "music_volume", MusicVolumeSlider.Value);
|
settingsConfig.SetValue("audio_settings", "music_volume", MusicVolumeSlider.Value);
|
||||||
settingsConfig.SetValue("audio_settings", "sfx_volume", SfxVolumeSlider.Value);
|
settingsConfig.SetValue("audio_settings", "sfx_volume", SfxVolumeSlider.Value);
|
||||||
@@ -94,7 +91,7 @@ public partial class AudioSettings : Control
|
|||||||
|
|
||||||
private void LoadSettings()
|
private void LoadSettings()
|
||||||
{
|
{
|
||||||
var settingsConfig = _configFileHandler.SettingsConfig;
|
var settingsConfig = ConfigFileHandler.SettingsConfig;
|
||||||
if (!settingsConfig.HasSection("audio_settings")) return;
|
if (!settingsConfig.HasSection("audio_settings")) return;
|
||||||
|
|
||||||
var masterVolume = (float)settingsConfig.GetValue("audio_settings", "master_volume", MasterVolumeSlider.Value);
|
var masterVolume = (float)settingsConfig.GetValue("audio_settings", "master_volume", MasterVolumeSlider.Value);
|
||||||
|
|||||||
@@ -1,24 +1,18 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Mr.BrickAdventures;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
|
|
||||||
public partial class Credits : Control
|
public partial class Credits : Control
|
||||||
{
|
{
|
||||||
private UIManager _uiManager;
|
private UIManager UIManager => UIManager.Instance;
|
||||||
|
|
||||||
public override void _Ready()
|
|
||||||
{
|
|
||||||
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void _UnhandledInput(InputEvent @event)
|
public override void _UnhandledInput(InputEvent @event)
|
||||||
{
|
{
|
||||||
if (!@event.IsActionPressed("ui_cancel")) return;
|
if (!@event.IsActionPressed("ui_cancel")) return;
|
||||||
if (_uiManager != null && _uiManager.IsScreenOnTop(this))
|
if (UIManager != null && UIManager.IsScreenOnTop(this))
|
||||||
{
|
{
|
||||||
_uiManager.PopScreen();
|
UIManager.PopScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Mr.BrickAdventures;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -16,15 +15,12 @@ public partial class MainMenu : Control
|
|||||||
[Export] public Control SettingsControl { get; set; }
|
[Export] public Control SettingsControl { get; set; }
|
||||||
[Export] public Control CreditsControl { get; set; }
|
[Export] public Control CreditsControl { get; set; }
|
||||||
|
|
||||||
private SaveSystem _saveSystem;
|
private SaveSystem SaveSystem => SaveSystem.Instance;
|
||||||
private GameManager _gameManager;
|
private GameManager GameManager => GameManager.Instance;
|
||||||
private UIManager _uiManager;
|
private UIManager UIManager => UIManager.Instance;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_saveSystem = SaveSystem.Instance;
|
|
||||||
_gameManager = GameManager.Instance;
|
|
||||||
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
|
||||||
|
|
||||||
NewGameButton.Pressed += OnNewGamePressed;
|
NewGameButton.Pressed += OnNewGamePressed;
|
||||||
ContinueButton.Pressed += OnContinuePressed;
|
ContinueButton.Pressed += OnContinuePressed;
|
||||||
@@ -33,9 +29,9 @@ public partial class MainMenu : Control
|
|||||||
ExitButton.Pressed += OnExitPressed;
|
ExitButton.Pressed += OnExitPressed;
|
||||||
|
|
||||||
VersionLabel.Text = $"v. {ProjectSettings.GetSetting("application/config/version")}";
|
VersionLabel.Text = $"v. {ProjectSettings.GetSetting("application/config/version")}";
|
||||||
ContinueButton.Disabled = !_saveSystem.CheckSaveExists();
|
ContinueButton.Disabled = !SaveSystem.CheckSaveExists();
|
||||||
|
|
||||||
if (_saveSystem.CheckSaveExists())
|
if (SaveSystem.CheckSaveExists())
|
||||||
ContinueButton.GrabFocus();
|
ContinueButton.GrabFocus();
|
||||||
else
|
else
|
||||||
NewGameButton.GrabFocus();
|
NewGameButton.GrabFocus();
|
||||||
@@ -43,26 +39,26 @@ public partial class MainMenu : Control
|
|||||||
|
|
||||||
private void OnExitPressed()
|
private void OnExitPressed()
|
||||||
{
|
{
|
||||||
_gameManager.QuitGame();
|
GameManager.QuitGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCreditsPressed()
|
private void OnCreditsPressed()
|
||||||
{
|
{
|
||||||
_uiManager.PushScreen(CreditsControl);
|
UIManager.PushScreen(CreditsControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSettingsPressed()
|
private void OnSettingsPressed()
|
||||||
{
|
{
|
||||||
_uiManager.PushScreen(SettingsControl);
|
UIManager.PushScreen(SettingsControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnContinuePressed()
|
private void OnContinuePressed()
|
||||||
{
|
{
|
||||||
_gameManager.ContinueGame();
|
GameManager.ContinueGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnNewGamePressed()
|
private void OnNewGamePressed()
|
||||||
{
|
{
|
||||||
_gameManager.StartNewGame();
|
GameManager.StartNewGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Mr.BrickAdventures;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -14,13 +13,11 @@ public partial class PauseMenu : Control
|
|||||||
[Export] public Button SettingsButton { get; set; }
|
[Export] public Button SettingsButton { get; set; }
|
||||||
[Export] public PackedScene MainMenuScene { get; set; }
|
[Export] public PackedScene MainMenuScene { get; set; }
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager GameManager => GameManager.Instance;
|
||||||
private UIManager _uiManager;
|
private UIManager UIManager => UIManager.Instance;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GameManager.Instance;
|
|
||||||
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
|
||||||
|
|
||||||
ResumeButton.Pressed += OnResumePressed;
|
ResumeButton.Pressed += OnResumePressed;
|
||||||
MainMenuButton.Pressed += OnMainMenuPressed;
|
MainMenuButton.Pressed += OnMainMenuPressed;
|
||||||
@@ -33,36 +30,36 @@ public partial class PauseMenu : Control
|
|||||||
public override void _UnhandledInput(InputEvent @event)
|
public override void _UnhandledInput(InputEvent @event)
|
||||||
{
|
{
|
||||||
if (!@event.IsActionPressed("pause")) return;
|
if (!@event.IsActionPressed("pause")) return;
|
||||||
if (_uiManager.IsVisibleOnStack(PauseMenuControl))
|
if (UIManager.IsVisibleOnStack(PauseMenuControl))
|
||||||
OnResumePressed();
|
OnResumePressed();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_uiManager.PushScreen(PauseMenuControl);
|
UIManager.PushScreen(PauseMenuControl);
|
||||||
_gameManager.PauseGame();
|
GameManager.PauseGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSettingsPressed()
|
private void OnSettingsPressed()
|
||||||
{
|
{
|
||||||
_uiManager.PushScreen(SettingsControl);
|
UIManager.PushScreen(SettingsControl);
|
||||||
_gameManager.PauseGame();
|
GameManager.PauseGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnQuitPressed()
|
private void OnQuitPressed()
|
||||||
{
|
{
|
||||||
_gameManager.QuitGame();
|
GameManager.QuitGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMainMenuPressed()
|
private void OnMainMenuPressed()
|
||||||
{
|
{
|
||||||
_gameManager.ResumeGame();
|
GameManager.ResumeGame();
|
||||||
_gameManager.ResetCurrentSessionState();
|
GameManager.ResetCurrentSessionState();
|
||||||
GetTree().ChangeSceneToPacked(MainMenuScene);
|
GetTree().ChangeSceneToPacked(MainMenuScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnResumePressed()
|
private void OnResumePressed()
|
||||||
{
|
{
|
||||||
_uiManager.PopScreen();
|
UIManager.PopScreen();
|
||||||
_gameManager.ResumeGame();
|
GameManager.ResumeGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Mr.BrickAdventures;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -16,11 +15,10 @@ public partial class SettingsMenu : Control
|
|||||||
[Export] public Button DisplaySettingsButton { get; set; }
|
[Export] public Button DisplaySettingsButton { get; set; }
|
||||||
[Export] public Button GameplaySettingsButton { get; set; }
|
[Export] public Button GameplaySettingsButton { get; set; }
|
||||||
|
|
||||||
private UIManager _uiManager;
|
private UIManager UIManager => UIManager.Instance;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
|
||||||
|
|
||||||
InputSettingsButton.Pressed += OnInputSettingsPressed;
|
InputSettingsButton.Pressed += OnInputSettingsPressed;
|
||||||
AudioSettingsButton.Pressed += OnAudioSettingsPressed;
|
AudioSettingsButton.Pressed += OnAudioSettingsPressed;
|
||||||
@@ -36,26 +34,26 @@ public partial class SettingsMenu : Control
|
|||||||
public override void _UnhandledInput(InputEvent @event)
|
public override void _UnhandledInput(InputEvent @event)
|
||||||
{
|
{
|
||||||
if (!@event.IsActionPressed("ui_cancel")) return;
|
if (!@event.IsActionPressed("ui_cancel")) return;
|
||||||
if (_uiManager.IsScreenOnTop(SettingsMenuControl)) _uiManager.PopScreen();
|
if (UIManager.IsScreenOnTop(SettingsMenuControl)) UIManager.PopScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInputSettingsPressed()
|
private void OnInputSettingsPressed()
|
||||||
{
|
{
|
||||||
_uiManager.PushScreen(InputSettingsControl);
|
UIManager.PushScreen(InputSettingsControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAudioSettingsPressed()
|
private void OnAudioSettingsPressed()
|
||||||
{
|
{
|
||||||
_uiManager.PushScreen(AudioSettingsControl);
|
UIManager.PushScreen(AudioSettingsControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDisplaySettingsPressed()
|
private void OnDisplaySettingsPressed()
|
||||||
{
|
{
|
||||||
_uiManager.PushScreen(DisplaySettingsControl);
|
UIManager.PushScreen(DisplaySettingsControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGameplaySettingsPressed()
|
private void OnGameplaySettingsPressed()
|
||||||
{
|
{
|
||||||
_uiManager.PushScreen(GameplaySettingsControl);
|
UIManager.PushScreen(GameplaySettingsControl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Mr.BrickAdventures;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.interfaces;
|
using Mr.BrickAdventures.scripts.interfaces;
|
||||||
using Mr.BrickAdventures.scripts.State;
|
using Mr.BrickAdventures.scripts.State;
|
||||||
@@ -17,14 +16,8 @@ public partial class ExitDoorComponent : Area2D, IUnlockable
|
|||||||
|
|
||||||
[Signal] public delegate void ExitTriggeredEventHandler();
|
[Signal] public delegate void ExitTriggeredEventHandler();
|
||||||
|
|
||||||
private GameManager _gameManager;
|
|
||||||
private AchievementManager _achievementManager;
|
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GameManager.Instance;
|
|
||||||
_achievementManager = GetNode<AchievementManager>(Constants.AchievementManagerPath);
|
|
||||||
|
|
||||||
BodyEntered += OnExitAreaBodyEntered;
|
BodyEntered += OnExitAreaBodyEntered;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -34,10 +27,9 @@ public partial class ExitDoorComponent : Area2D, IUnlockable
|
|||||||
if (Locked) return;
|
if (Locked) return;
|
||||||
|
|
||||||
EmitSignalExitTriggered();
|
EmitSignalExitTriggered();
|
||||||
_achievementManager.UnlockAchievement(AchievementId);
|
AchievementManager.Instance?.UnlockAchievement(AchievementId);
|
||||||
// Get current level from GameStateStore
|
|
||||||
var currentLevel = GameStateStore.Instance?.Session.CurrentLevel ?? 0;
|
var currentLevel = GameStateStore.Instance?.Session.CurrentLevel ?? 0;
|
||||||
_gameManager.UnlockLevel(currentLevel + 1);
|
GameManager.Instance?.UnlockLevel(currentLevel + 1);
|
||||||
CallDeferred(nameof(GoToNextLevel));
|
CallDeferred(nameof(GoToNextLevel));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +46,6 @@ public partial class ExitDoorComponent : Area2D, IUnlockable
|
|||||||
|
|
||||||
private void GoToNextLevel()
|
private void GoToNextLevel()
|
||||||
{
|
{
|
||||||
_gameManager.OnLevelComplete();
|
GameManager.Instance?.OnLevelComplete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Mr.BrickAdventures;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
namespace Mr.BrickAdventures.scripts.components;
|
||||||
@@ -17,12 +16,8 @@ public partial class LeverComponent : Node
|
|||||||
[Signal]
|
[Signal]
|
||||||
public delegate void ActivatedEventHandler();
|
public delegate void ActivatedEventHandler();
|
||||||
|
|
||||||
private FloatingTextManager _floatingTextManager;
|
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_floatingTextManager = GetNode<FloatingTextManager>(Constants.FloatingTextManagerPath);
|
|
||||||
|
|
||||||
if (Area == null)
|
if (Area == null)
|
||||||
{
|
{
|
||||||
GD.PushError("LeverComponent: Area is not set.");
|
GD.PushError("LeverComponent: Area is not set.");
|
||||||
@@ -52,7 +47,7 @@ public partial class LeverComponent : Node
|
|||||||
private async Task Activate()
|
private async Task Activate()
|
||||||
{
|
{
|
||||||
EmitSignalActivated();
|
EmitSignalActivated();
|
||||||
_floatingTextManager?.ShowMessage("Activated!", ((Node2D)Owner).GlobalPosition);
|
FloatingTextManager.Instance?.ShowMessage("Activated!", ((Node2D)Owner).GlobalPosition);
|
||||||
Sfx?.Play();
|
Sfx?.Play();
|
||||||
Sprite.Frame = StartAnimationIndex + 1;
|
Sprite.Frame = StartAnimationIndex + 1;
|
||||||
var timer = GetTree().CreateTimer(AnimationDuration);
|
var timer = GetTree().CreateTimer(AnimationDuration);
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 93 KiB |
Reference in New Issue
Block a user