- Fix double-execution bug in LevelStateHandler (coins/skills were committed twice per level) - Fix DamageComponent to track multiple targets via HashSet instead of single node - Fix HealthComponent: update health immediately, decouple from PlayerController via signal wiring in PlayerController - Remove dead loop in SkillManager.RemoveSkill; simplify O(n²) throw skill loop - Replace GetNode<T>(path) with .Instance across managers; add Instance to StatisticsManager/SpeedRunManager - GameManager.GetPlayer() now uses EventBus.PlayerSpawned instead of scanning all scene nodes - UIManager.UiStack: remove [Export], use private List<Control> - PlayerState: extract DefaultLives constant, simplify CreateDefault()
66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using Godot;
|
|
using Mr.BrickAdventures.scripts.State;
|
|
|
|
namespace Mr.BrickAdventures.Autoloads;
|
|
|
|
/// <summary>
|
|
/// Manages game statistics using GameStateStore.
|
|
/// </summary>
|
|
public partial class StatisticsManager : Node
|
|
{
|
|
public static StatisticsManager Instance { get; private set; }
|
|
|
|
public override void _Ready() => Instance = this;
|
|
public override void _ExitTree() { if (Instance == this) Instance = null; }
|
|
|
|
/// <summary>
|
|
/// Gets the statistics dictionary from the store.
|
|
/// </summary>
|
|
private Dictionary<string, int> GetStats()
|
|
{
|
|
return GameStateStore.Instance?.Player.Statistics ?? new Dictionary<string, int>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Increases a numerical statistic by a given amount.
|
|
/// </summary>
|
|
public void IncrementStat(string statName, int amount = 1)
|
|
{
|
|
var stats = GetStats();
|
|
if (stats.TryGetValue(statName, out var currentValue))
|
|
{
|
|
stats[statName] = currentValue + amount;
|
|
}
|
|
else
|
|
{
|
|
stats[statName] = amount;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets a statistic to a specific value.
|
|
/// </summary>
|
|
public void SetStat(string statName, int value)
|
|
{
|
|
var stats = GetStats();
|
|
stats[statName] = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the value of a statistic.
|
|
/// </summary>
|
|
public int GetStat(string statName)
|
|
{
|
|
var stats = GetStats();
|
|
return stats.TryGetValue(statName, out var value) ? value : 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a copy of all statistics.
|
|
/// </summary>
|
|
public Dictionary<string, int> GetAllStats()
|
|
{
|
|
return new Dictionary<string, int>(GetStats());
|
|
}
|
|
} |