SupaLidlGame/BoundingBoxes/ConnectorBox.cs

68 lines
1.6 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-08-01 23:49:48 -07:00
using SupaLidlGame.Extensions;
using SupaLidlGame.Events;
2023-03-22 21:22:51 -07:00
2023-06-03 18:21:46 -07:00
namespace SupaLidlGame.BoundingBoxes;
public partial class ConnectorBox : Area2D
2023-03-22 21:22:51 -07:00
{
2023-06-03 18:21:46 -07:00
[Signal]
public delegate void RequestedEnterEventHandler(
ConnectorBox box,
Player player);
2023-03-25 10:21:24 -07:00
2023-08-05 00:32:43 -07:00
[Export(PropertyHint.File, "*.tscn")]
2023-06-03 18:21:46 -07:00
public string ToArea { get; set; }
2023-03-22 21:22:51 -07:00
2023-06-03 18:21:46 -07:00
[Export]
public string ToConnector { get; set; }
2023-03-25 10:21:24 -07:00
2023-06-03 18:21:46 -07:00
[Export]
public string Identifier { get; set; }
2023-03-26 10:53:45 -07:00
2023-06-03 18:21:46 -07:00
/// <summary>
/// Determines if the connector requires the user to interact to enter
/// the connector
/// </summary>
[Export]
2023-08-01 23:49:48 -07:00
public InteractionTrigger InteractionTrigger { get; set; }
2023-03-25 10:21:24 -07:00
2023-06-03 18:21:46 -07:00
private Player _player = null;
2023-03-25 10:21:24 -07:00
2023-06-03 18:21:46 -07:00
public override void _Ready()
{
BodyEntered += (Node2D body) =>
{
GD.Print(body.Name + " entered");
2023-08-01 23:49:48 -07:00
if (body is Player && InteractionTrigger is null)
2023-03-25 10:21:24 -07:00
{
2023-08-01 23:49:48 -07:00
OnInteraction();
2023-06-03 18:21:46 -07:00
}
};
2023-03-25 10:21:24 -07:00
2023-08-01 23:49:48 -07:00
if (InteractionTrigger is not null)
2023-06-03 18:21:46 -07:00
{
2023-08-01 23:49:48 -07:00
InteractionTrigger.Interaction += OnInteraction;
}
2023-06-03 18:21:46 -07:00
}
2023-03-25 10:21:24 -07:00
2023-06-03 18:21:46 -07:00
public override void _Process(double delta)
{
base._Process(delta);
2023-03-22 21:22:51 -07:00
}
2023-08-01 23:49:48 -07:00
protected void OnInteraction()
{
var eventBus = this.GetEventBus();
System.Diagnostics.Debug.Assert(eventBus is not null);
var args = new Events.RequestAreaArgs
{
Area = ToArea,
Connector = ToConnector,
};
eventBus.EmitSignal(EventBus.SignalName.RequestMoveToArea, args);
}
2023-03-22 21:22:51 -07:00
}