Skip to content

Commit 489840a

Browse files
committed
Extend interactivity export validator: checking debug/log messages for {} templates with input sockets
1 parent e47d90c commit 489840a

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Runtime/Scripts/Interactivity/Export/Helpers/Validator.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Linq;
22
using System.Text;
3+
using System.Text.RegularExpressions; // added for placeholder parsing
34
using UnityEngine;
45
using UnityGLTF.Interactivity.Schema;
56

@@ -58,6 +59,44 @@ void NodeAppendLine(GltfInteractivityNode node, string message)
5859
}
5960
}
6061

62+
if (node.Schema.Op == "debug/log")
63+
{
64+
if (node.Configuration.ContainsKey(Debug_LogNode.IdConfigMessage))
65+
{
66+
if (node.Configuration[Debug_LogNode.IdConfigMessage].Value == null)
67+
NodeAppendLine(node, $"Debug Log Node has no Message");
68+
else
69+
{
70+
var templateStr = node.Configuration[Debug_LogNode.IdConfigMessage].Value;
71+
// Extract placeholders in the form {placeholder} from the template string and validate they exist as value socket keys
72+
if (templateStr is string template)
73+
{
74+
var matches = Regex.Matches(template, @"\{([^{}]+)\}");
75+
foreach (Match m in matches)
76+
{
77+
var placeholder = m.Groups[1].Value.Trim();
78+
if (string.IsNullOrEmpty(placeholder))
79+
continue; // ignore empty braces
80+
if (!node.ValueInConnection.ContainsKey(placeholder))
81+
{
82+
NodeAppendLine(node, $"Debug Log template placeholder '{{{placeholder}}}' has no matching ValueIn socket");
83+
}
84+
else
85+
{
86+
var socket = node.ValueInConnection[placeholder];
87+
if (socket.Node == null && socket.Value == null)
88+
NodeAppendLine(node, $"Debug Log template placeholder '{{{placeholder}}}' socket has neither connection nor default value");
89+
}
90+
}
91+
}
92+
else
93+
{
94+
NodeAppendLine(node, $"Debug Log Node Message config is not a string (Type={templateStr.GetType().Name})");
95+
}
96+
}
97+
}
98+
}
99+
61100
if (node.Schema.Op == "pointer/set" || node.Schema.Op == "pointer/get")
62101
{
63102
if (node.ValueInConnection.TryGetValue(PointersHelper.IdPointerNodeIndex, out var valueSocket))

0 commit comments

Comments
 (0)