版本 1.0.0-rc3:手册占位符取值改查表,扫描结果无权限
This commit is contained in:
1 parent
e8532f9e1b
commit
c4aee5e53b
7 files changed
+479
-22
No files matched your search
@@ -26,8 +26,41 @@ internal static class Program
|
||||
|
||||
private static bool Near(double a, double b, double tol) => Math.Abs(a - b) <= tol;
|
||||
|
||||
private static int Main()
|
||||
/// <summary>生成 TuningTable.cs:占位符取值走查表而不是运行时反射(游戏的模组扫描会把反射算作未声明的权限)。</summary>
|
||||
private static string GenerateTuningTable()
|
||||
{
|
||||
var fields = typeof(Tuning).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)
|
||||
.OrderBy(f => f.Name, StringComparer.Ordinal).ToList();
|
||||
var sb = new System.Text.StringBuilder();
|
||||
sb.Append("// 由测试项目生成:dotnet run --project tests/Decentralized.Domain.Tests -c Release -- --gen-tuning-table\n");
|
||||
sb.Append("// Tuning 增删数值后要重新生成(单元测试会核对)。\n");
|
||||
sb.Append("using System;\nusing System.Collections.Generic;\n\nnamespace Decentralized.Domain\n{\n");
|
||||
sb.Append(" internal static class TuningTable\n {\n");
|
||||
sb.Append(" public static readonly Dictionary<string, double> Scalars = new Dictionary<string, double>\n {\n");
|
||||
foreach (var f in fields.Where(f => !f.FieldType.IsArray)) sb.Append($" [\"{f.Name}\"] = Tuning.{f.Name},\n");
|
||||
sb.Append(" };\n\n public static readonly Dictionary<string, double[]> Arrays = new Dictionary<string, double[]>\n {\n");
|
||||
foreach (var f in fields.Where(f => f.FieldType.IsArray)) sb.Append($" [\"{f.Name}\"] = Array.ConvertAll(Tuning.{f.Name}, v => (double)v),\n");
|
||||
sb.Append(" };\n }\n}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static string FindRoot() => System.IO.Path.GetFullPath(System.IO.Path.Combine(AppContext.BaseDirectory, "../../../../.."));
|
||||
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
if (args.Contains("--gen-tuning-table"))
|
||||
{
|
||||
System.IO.File.WriteAllText(System.IO.Path.Combine(FindRoot(), "src/Decentralized.Domain/TuningTable.cs"), GenerateTuningTable().Replace("\r", ""));
|
||||
Console.WriteLine("TuningTable.cs 已生成");
|
||||
return 0;
|
||||
}
|
||||
Test("占位符查表(TuningTable)和 Tuning 一致", () =>
|
||||
{
|
||||
var path = System.IO.Path.Combine(FindRoot(), "src/Decentralized.Domain/TuningTable.cs");
|
||||
Check(System.IO.File.ReadAllText(path).Replace("\r", "") == GenerateTuningTable().Replace("\r", ""), "TuningTable.cs 已过期,重新生成:dotnet run --project tests/Decentralized.Domain.Tests -c Release -- --gen-tuning-table");
|
||||
var src = System.IO.File.ReadAllText(System.IO.Path.Combine(FindRoot(), "src/Decentralized.Domain/TuningText.cs"));
|
||||
Check(!src.Contains("System.Reflection") && !src.Contains("GetField"), "TuningText 不用反射");
|
||||
});
|
||||
Test("随机数:同种子同序列;状态可复制后继续", () =>
|
||||
{
|
||||
var a = new Rng(42);
|
||||
|
||||
Reference in new issue
Block a user