another approach for making the debugger nicer

This commit is contained in:
Lilith Schier 2026-06-29 02:40:34 +02:00
parent b5d5a8f9f3
commit b37c78d75b
4 changed files with 65 additions and 55 deletions

View file

@ -1,11 +1,8 @@
#if TOOLS
using System.Diagnostics;
using System.Linq;
using Godot.Collections;
namespace Dancer;
[Tool]
public sealed partial class BehaviorDebugControl : Control
{
@ -35,16 +32,17 @@ public sealed partial class BehaviorDebugControl : Control
public void AddTreeData(Array raw)
{
(ulong instanceId, Dictionary tree) data = (raw[0].AsUInt64(), raw[1].AsGodotDictionary());
(string name, ulong instanceId, Dictionary tree) data = (raw[0].AsString(), raw[1].AsUInt64(),
raw[2].AsGodotDictionary());
var idx = _trees.FindIndex(tuple => tuple.instanceId == data.instanceId);
if (idx == -1)
{
_trees.Add(data);
_itemList.AddItem($"{data.instanceId}");
_trees.Add((data.instanceId, data.tree));
_itemList.AddItem($"{data.name} ({data.instanceId})");
return;
}
_trees[idx] = data;
_trees[idx] = (data.instanceId, data.tree);
if (idx == _selectedIndex)
{
UpdateTree(data.tree);
@ -103,19 +101,38 @@ public sealed partial class BehaviorDebugControl : Control
"Selector" => "?",
var other => other,
};
item.SetText(0, displayName);
var state = node["state"].As<string>();
var isStale = node["is_stale"].AsBool();
var theme = EditorInterface.Singleton.GetEditorTheme();
var textColor = theme.GetColor("font_color", "Tree");
var textLightness = textColor.OkHslL;
var bgLightness = textLightness > .5f ? .3f : .8f;
var bgAlpha = isStale ? .06f : .4f;
var bgColor = state switch
{
"Idle" => Color.FromOkHsl(.653f, .3f, .2f),
"Running" => Color.FromOkHsl(.222f, .7f, .3f),
"Success" => Color.FromOkHsl(.375f, .3f, .2f),
"Failure" => Color.FromOkHsl(.055f, .3f, .2f),
"Idle" => Colors.Transparent,
"Running" => Color.FromOkHsl(.653f, .7f, bgLightness) with { A = bgAlpha + .1f },
"Success" => Color.FromOkHsl(.375f, .7f, bgLightness) with { A = bgAlpha },
"Failure" => Color.FromOkHsl(.055f, .7f, bgLightness) with { A = bgAlpha },
_ => throw new UnreachableException(),
};
item.SetCustomBgColor(1, bgColor);
item.SetCustomColor(1, Colors.AntiqueWhite);
item.SetText(1, state);
var color = textColor with { A = isStale ? .35f : 1f };
item.SetText(0, displayName);
item.SetText(1, isStale ? $"Stale ({state})" : state);
for (var col = 0; col < 2; col++)
{
item.SetCustomColor(col, color);
item.SetCustomBgColor(col, bgColor);
}
}
public void Clear()
{
_itemList.Clear();
_trees.Clear();
_tree.GetRoot()?.Free();
}
}