cirnogodot/Scripts/Components/FSM/Elevator/ElevatorProxy.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2025-03-06 10:27:06 +01:00
using System;
2025-03-06 11:34:45 +01:00
using System.Collections.Generic;
2025-03-06 10:27:06 +01:00
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Components.FSM.Elevator;
public partial class ElevatorProxy : Area2D, IActivable
{
2025-03-11 15:03:44 +01:00
[Export] public ElevatorState StartingState { get; protected set; } = ElevatorState.Bottom;
[Export] public float MovementTime { get; protected set; } = 1.0f;
[Export] public Path2D ElevatorPath { get; protected set; }
[Export] public CollisionShape2D TopBody { get; protected set; }
[Signal]
public delegate void ActivatedEventHandler(ActivationType type);
2025-03-06 10:27:06 +01:00
public Vector2 Top => ElevatorPath.Curve.GetPointPosition(0);
2025-03-11 15:03:44 +01:00
2025-03-06 10:27:06 +01:00
public Vector2 Bottom => ElevatorPath.Curve.GetPointPosition(1);
2025-03-11 15:03:44 +01:00
public IStateMachine<ElevatorState, ElevatorProxy> StateMachine { get; set; }
2025-03-06 10:27:06 +01:00
// public void SetPosition(Vector2 position)
// {
//
// }
2025-03-11 15:03:44 +01:00
2025-03-06 11:34:45 +01:00
public InteractionController CachedPlayer { get; private set; }
2025-03-06 10:27:06 +01:00
2025-03-09 21:58:25 +01:00
public bool Activate(ActivationType activationType = ActivationType.Toggle)
2025-03-06 10:27:06 +01:00
{
EmitSignal(SignalName.Activated, (int)activationType);
2025-03-09 21:58:25 +01:00
return true;
2025-03-06 10:27:06 +01:00
}
2025-03-06 11:34:45 +01:00
private void _on_area_entered(Area2D area)
{
if (area is InteractionController player)
{
CachedPlayer = player;
}
}
2025-03-11 15:03:44 +01:00
2025-03-06 11:34:45 +01:00
private void _on_area_exited(Area2D area)
{
if (area is InteractionController player)
{
CachedPlayer = null;
}
}
2025-03-06 10:27:06 +01:00
}