Add some props to ArenaExterior

pull/43/head
John Montagu, the 4th Earl of Sandvich 2024-08-25 23:56:01 -07:00
parent 95a8e8895a
commit a37288e672
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
2 changed files with 255 additions and 43 deletions

View File

@ -0,0 +1,70 @@
using Godot;
using System.Linq;
using System.Collections.Generic;
namespace SupaLidlGame.BoundingBoxes;
public partial class OcclusionTrigger : Area2D
{
[Export]
public double FadeDuration { get; set; }
[Export]
public Godot.Collections.Array<string> Groups { get; set; }
private Tween _tween = null;
public override void _Ready()
{
Connect(SignalName.BodyEntered, new Callable(this, nameof(OnBodyEntered)));
Connect(SignalName.BodyExited, new Callable(this, nameof(OnBodyExited)));
}
private IEnumerable<CanvasItem> GetCanvasItems()
{
IEnumerable<IEnumerable<CanvasItem>> pack()
{
foreach (string group in Groups)
{
var nodes = GetTree().GetNodesInGroup(group)
.OfType<CanvasItem>();
yield return nodes;
}
}
return pack().SelectMany(e => e);
}
private void OnBodyEntered(Node2D _)
{
if (IsInstanceValid(_tween))
{
_tween.Kill();
}
_tween = GetTree().CreateTween();
_tween.SetParallel();
foreach (var node in GetCanvasItems())
{
_tween.TweenProperty(node, "modulate", Colors.Transparent, FadeDuration);
}
}
private void OnBodyExited(Node2D _)
{
if (IsInstanceValid(_tween))
{
_tween.Kill();
}
_tween = GetTree().CreateTween();
_tween.SetParallel();
foreach (var node in GetCanvasItems())
{
_tween.TweenProperty(node, "modulate", Colors.White, FadeDuration);
}
}
}

File diff suppressed because one or more lines are too long