Changed camera no not need a direct reference to vesna

pull/54/head
jonathan 2 months ago
parent 628da80ed3
commit 2cbf7e15a4

@ -5,26 +5,8 @@ namespace Babushka.scripts.CSharp.Common.Camera;
public partial class CameraController : Camera2D
{
#region Singleton ( Contains _EnterTree() ) // TODO: use autoload or other solution
public static CameraController Instance { get; private set; } = null!;
public override void _EnterTree()
{
Instance = this;
}
#endregion
[Export] private Node2D _followNode;
public FightHappening? fightToShow;
public override void _Process(double delta)
{
this.GlobalPosition = /*fightToShow?.camPositionNode.GlobalPosition ??*/ _followNode.GlobalPosition;
GlobalPosition = CameraTarget.GetActiveTarget().GlobalPosition;
}
}

@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Linq;
using Godot;
namespace Babushka.scripts.CSharp.Common.Camera;
public partial class CameraTarget : Node2D
{
private static readonly List<CameraTarget> AllTargets = new();
public static CameraTarget GetActiveTarget() // Called every frame. Maybe needs performance optimization in the future
{
return AllTargets
.OrderByDescending(t => t.Priority)
.First();
}
[Export] public float Priority { get; set; }
public override void _EnterTree()
{
AllTargets.Add(this);
}
public override void _ExitTree()
{
AllTargets.Remove(this);
}
}
Loading…
Cancel
Save