feat: Add Rider IDE configuration files and update project settings, along with minor script and export preset modifications.
This commit is contained in:
@@ -9,14 +9,20 @@ namespace Mr.BrickAdventures.scripts.components;
|
|||||||
public partial class CollectableComponent : Node
|
public partial class CollectableComponent : Node
|
||||||
{
|
{
|
||||||
private bool _hasFadeAway = false;
|
private bool _hasFadeAway = false;
|
||||||
|
|
||||||
[Export] public Area2D Area2D { get; set; }
|
[Export] public Area2D Area2D { get; set; }
|
||||||
[Export] public CollisionShape2D CollisionShape { get; set; }
|
[Export] public CollisionShape2D CollisionShape { get; set; }
|
||||||
[Export] public CollectableResource Data { get; set; }
|
[Export] public CollectableResource Data { get; set; }
|
||||||
[Export] public AudioStreamPlayer2D Sfx {get; set; }
|
[Export] public AudioStreamPlayer2D Sfx { get; set; }
|
||||||
|
|
||||||
[Signal] public delegate void CollectedEventHandler(float amount, CollectableType type, Node2D body);
|
[Signal] public delegate void CollectedEventHandler(float amount, CollectableType type, Node2D body);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delegate for checking if collection should be allowed.
|
||||||
|
/// Return false to prevent collection.
|
||||||
|
/// </summary>
|
||||||
|
public Func<Node2D, bool> CanCollect { get; set; }
|
||||||
|
|
||||||
private FloatingTextManager _floatingTextManager;
|
private FloatingTextManager _floatingTextManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
@@ -25,10 +31,10 @@ public partial class CollectableComponent : Node
|
|||||||
Area2D.BodyEntered += OnArea2DBodyEntered;
|
Area2D.BodyEntered += OnArea2DBodyEntered;
|
||||||
else
|
else
|
||||||
GD.PushError("Collectable node missing Area2D node.");
|
GD.PushError("Collectable node missing Area2D node.");
|
||||||
|
|
||||||
if (Owner.HasNode("FadeAwayComponent"))
|
if (Owner.HasNode("FadeAwayComponent"))
|
||||||
_hasFadeAway = true;
|
_hasFadeAway = true;
|
||||||
|
|
||||||
_floatingTextManager = GetNode<FloatingTextManager>("/root/FloatingTextManager");
|
_floatingTextManager = GetNode<FloatingTextManager>("/root/FloatingTextManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +44,9 @@ public partial class CollectableComponent : Node
|
|||||||
{
|
{
|
||||||
if (!body.HasNode("CanPickUpComponent")) return;
|
if (!body.HasNode("CanPickUpComponent")) return;
|
||||||
|
|
||||||
|
// Allow components to veto collection (e.g., full health for potions)
|
||||||
|
if (CanCollect != null && !CanCollect(body)) return;
|
||||||
|
|
||||||
if (Owner is Node2D ownerNode)
|
if (Owner is Node2D ownerNode)
|
||||||
{
|
{
|
||||||
switch (Data.Type)
|
switch (Data.Type)
|
||||||
@@ -53,13 +62,13 @@ public partial class CollectableComponent : Node
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EmitSignalCollected(Data.Amount, Data.Type, body);
|
EmitSignalCollected(Data.Amount, Data.Type, body);
|
||||||
CollisionShape?.CallDeferred("set_disabled", true);
|
CollisionShape?.CallDeferred("set_disabled", true);
|
||||||
Sfx?.Play();
|
Sfx?.Play();
|
||||||
|
|
||||||
if (_hasFadeAway) return;
|
if (_hasFadeAway) return;
|
||||||
|
|
||||||
if (Sfx != null)
|
if (Sfx != null)
|
||||||
await ToSignal(Sfx, AudioStreamPlayer2D.SignalName.Finished);
|
await ToSignal(Sfx, AudioStreamPlayer2D.SignalName.Finished);
|
||||||
Owner.QueueFree();
|
Owner.QueueFree();
|
||||||
|
|||||||
@@ -16,16 +16,27 @@ public partial class HealComponent : Node
|
|||||||
GD.PushError("HealComponent: Collectable is not set.");
|
GD.PushError("HealComponent: Collectable is not set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register check to prevent collecting when at full health
|
||||||
|
Collectable.CanCollect = CanCollectHealth;
|
||||||
Collectable.Collected += OnCollected;
|
Collectable.Collected += OnCollected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool CanCollectHealth(Node2D body)
|
||||||
|
{
|
||||||
|
var healthComponent = body.GetNodeOrNull<HealthComponent>("HealthComponent");
|
||||||
|
if (healthComponent == null) return true; // Allow collection if no health component
|
||||||
|
|
||||||
|
// Prevent collection if already at full health
|
||||||
|
return healthComponent.Health < healthComponent.MaxHealth;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnCollected(float amount, CollectableType type, Node2D body)
|
private void OnCollected(float amount, CollectableType type, Node2D body)
|
||||||
{
|
{
|
||||||
if (type != CollectableType.Health) return;
|
if (type != CollectableType.Health) return;
|
||||||
|
|
||||||
if (Collectable == null) return;
|
if (Collectable == null) return;
|
||||||
|
|
||||||
var healthComponent = body.GetNodeOrNull<HealthComponent>("HealthComponent");
|
var healthComponent = body.GetNodeOrNull<HealthComponent>("HealthComponent");
|
||||||
if (healthComponent == null) return;
|
if (healthComponent == null) return;
|
||||||
|
|
||||||
@@ -34,14 +45,14 @@ public partial class HealComponent : Node
|
|||||||
{
|
{
|
||||||
PlayHealFx();
|
PlayHealFx();
|
||||||
}
|
}
|
||||||
|
|
||||||
Owner.QueueFree();
|
Owner.QueueFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlayHealFx()
|
private void PlayHealFx()
|
||||||
{
|
{
|
||||||
if (HealFx == null) return;
|
if (HealFx == null) return;
|
||||||
|
|
||||||
HealFx.Restart();
|
HealFx.Restart();
|
||||||
HealFx.Emitting = true;
|
HealFx.Emitting = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user