You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1016 B
37 lines
1016 B
using Babushka.scripts.CSharp.Common.Services;
|
|
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.NPC;
|
|
|
|
public partial class TalkingCharacter : Node2D
|
|
{
|
|
[Export] private AnimatedSprite2D? _sprite;
|
|
[Export] private string[] _timelinesToPlay;
|
|
[Export] private bool _retriggerSameTimeline = false;
|
|
|
|
private int _timelineIndex = 0;
|
|
|
|
[Signal] public delegate void TalkingEventHandler(string timelineName);
|
|
|
|
public void StartTalking()
|
|
{
|
|
if (_sprite != null)
|
|
_sprite.Animation = "talk";
|
|
EmitSignal(SignalName.Talking, _timelinesToPlay[_timelineIndex]);
|
|
if (!_retriggerSameTimeline)
|
|
_timelineIndex++;
|
|
InputService.Instance.InputEnabled = false;
|
|
if (_sprite != null)
|
|
_sprite.Play();
|
|
}
|
|
|
|
public void StopTalking()
|
|
{
|
|
if (_sprite != null)
|
|
_sprite.Animation = "idle";
|
|
InputService.Instance.InputEnabled = true;
|
|
if (_sprite != null)
|
|
_sprite.Play();
|
|
}
|
|
}
|