refactor: enhance GameStateStore integration and improve skill management

This commit is contained in:
2026-03-19 02:33:07 +01:00
parent 3e36e48e97
commit eeefca4d4e
31 changed files with 260 additions and 419 deletions

View File

@@ -11,29 +11,26 @@ public partial class GameOverScreen : Control
[Export] public Button MainMenuButton { get; set; }
[Export] public PackedScene MainMenuScene { get; set; }
private GameManager _gameManager;
public override void _Ready()
{
_gameManager = GameManager.Instance;
RestartButton.Pressed += OnRestartClicked;
MainMenuButton.Pressed += OnMainMenuClicked;
}
private void OnMainMenuClicked()
{
_gameManager.ResetPlayerState();
GameStateStore.Instance?.ResetAll();
GetTree().ChangeSceneToPacked(MainMenuScene);
}
private void OnRestartClicked()
{
_gameManager.RestartGame();
GameManager.Instance?.RestartGame();
}
public void OnPlayerDeath()
{
if (_gameManager == null || _gameManager.GetLives() != 0) return;
if (GameStateStore.Instance?.Player.Lives != 0) return;
GameOverPanel.Show();
}

View File

@@ -12,12 +12,7 @@ public partial class Hud : Control
[Export] public ProgressBar HealthBar { get; set; }
[Export] public Label LivesLabel { get; set; }
private GameManager _gameManager;
public override void _Ready()
{
_gameManager = GameManager.Instance;
}
private GameStateStore Store => GameStateStore.Instance;
public override void _Process(double delta)
{
@@ -28,12 +23,12 @@ public partial class Hud : Control
private void SetCoinsLabel()
{
CoinsLabel.Text = Tr("COINS_LABEL") + ": " + _gameManager.GetCoins();
CoinsLabel.Text = Tr("COINS_LABEL") + ": " + (Store?.GetTotalCoins() ?? 0);
}
private void SetLivesLabel()
{
LivesLabel.Text = Tr("LIVES_LABEL") + ": " + _gameManager.GetLives();
LivesLabel.Text = Tr("LIVES_LABEL") + ": " + (Store?.Player.Lives ?? 0);
}
private void SetHealthBar()

View File

@@ -18,7 +18,7 @@ public partial class Marketplace : Control
[Export] public PackedScene MarketplaceButtonScene { get; set; }
[Export] public PackedScene SkillButtonScene { get; set; }
private GameManager GameManager => GameManager.Instance;
private GameStateStore Store => GameStateStore.Instance;
private SkillManager SkillManager => SkillManager.Instance;
private readonly List<Button> _unlockButtons = [];
private readonly List<SkillButton> _skillButtons = [];
@@ -33,7 +33,7 @@ public partial class Marketplace : Control
foreach (var skill in skillsToUnlock) CreateUpgradeButton(skill);
var unlockedSkills = GameManager.GetUnlockedSkills();
var unlockedSkills = Store.GetAllUnlockedSkills();
foreach (var skill in unlockedSkills) CreateSkillButton(skill);
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked;
@@ -113,7 +113,7 @@ public partial class Marketplace : Control
private void OnUpgradeButtonPressed(SkillData skill)
{
if (GameManager.IsSkillUnlocked(skill))
if (Store.IsSkillUnlocked(skill))
{
if (skill.Level < skill.MaxLevel)
{

View File

@@ -13,14 +13,12 @@ public partial class MarketplaceButton : Button
[Export] public Texture2D LockedSkillIcon { get; set; }
[Export] public Container SkillLevelContainer { get; set; }
private GameManager _gameManager;
private SkillUnlockerComponent _skillUnlockerComponent;
private SkillManager _skillManager;
public override void _Ready()
{
_gameManager = GameManager.Instance;
var player = _gameManager.Player;
var player = GameManager.Instance?.Player;
if (player == null) return;
_skillUnlockerComponent = player.GetNodeOrNull<SkillUnlockerComponent>("SkillUnlockerComponent");
@@ -59,7 +57,7 @@ public partial class MarketplaceButton : Button
return;
}
var isUnlocked = _gameManager.IsSkillUnlocked(Data);
var isUnlocked = GameStateStore.Instance?.IsSkillUnlocked(Data) ?? false;
for (var i = 0; i < SkillLevelContainer.GetChildCount(); i++)
{

View File

@@ -53,7 +53,7 @@ public partial class PauseMenu : Control
private void OnMainMenuPressed()
{
GameManager.ResumeGame();
GameManager.ResetCurrentSessionState();
GameStateStore.Instance?.ResetSession();
GetTree().ChangeSceneToPacked(MainMenuScene);
}