mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 13:55:54 +00:00
Chain activables
This commit is contained in:
parent
a430554e27
commit
77b18d250e
5 changed files with 144 additions and 32 deletions
32
Scripts/Activables/ChainActivable.cs
Normal file
32
Scripts/Activables/ChainActivable.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
||||
public partial class ChainActivable : Activable
|
||||
{
|
||||
[Export] private Array<Node2D> _targets;
|
||||
|
||||
protected void ActivateTargets()
|
||||
{
|
||||
foreach (var activationTarget in _targets)
|
||||
{
|
||||
ActivateTarget(activationTarget);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ActivateTarget(Node2D activationTarget)
|
||||
{
|
||||
if (activationTarget is not IActivable target)
|
||||
{
|
||||
GD.PrintErr($"Target {activationTarget.Name} is not activable");
|
||||
return false;
|
||||
}
|
||||
|
||||
target?.Activate();
|
||||
|
||||
GD.Print($"{activationTarget.Name} activated");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,12 +3,12 @@ using Godot.Collections;
|
|||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
||||
public partial class DialogueStarter : Activable
|
||||
public partial class DialogueStarter : ChainActivable
|
||||
{
|
||||
|
||||
[Export] private string _trackName = "timeline";
|
||||
|
||||
[Export] private Array<Node2D> _dialogueEndActivationTargets;
|
||||
//[Export] private Array<Node2D> _dialogueEndActivationTargets;
|
||||
|
||||
private Node _dialogic;
|
||||
|
||||
|
|
@ -50,24 +50,25 @@ public partial class DialogueStarter : Activable
|
|||
private void DialogueEndAction()
|
||||
{
|
||||
_gameManager.ChangeState(GameState.Playing);
|
||||
foreach (var activationTarget in _dialogueEndActivationTargets)
|
||||
{
|
||||
ActivateTarget(activationTarget);
|
||||
}
|
||||
ActivateTargets();
|
||||
// foreach (var activationTarget in _dialogueEndActivationTargets)
|
||||
// {
|
||||
// ActivateTarget(activationTarget);
|
||||
// }
|
||||
}
|
||||
|
||||
private bool ActivateTarget(Node2D activationTarget)
|
||||
{
|
||||
if (activationTarget is not IActivable target)
|
||||
{
|
||||
GD.PrintErr($"Target {activationTarget.Name} is not activable");
|
||||
return false;
|
||||
}
|
||||
|
||||
target?.Activate();
|
||||
|
||||
GD.Print($"{activationTarget.Name} activated");
|
||||
|
||||
return true;
|
||||
}
|
||||
// private bool ActivateTarget(Node2D activationTarget)
|
||||
// {
|
||||
// if (activationTarget is not IActivable target)
|
||||
// {
|
||||
// GD.PrintErr($"Target {activationTarget.Name} is not activable");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// target?.Activate();
|
||||
//
|
||||
// GD.Print($"{activationTarget.Name} activated");
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
55
Scripts/Activables/PlayerMover.cs
Normal file
55
Scripts/Activables/PlayerMover.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
||||
public partial class PlayerMover : ChainActivable
|
||||
{
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
[Export]
|
||||
public Vector2 RelativeTargetPosition = Vector2.Zero;
|
||||
|
||||
[Export]
|
||||
public float MovementTime = 1f;
|
||||
|
||||
[Export]
|
||||
public Tween.EaseType EaseType = Tween.EaseType.InOut;
|
||||
|
||||
[Export]
|
||||
public Tween.TransitionType TransitionType = Tween.TransitionType.Linear;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
_gameManager = this.GetGameManager();
|
||||
}
|
||||
|
||||
public override void Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
if (_gameManager.Player is null) return;
|
||||
|
||||
_ = MovePlayer();
|
||||
}
|
||||
|
||||
private async Task MovePlayer()
|
||||
{
|
||||
_gameManager.Player.RequestMovementDisable(true);
|
||||
|
||||
Tween tween = GetTree().CreateTween();
|
||||
tween.SetEase(EaseType);
|
||||
tween.SetTrans(TransitionType);
|
||||
tween.TweenProperty(_gameManager.Player, "global_position", _gameManager.Player.GlobalPosition + RelativeTargetPosition, MovementTime);
|
||||
|
||||
// Wait for the tween to finish
|
||||
await ToSignal(tween, "finished");
|
||||
|
||||
_gameManager.Player.RequestMovementDisable(false);
|
||||
|
||||
ActivateTargets();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue