Chain activables

This commit is contained in:
Marco 2025-02-13 13:44:44 +01:00
commit 77b18d250e
5 changed files with 144 additions and 32 deletions

View file

@ -8,4 +8,5 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fbb1b701f3c7411227a9d2e09f965d857ff3e771557650c4f513e427d77c_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerMovement_005FScriptMethods_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F4af4702ac4bbb9ab7299554c41beea2bf703b4a_003FPlayerMovement_005FScriptMethods_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AScriptManagerBridge_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F4fd22cd129a84c16b5d8004b467c426f518800_003F3a_003Fc456f450_003FScriptManagerBridge_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVariantUtils_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F4fd22cd129a84c16b5d8004b467c426f518800_003F38_003Fb04c4423_003FVariantUtils_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVariantUtils_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F4fd22cd129a84c16b5d8004b467c426f518800_003F38_003Fb04c4423_003FVariantUtils_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVector2_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F08f0ea1144634eedbe3a87b9762ef1dd4bd200_003F85_003F367e08bf_003FVector2_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>

File diff suppressed because one or more lines are too long

View 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;
}
}

View file

@ -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;
// }
}

View 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();
}
}