2025-11-25 13:33:53 +01:00
|
|
|
using System;
|
|
|
|
|
using Godot;
|
|
|
|
|
using Godot.Collections;
|
|
|
|
|
|
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Savegame;
|
|
|
|
|
|
2025-11-25 13:46:46 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// And editor tool that lives in the scene scope and iterates over saveable nodes and assigns them unique IDs where necessary.
|
|
|
|
|
/// It only works if the object (prefab) in question has been added to the "Saveable"-group beforehand.
|
|
|
|
|
/// </summary>
|
2025-11-25 13:33:53 +01:00
|
|
|
[Tool]
|
|
|
|
|
public partial class SaveIDProviderTool : Node
|
|
|
|
|
{
|
2025-11-25 13:46:46 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Creates an inspector button that calls the AssignIDs method.
|
|
|
|
|
/// </summary>
|
2025-11-25 13:33:53 +01:00
|
|
|
[ExportToolButton("Assign IDs")] private Callable assignIDs => Callable.From(AssignIDs);
|
|
|
|
|
|
|
|
|
|
private void AssignIDs()
|
|
|
|
|
{
|
|
|
|
|
Array<Node> saveables = GetTree().GetNodesInGroup("Saveable");
|
|
|
|
|
foreach (var node in saveables)
|
|
|
|
|
{
|
|
|
|
|
GD.Print($"Checking {node.Name}.");
|
|
|
|
|
if (!node.HasMeta("SaveID") || string.IsNullOrEmpty(node.GetMeta("SaveID").AsString()))
|
|
|
|
|
{
|
|
|
|
|
string saveID = Guid.NewGuid().ToString();
|
|
|
|
|
node.SetMeta("SaveID", saveID);
|
|
|
|
|
GD.Print($"Setting Save ID for node {node.Name}: " + saveID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|