From 2cbf7e15a413a268d4aa048217d7d39cbe931d8c Mon Sep 17 00:00:00 2001 From: jonathan Date: Wed, 4 Feb 2026 19:40:10 +0100 Subject: [PATCH] Changed camera no not need a direct reference to vesna --- .../CSharp/Common/Camera/CameraController.cs | 20 +------------ scripts/CSharp/Common/Camera/CameraTarget.cs | 29 +++++++++++++++++++ .../CSharp/Common/Camera/CameraTarget.cs.uid | 1 + 3 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 scripts/CSharp/Common/Camera/CameraTarget.cs create mode 100644 scripts/CSharp/Common/Camera/CameraTarget.cs.uid diff --git a/scripts/CSharp/Common/Camera/CameraController.cs b/scripts/CSharp/Common/Camera/CameraController.cs index 661e65c..73c88e4 100644 --- a/scripts/CSharp/Common/Camera/CameraController.cs +++ b/scripts/CSharp/Common/Camera/CameraController.cs @@ -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; } - } diff --git a/scripts/CSharp/Common/Camera/CameraTarget.cs b/scripts/CSharp/Common/Camera/CameraTarget.cs new file mode 100644 index 0000000..1eff8cc --- /dev/null +++ b/scripts/CSharp/Common/Camera/CameraTarget.cs @@ -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 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); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Camera/CameraTarget.cs.uid b/scripts/CSharp/Common/Camera/CameraTarget.cs.uid new file mode 100644 index 0000000..0f69658 --- /dev/null +++ b/scripts/CSharp/Common/Camera/CameraTarget.cs.uid @@ -0,0 +1 @@ +uid://ccdhx1lt4n271