refactor: Replace hardcoded node paths with constants and remove ScoreComponent.
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Mr.BrickAdventures;
|
||||
using Mr.BrickAdventures.scripts.components;
|
||||
using Mr.BrickAdventures.scripts.interfaces;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
@@ -14,19 +15,19 @@ public partial class SkillManager : Node
|
||||
private PlayerController _player;
|
||||
|
||||
[Export] public Array<SkillData> AvailableSkills { get; set; } = [];
|
||||
|
||||
|
||||
public Dictionary ActiveComponents { get; private set; } = new();
|
||||
|
||||
[Signal]
|
||||
public delegate void ActiveThrowSkillChangedEventHandler(BrickThrowComponent throwComponent);
|
||||
[Signal]
|
||||
public delegate void SkillRemovedEventHandler(SkillData skillData);
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
||||
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called by the PlayerController from its _Ready method to register itself with the manager.
|
||||
/// </summary>
|
||||
@@ -39,7 +40,7 @@ public partial class SkillManager : Node
|
||||
{
|
||||
UnregisterPlayer();
|
||||
}
|
||||
|
||||
|
||||
_player = player;
|
||||
if (_player != null)
|
||||
{
|
||||
@@ -61,7 +62,7 @@ public partial class SkillManager : Node
|
||||
}
|
||||
_player = null;
|
||||
}
|
||||
|
||||
|
||||
public void AddSkill(SkillData skillData)
|
||||
{
|
||||
// Ensure a valid player is registered before adding a skill.
|
||||
@@ -70,7 +71,7 @@ public partial class SkillManager : Node
|
||||
GD.Print("SkillManager: Player not available to add skill.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (ActiveComponents.ContainsKey(skillData.Name))
|
||||
return;
|
||||
|
||||
@@ -98,9 +99,9 @@ public partial class SkillManager : Node
|
||||
if (instance is ISkill skill)
|
||||
{
|
||||
// Initialize the skill with the registered player instance.
|
||||
skill.Initialize(_player, skillData);
|
||||
skill.Initialize(_player, skillData);
|
||||
skill.Activate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr($"Skill scene for '{skillData.Name}' does not implement ISkill!");
|
||||
@@ -111,18 +112,18 @@ public partial class SkillManager : Node
|
||||
// Add the skill node as a child of the player.
|
||||
_player.AddChild(instance);
|
||||
ActiveComponents[skillData.Name] = instance;
|
||||
|
||||
|
||||
if (instance is BrickThrowComponent btc)
|
||||
{
|
||||
EmitSignalActiveThrowSkillChanged(btc);
|
||||
EmitSignalActiveThrowSkillChanged(btc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RemoveSkill(string skillName)
|
||||
{
|
||||
if (!ActiveComponents.TryGetValue(skillName, out var component))
|
||||
return;
|
||||
|
||||
|
||||
if (component.AsGodotObject() is BrickThrowComponent)
|
||||
{
|
||||
EmitSignalActiveThrowSkillChanged(null);
|
||||
@@ -133,7 +134,7 @@ public partial class SkillManager : Node
|
||||
{
|
||||
skill.Deactivate();
|
||||
}
|
||||
|
||||
|
||||
if (IsInstanceValid(inst))
|
||||
inst.QueueFree();
|
||||
|
||||
@@ -150,7 +151,7 @@ public partial class SkillManager : Node
|
||||
var sd = GetSkillByName(skillName);
|
||||
if (sd != null) EmitSignalSkillRemoved(sd);
|
||||
}
|
||||
|
||||
|
||||
private void RemoveAllActiveSkills()
|
||||
{
|
||||
// Create a copy of keys to avoid modification during iteration
|
||||
|
||||
Reference in New Issue
Block a user