refactor: fix bugs and improve architecture

- 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()
This commit is contained in:
2026-03-19 01:41:14 +01:00
parent 427bef6509
commit 321905e68e
11 changed files with 85 additions and 161 deletions

View File

@@ -2,7 +2,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Godot;
using Mr.BrickAdventures;
using Mr.BrickAdventures.Autoloads;
namespace Mr.BrickAdventures.scripts.components;
@@ -34,8 +33,19 @@ public partial class PlayerController : CharacterBody2D
public override void _Ready()
{
var skillManager = GetNodeOrNull<SkillManager>(Constants.SkillManagerPath);
skillManager?.RegisterPlayer(this);
SkillManager.Instance?.RegisterPlayer(this);
// Wire HealthComponent signals to global EventBus events
var health = GetNodeOrNull<HealthComponent>("HealthComponent");
if (health != null)
{
health.Death += () => EventBus.EmitPlayerDied(GlobalPosition);
health.HealthChanged += (delta, total) =>
{
if (delta < 0f) EventBus.EmitPlayerDamaged(Mathf.Abs(delta), total, GlobalPosition);
else EventBus.EmitPlayerHealed(delta, total, GlobalPosition);
};
}
_inputHandler = GetNode<PlayerInputHandler>("PlayerInputHandler");
foreach (var child in MovementAbilitiesContainer.GetChildren())
@@ -49,6 +59,7 @@ public partial class PlayerController : CharacterBody2D
_ = ConnectJumpAndGravityAbilities();
EmitSignalMovementAbilitiesChanged();
EventBus.EmitPlayerSpawned(this);
}
public override void _PhysicsProcess(double delta)