Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions SourceGenerators/Shared/Tools/MiniTresScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ internal static class MiniTresScraper
{
private const string ResourceToken = "[resource]";
private const string BaseTypeRegexStr = @"^\[gd_resource type=""(?<BaseType>.+?)""";
private const string ScriptClassRegexStr = @"script_class=""(?<ScriptClass>.+?)""";
private const string ScriptPathRegexStr = @"^\[ext_resource type=""Script"".+?path=""(?<Path>.+?)"".+?id=""(?<Id>.+?)""";
private const string ScriptUsageRegexStr = @"^script = ExtResource(""(?<Id>.+?)"")";
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)
Expand Down Expand Up @@ -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;
}

Expand Down