Skip to content

Commit 8751ae8

Browse files
committed
#53 Minor readbility improvements. No behavioural changes as yet.
1 parent de28afe commit 8751ae8

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

SourceGenerators/Utilities/Extensions/GeneratorExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public static string TryGetGodotProjectDir(this AnalyzerConfigOptions options)
99
const string GodotProjectDir = "build_property.GodotProjectDir";
1010
const string GodotProjectDirBase64 = "build_property.GodotProjectDirBase64";
1111

12-
return options.TryGetValue(GodotProjectDir, out var value) ? value.Trim('\\')
13-
: options.TryGetValue(GodotProjectDirBase64, out value) ? value.Trim('\\') : null;
12+
return options.TryGetValue(GodotProjectDir, out var value) ? value.TrimEnd('\\')
13+
: options.TryGetValue(GodotProjectDirBase64, out value) ? value.TrimEnd('\\') : null;
1414
}
1515
}
1616
}

SourceGenerators/Utilities/Extensions/GodotExtensions.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace GodotSharp.SourceGenerators
1+
using System.Diagnostics;
2+
3+
namespace GodotSharp.SourceGenerators
24
{
35
internal static class GD
46
{
@@ -27,9 +29,21 @@ static string GetProjectRoot(string path)
2729
}
2830

2931
public static string GetProjectFile(string path, string projectDir = null)
30-
=> $"{projectDir ?? GetProjectRoot(path)}/{GodotProjectFile}";
32+
=> Path.Combine(projectDir ?? GetProjectRoot(path), GodotProjectFile);
3133

3234
public static string GetResourcePath(string path, string projectDir = null)
33-
=> $"res:/{path[(projectDir ?? GetProjectRoot(path)).Length..].Replace(@"\", "/")}";
35+
{
36+
projectDir ??= GetProjectRoot(path);
37+
Debug.Assert(path.StartsWith(projectDir));
38+
39+
var resPath = path[projectDir.Length..];
40+
Debug.Assert(resPath.StartsWith(@"\"));
41+
42+
resPath = $"res:/{resPath.Replace(@"\", "/")}";
43+
Debug.Assert(resPath.StartsWith("res://"));
44+
Debug.Assert(!resPath.StartsWith("res:///"));
45+
46+
return resPath;
47+
}
3448
}
3549
}

0 commit comments

Comments
 (0)