using Godot;
namespace DialogueManagerRuntime
{
///
/// Add a to a scene to expose a node (usually the base node) to dialogue.
///
[Tool, Icon("uid://c22t5famre1yo")]
public partial class DialogueStateContext : Node
{
private string alias = "";
///
/// The name used in dialogue to refer to the exposed target node.
///
[Export]
public string Alias
{
get => alias;
set
{
alias = value;
UpdateConfigurationWarnings();
}
}
private Node target = null;
///
/// The target whose values are exposed to dialogue.
///
[Export]
public Node Target
{
get => target;
set
{
target = value;
UpdateConfigurationWarnings();
}
}
public override void _EnterTree()
{
if (!Engine.IsEditorHint())
{
DialogueManager.Instance.Call("register_state_context", Alias, Target);
}
}
public override void _ExitTree()
{
if (!Engine.IsEditorHint())
{
DialogueManager.Instance.Call("unregister_state_context", Alias);
}
}
public override string[] _GetConfigurationWarnings()
{
var warnings = new System.Collections.Generic.List();
if (string.IsNullOrEmpty(Alias))
{
warnings.Add("Alias cannot be empty.");
}
if (Target == null)
{
warnings.Add("Target cannot be null.");
}
return warnings.ToArray();
}
}
}