refacto: moved systems from player controller physics process to their own signal based systems
This commit is contained in:
52
systems/tween_queue/TweenQueueSystem.cs
Normal file
52
systems/tween_queue/TweenQueueSystem.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class TweenQueueSystem : Node3D
|
||||
{
|
||||
public record TweenInputs(Vector3 Location, float Duration);
|
||||
|
||||
private Queue<TweenInputs> _tweenInputs = new Queue<TweenInputs>();
|
||||
private Node3D _tweenObject;
|
||||
private bool _isTweening = false;
|
||||
|
||||
public void Init(Node3D tweenObject)
|
||||
{
|
||||
_tweenObject = tweenObject;
|
||||
}
|
||||
|
||||
public void EndTween()
|
||||
{
|
||||
_isTweening = false;
|
||||
}
|
||||
|
||||
private void TweenToLocation(TweenInputs inputs)
|
||||
{
|
||||
var (location, duration) = inputs;
|
||||
|
||||
var tween = GetTree().CreateTween();
|
||||
var callback = new Callable(this, MethodName.EndTween);
|
||||
|
||||
tween.TweenProperty(_tweenObject, "position", location, duration);
|
||||
tween.TweenCallback(callback);
|
||||
|
||||
_isTweening = true;
|
||||
tween.Play();
|
||||
}
|
||||
|
||||
public void QueueTween(TweenInputs inputs)
|
||||
{
|
||||
_tweenInputs.Enqueue(inputs);
|
||||
}
|
||||
|
||||
public void QueueTween(Vector3 location, float duration)
|
||||
{
|
||||
QueueTween(new TweenInputs(location, duration));
|
||||
}
|
||||
|
||||
public void ProcessTweens()
|
||||
{
|
||||
if (_tweenInputs.Count > 0 && !_isTweening)
|
||||
TweenToLocation(_tweenInputs.Dequeue());
|
||||
}
|
||||
|
||||
}
|
1
systems/tween_queue/TweenQueueSystem.cs.uid
Normal file
1
systems/tween_queue/TweenQueueSystem.cs.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://crm4u4r56hvg7
|
6
systems/tween_queue/tween_queue_system.tscn
Normal file
6
systems/tween_queue/tween_queue_system.tscn
Normal file
@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dbe5f0p6lvqtr"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://crm4u4r56hvg7" path="res://systems/tween_queue/TweenQueueSystem.cs" id="1_iqosd"]
|
||||
|
||||
[node name="TweenQueueSystem" type="Node3D"]
|
||||
script = ExtResource("1_iqosd")
|
Reference in New Issue
Block a user