// Copyright © Gamesmiths Guild.
using Godot;
using Godot.Collections;
namespace Gamesmiths.Forge.Godot.Resources.Statescript;
///
/// Resource representing a complete Statescript graph. Contains all nodes and their connections.
///
[Tool]
[GlobalClass]
[Icon("uid://b6yrjb46fluw3")]
public partial class StatescriptGraph : Resource
{
///
/// Gets or sets the display name for this graph.
///
[Export]
public string StatescriptName { get; set; } = "New Statescript";
///
/// Gets or sets the nodes in this graph.
///
[Export]
public Array Nodes { get; set; } = [];
///
/// Gets or sets the connections between nodes in this graph.
///
[Export]
public Array Connections { get; set; } = [];
///
/// Gets or sets the graph variable definitions.
///
[Export]
public Array Variables { get; set; } = [];
///
/// Gets or sets the scroll offset of the graph editor when this graph was last saved.
///
[Export]
public Vector2 ScrollOffset { get; set; }
///
/// Gets or sets the zoom level of the graph editor when this graph was last saved.
///
[Export]
public float Zoom { get; set; } = 1.0f;
///
/// Ensures the graph has an Entry node. Called when the graph is first created or loaded.
///
public void EnsureEntryNode()
{
foreach (StatescriptNode node in Nodes)
{
if (node.NodeType == StatescriptNodeType.Entry)
{
return;
}
}
var entryNode = new StatescriptNode
{
NodeId = "entry",
Title = "Entry",
NodeType = StatescriptNodeType.Entry,
PositionOffset = new Vector2(100, 200),
};
Nodes.Add(entryNode);
}
}