refactor: Replace hardcoded node paths with constants and remove ScoreComponent.

This commit is contained in:
2026-01-31 15:35:04 +01:00
parent 62bdf1ba39
commit b62478bbea
27 changed files with 183 additions and 202 deletions

View File

@@ -1,4 +1,5 @@
using Godot;
using Mr.BrickAdventures;
using Mr.BrickAdventures.Autoloads;
using Mr.BrickAdventures.scripts.Resources;
@@ -12,27 +13,27 @@ public partial class DeathScreen : Control
[Export] public Label LivesLeftLabel { get; set; }
[Export] public float TimeoutTime { get; set; } = 2.0f;
[Export] public Godot.Collections.Array<Node> NodesToDisable { get; set; } = new();
private GameManager _gameManager;
private Timer _timer;
public override void _Ready()
{
_gameManager = GetNode<GameManager>("/root/GameManager");
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
SetLabels();
}
private void SetLabels()
{
if (_gameManager == null) return;
if (CurrentLevel != null)
{
CurrentLevelLabel.Text = CurrentLevel.LevelName;
}
LivesLeftLabel.Text = $" x {_gameManager.GetLives()}";
}
private void SetupTimer()
{
_timer = new Timer();
@@ -42,31 +43,31 @@ public partial class DeathScreen : Control
AddChild(_timer);
_timer.Start();
}
private void ToggleNodes()
{
foreach (var node in NodesToDisable)
{
node.ProcessMode = node.ProcessMode == ProcessModeEnum.Disabled
? ProcessModeEnum.Inherit
node.ProcessMode = node.ProcessMode == ProcessModeEnum.Disabled
? ProcessModeEnum.Inherit
: ProcessModeEnum.Disabled;
}
}
public void OnPlayerDeath()
{
if (_gameManager == null) return;
ToggleNodes();
SetLabels();
Show();
SetupTimer();
}
private void OnTimeout()
{
if (_gameManager == null || _gameManager.GetLives() == 0) return;
GetTree().ReloadCurrentScene();
}
}