Elevators

This commit is contained in:
Marco 2025-06-12 16:26:11 +02:00
commit 4fc136e5d7
39 changed files with 4471 additions and 264 deletions

View file

@ -0,0 +1,48 @@
using Godot;
namespace Cirno.Scripts.Actors;
public partial class Elevator3D : PathFollow3D, IActivable
{
[Export] public float Speed { get; set; }
private bool _isMoving = false;
private float _multiplier = 1f;
public override void _Process(double delta)
{
if (!_isMoving) return;
ProgressRatio += (Speed * (float)delta) * _multiplier;
if (ProgressRatio is >= 1 or <= 0)
{
_isMoving = false;
}
}
public bool Activate(ActivationType activationType = ActivationType.Toggle)
{
if (_isMoving) return false;
StartMoving();
return true;
}
public void StartMoving()
{
if (_isMoving) return;
_isMoving = true;
if (ProgressRatio <= 0)
{
_multiplier = 1f;
}
else if (ProgressRatio >= 1)
{
_multiplier = -1f;
}
}
}

View file

@ -0,0 +1 @@
uid://cyr7ypanl8drq

View file

@ -0,0 +1,53 @@
using Godot;
namespace Cirno.Scripts.Components.FSM._3DPlayer;
public partial class IsoInteractionController : Area3D, IModule<PlayerState, CharacterBody3D>
{
private bool _enabled = false;
public bool Enabled
{
get => _enabled;
set
{
if (_enabled == value) return;
_enabled = value;
if (_enabled)
{
EmitSignal(SignalName.InteractionStarted);
}
}
}
[Signal]
public delegate void InteractionStartedEventHandler();
public IStateMachine<PlayerState, CharacterBody3D> StateMachine { get; private set; }
public void EnterState(PlayerState state)
{
Enabled = true;
}
public void ExitState(PlayerState state)
{
Enabled = false;
}
public void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
{
StateMachine = machine;
}
public void Process(double delta)
{
}
public void PhysicsProcess(double delta)
{
}
}

View file

@ -0,0 +1 @@
uid://bm73kgly8gv2i

View file

@ -0,0 +1,72 @@
using Cirno.Scripts.Components.FSM._3DPlayer;
using Godot;
namespace Cirno.Scripts.Interactables;
public partial class AreaTrigger3D : Area3D
{
[Export] public Node3D Target { get; set; }
[Export] public ActivationType ActivationType { get; set; } = Scripts.ActivationType.Toggle;
[Export] public bool OneTime { get; set; }
[Export] public bool DoNotActivateOnFirst { get; set; }
private int _activations = 0;
[Signal]
public delegate void ActivatedEventHandler();
private IsoInteractionController _cachedPlayer;
private bool Activate()
{
if (_activations == 0 && DoNotActivateOnFirst)
{
_activations++;
return false;
}
if (OneTime && _activations > 0) return false;
if (Target != null)
{
if (Target is not IActivable target)
{
GD.PrintErr($"Target {Target.Name} is not activable");
return false;
}
target.Activate(ActivationType);
}
EmitSignal(nameof(Activated));
_activations++;
return true;
}
private void _on_area_entered(Area3D area)
{
if (area is not IsoInteractionController player) return;
if (player.Enabled)
{
Activate();
}
else
{
_cachedPlayer = player;
_cachedPlayer.InteractionStarted += PlayerOnInteractionStarted;
}
}
private void PlayerOnInteractionStarted()
{
Activate();
if (_cachedPlayer != null)
{
_cachedPlayer.InteractionStarted -= PlayerOnInteractionStarted;
}
}
}

View file

@ -0,0 +1 @@
uid://btyooucm1g70g