refactor: implement singleton pattern for key managers and improve resource access
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
using Mr.BrickAdventures.scripts.interfaces;
|
||||
using Mr.BrickAdventures.scripts.State;
|
||||
@@ -17,14 +16,8 @@ public partial class ExitDoorComponent : Area2D, IUnlockable
|
||||
|
||||
[Signal] public delegate void ExitTriggeredEventHandler();
|
||||
|
||||
private GameManager _gameManager;
|
||||
private AchievementManager _achievementManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GameManager.Instance;
|
||||
_achievementManager = GetNode<AchievementManager>(Constants.AchievementManagerPath);
|
||||
|
||||
BodyEntered += OnExitAreaBodyEntered;
|
||||
|
||||
}
|
||||
@@ -34,10 +27,9 @@ public partial class ExitDoorComponent : Area2D, IUnlockable
|
||||
if (Locked) return;
|
||||
|
||||
EmitSignalExitTriggered();
|
||||
_achievementManager.UnlockAchievement(AchievementId);
|
||||
// Get current level from GameStateStore
|
||||
AchievementManager.Instance?.UnlockAchievement(AchievementId);
|
||||
var currentLevel = GameStateStore.Instance?.Session.CurrentLevel ?? 0;
|
||||
_gameManager.UnlockLevel(currentLevel + 1);
|
||||
GameManager.Instance?.UnlockLevel(currentLevel + 1);
|
||||
CallDeferred(nameof(GoToNextLevel));
|
||||
}
|
||||
|
||||
@@ -54,6 +46,6 @@ public partial class ExitDoorComponent : Area2D, IUnlockable
|
||||
|
||||
private void GoToNextLevel()
|
||||
{
|
||||
_gameManager.OnLevelComplete();
|
||||
GameManager.Instance?.OnLevelComplete();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
using Mr.BrickAdventures;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
@@ -17,12 +16,8 @@ public partial class LeverComponent : Node
|
||||
[Signal]
|
||||
public delegate void ActivatedEventHandler();
|
||||
|
||||
private FloatingTextManager _floatingTextManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_floatingTextManager = GetNode<FloatingTextManager>(Constants.FloatingTextManagerPath);
|
||||
|
||||
if (Area == null)
|
||||
{
|
||||
GD.PushError("LeverComponent: Area is not set.");
|
||||
@@ -52,7 +47,7 @@ public partial class LeverComponent : Node
|
||||
private async Task Activate()
|
||||
{
|
||||
EmitSignalActivated();
|
||||
_floatingTextManager?.ShowMessage("Activated!", ((Node2D)Owner).GlobalPosition);
|
||||
FloatingTextManager.Instance?.ShowMessage("Activated!", ((Node2D)Owner).GlobalPosition);
|
||||
Sfx?.Play();
|
||||
Sprite.Frame = StartAnimationIndex + 1;
|
||||
var timer = GetTree().CreateTimer(AnimationDuration);
|
||||
|
||||
Reference in New Issue
Block a user