Files
MovementTests/addons/forge/nodes/EffectArea2D.cs
Minimata c4be97e0de
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 21s
Create tag and build when new code gets to main / Test (push) Successful in 6m56s
Create tag and build when new code gets to main / Export (push) Successful in 9m3s
added forge addon
2026-02-08 15:16:01 +01:00

82 lines
2.0 KiB
C#

// Copyright © Gamesmiths Guild.
using System.Diagnostics;
using Gamesmiths.Forge.Core;
using Gamesmiths.Forge.Godot.Core;
using Godot;
namespace Gamesmiths.Forge.Godot.Nodes;
[GlobalClass]
[Icon("uid://cnjrjkgwyewjx")]
public partial class EffectArea2D : Area2D
{
private EffectApplier? _effectApplier;
[Export]
public Node? EffectOwner { get; set; }
[Export]
public Node? EffectSource { get; set; }
[Export]
public int EffectLevel { get; set; } = 1;
[Export]
public EffectTriggerMode TriggerMode { get; set; }
private IForgeEntity? OwnerEntity => EffectOwner as IForgeEntity;
private IForgeEntity? SourceEntity => EffectSource as IForgeEntity;
public override void _Ready()
{
if (EffectOwner is not null && EffectOwner is not IForgeEntity)
{
GD.PushError($"{nameof(EffectOwner)} must implement {nameof(IForgeEntity)}.");
}
base._Ready();
_effectApplier = new EffectApplier(this);
switch (TriggerMode)
{
case EffectTriggerMode.OnEnter:
BodyEntered += ApplyEffects;
AreaEntered += ApplyEffects;
break;
case EffectTriggerMode.OnExit:
BodyExited += ApplyEffects;
AreaExited += ApplyEffects;
break;
case EffectTriggerMode.OnStay:
BodyEntered += AddEffects;
AreaEntered += AddEffects;
BodyExited += RemoveEffects;
AreaExited += RemoveEffects;
break;
}
}
private void ApplyEffects(Node2D node)
{
Debug.Assert(_effectApplier is not null, $"{_effectApplier} should have been initialized on _Ready().");
_effectApplier.ApplyEffects(node, OwnerEntity, SourceEntity, EffectLevel);
}
private void AddEffects(Node2D node)
{
Debug.Assert(_effectApplier is not null, $"{_effectApplier} should have been initialized on _Ready().");
_effectApplier.AddEffects(node, OwnerEntity, SourceEntity, EffectLevel);
}
private void RemoveEffects(Node2D node)
{
Debug.Assert(_effectApplier is not null, $"{_effectApplier} should have been initialized on _Ready().");
_effectApplier.RemoveEffects(node);
}
}