From d84ed5aaac159f301013b081d6f296dfd2f5ce95 Mon Sep 17 00:00:00 2001 From: Seb Date: Tue, 18 Aug 2026 16:28:32 +0100 Subject: [PATCH] Strongly type Resource tres files in ResourceTree when possible --- SourceGenerators/Shared/Tools/MiniTresScraper.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/SourceGenerators/Shared/Tools/MiniTresScraper.cs b/SourceGenerators/Shared/Tools/MiniTresScraper.cs index 288ad18c..5e8c973c 100644 --- a/SourceGenerators/Shared/Tools/MiniTresScraper.cs +++ b/SourceGenerators/Shared/Tools/MiniTresScraper.cs @@ -7,10 +7,12 @@ internal static class MiniTresScraper { private const string ResourceToken = "[resource]"; private const string BaseTypeRegexStr = @"^\[gd_resource type=""(?.+?)"""; + private const string ScriptClassRegexStr = @"script_class=""(?.+?)"""; private const string ScriptPathRegexStr = @"^\[ext_resource type=""Script"".+?path=""(?.+?)"".+?id=""(?.+?)"""; private const string ScriptUsageRegexStr = @"^script = ExtResource(""(?.+?)"")"; private static readonly Regex BaseTypeRegex = new(BaseTypeRegexStr, RegexOptions.Compiled | RegexOptions.ExplicitCapture); private static readonly Regex ScriptPathRegex = new(ScriptPathRegexStr, RegexOptions.Compiled | RegexOptions.ExplicitCapture); + private static readonly Regex ScriptClassRegex = new(ScriptClassRegexStr, RegexOptions.Compiled | RegexOptions.ExplicitCapture); private static readonly Regex ScriptUsageRegex = new(ScriptUsageRegexStr, RegexOptions.Compiled | RegexOptions.ExplicitCapture); public static string GetType(Compilation compilation, string tres) @@ -49,6 +51,13 @@ bool ScanHeader(string line) if (!match.Success) throw new Exception($"Expected gd_resource header on first line!\n - Line: {line}\n - TRES: {tres}"); Log.Debug($" - BaseTypeRegex {BaseTypeRegex.GetGroupsAsStr(match)}"); baseType = match.Groups["BaseType"].Value; + if (baseType is "Resource") + { + var scriptClassMatch = ScriptClassRegex.Match(line); + if (scriptClassMatch.Success && compilation.GetValidType(scriptClassMatch.Groups["ScriptClass"].Value) is {} cSharpType) { + classType = cSharpType; + } + } return true; }