SupaLidlGame/BoundingBoxes/ConnectorBox.cs

73 lines
1.7 KiB
C#
Raw Normal View History

2023-03-22 21:22:51 -07:00
using Godot;
using System;
2023-03-25 10:21:24 -07:00
using SupaLidlGame.Characters;
2023-03-22 21:22:51 -07:00
namespace SupaLidlGame.BoundingBoxes
{
public partial class ConnectorBox : Area2D
{
2023-03-25 10:21:24 -07:00
[Signal]
public delegate void RequestedEnterEventHandler(
ConnectorBox box,
Player player);
2023-03-22 21:22:51 -07:00
[Export]
public string ToArea { get; set; }
[Export]
public string ToConnector { get; set; }
2023-03-25 10:21:24 -07:00
2023-03-26 10:53:45 -07:00
[Export]
public string Identifier { get; set; }
2023-03-25 10:21:24 -07:00
/// <summary>
/// Determines if the connector requires the user to interact to enter
/// the connector
/// </summary>
[Export]
2023-03-26 10:53:45 -07:00
public bool RequiresInteraction { get; set; } = false;
2023-03-25 10:21:24 -07:00
[Export]
public CollisionShape2D Collision { get; set; }
private Player _player = null;
public override void _Ready()
{
if (Collision is null)
{
throw new NullReferenceException("Collision not specified");
}
BodyEntered += (Node2D body) =>
{
if (body is Player player)
{
_player = player;
}
};
BodyExited += (Node2D body) =>
{
if (body is Player)
{
_player = null;
}
};
}
public override void _Process(double delta)
{
2023-03-26 10:53:45 -07:00
if (Input.IsActionJustReleased("interact"))
2023-03-25 10:21:24 -07:00
{
2023-03-26 10:53:45 -07:00
if (_player is not null)
{
EmitSignal(SignalName.RequestedEnter, this, _player);
}
2023-03-25 10:21:24 -07:00
}
base._Process(delta);
}
2023-03-22 21:22:51 -07:00
}
}