using Godot;
using Mr.BrickAdventures.Autoloads;
using Mr.BrickAdventures.Progression;
using Mr.BrickAdventures.scripts.Resources;
namespace Mr.BrickAdventures.scripts.Events;
///
/// Grants a skill picked up in a level.
///
///
/// Only records that it is owned. Attaching the live component is SkillManager's job, driven by
/// SkillSetChanged — previously this did both as two separate calls, and the second could silently do
/// nothing if no player was registered yet, leaving the skill owned but inert.
///
public partial class SkillCollectHandler : Node
{
public override void _Ready()
{
EventBus.Instance.SkillCollected += OnSkillCollected;
}
public override void _ExitTree()
{
if (EventBus.Instance != null)
EventBus.Instance.SkillCollected -= OnSkillCollected;
}
private void OnSkillCollected(SkillData skill, Vector2 position)
{
if (skill == null || string.IsNullOrWhiteSpace(skill.Name)) return;
ProgressionRoot.Instance?.GrantSkill(SkillId.Of(skill.Name));
}
}