Conversation
There was a problem hiding this comment.
Hey - 我发现了两个问题,并提供了一些整体性的反馈:
- 使用「仅导出字符集到 TXT」选项导出字符时,建议在写入前对
chars集合进行排序(例如按码点排序),以确保输出是确定性的,更便于检查或进行 diff。 Program.cs中的Run方法已经变得相当庞大,现在包含了多个针对不同导入/导出模式的交互式循环;建议将新增的「从字体导出 TXT 读取」和「仅导出字符集到 TXT」流程提取到单独的辅助方法中,从而让 CLI 入口逻辑更易于阅读和维护。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When exporting characters with the "仅导出字符集到 TXT" option, consider sorting the `chars` set (e.g., by code point) before writing so the output is deterministic and easier to inspect or diff.
- The `Run` method in `Program.cs` is becoming quite large and now contains multiple interactive loops for different import/export modes; consider extracting the new "从字体导出 TXT 读取" and "仅导出字符集到 TXT" flows into dedicated helper methods to keep the CLI entrypoint easier to follow and maintain.
## Individual Comments
### Comment 1
<location path="TRPEFontGen/WriterExtensions.cs" line_range="27-34" />
<code_context>
}
}
+ extension(BinaryReader br)
+ {
+ public Rectangle ReadRectangle()
+ {
+ return new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
+ }
+
+ public Vector3 ReadVector3()
+ {
+ return new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
</code_context>
<issue_to_address>
**issue (bug_risk):** `extension(BinaryReader br)` 代码块不是合法的 C# 语法,会导致项目无法编译;这里应该使用标准的扩展方法。
要将其改为合法的扩展方法,请将这些方法移动到静态的 `WriterExtensions` 类中,并将其声明为 `public static`,同时使用 `this BinaryReader` 作为第一个参数,例如:
```csharp
public static Rectangle ReadRectangle(this BinaryReader br)
=> new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
public static Vector3 ReadVector3(this BinaryReader br)
=> new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
```
这样可以恢复编译,并使 `br.ReadRectangle()` / `br.ReadVector3()` 按预期工作。
</issue_to_address>
### Comment 2
<location path="FontGeneratorCLI/Program.cs" line_range="188-194" />
<code_context>
+ return;
+ }
+ var exportPath = AnsiConsole.Ask<string>("请输入 [blue]导出 TXT 文件路径[/]:", "chars_export.txt");
+ var sb = new System.Text.StringBuilder();
+ foreach (var c in chars)
+ {
+ sb.Append(c);
+ }
+ File.WriteAllText(exportPath, sb.ToString());
+ AnsiConsole.MarkupLine($"[green]已导出 [yellow]{chars.Count}[/] 个字符到: {exportPath}[/]");
+ return;
+ }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** 从 `HashSet<char>` 导出字符时,其顺序是非确定性的,这可能会导致多次运行间 TXT 输出结果不稳定。
由于 `chars` 是 `HashSet<char>`,它的迭代顺序并不稳定。对于 TXT 导出,更理想的方式是使用确定性的顺序(例如按码点排序)。建议在写入前先排序:
```csharp
var orderedChars = chars.OrderBy(c => c).ToArray();
File.WriteAllText(exportPath, new string(orderedChars));
```
这样可以确保多次运行之间的输出保持一致。
建议实现如下:
```csharp
if (charOptions.Contains("仅导出字符集到 TXT"))
{
if (chars.Count == 0)
{
AnsiConsole.MarkupLine("[red]错误: 未选择或未识别到任何字符,程序退出。[/]");
return;
}
var exportPath = AnsiConsole.Ask<string>("请输入 [blue]导出 TXT 文件路径[/]:", "chars_export.txt");
// 将 HashSet<char> 按字符码点排序,保证导出顺序稳定
var orderedChars = chars.OrderBy(c => c).ToArray();
var content = new string(orderedChars);
File.WriteAllText(exportPath, content);
AnsiConsole.MarkupLine($"[green]已导出 [yellow]{orderedChars.Length}[/] 个字符到: {exportPath}[/]");
}
if (charOptions.Contains("从字体导出 TXT 读取"))
```
1. 确保文件顶部已包含 `using System.Linq;` 和 `using System.IO;`,如果没有,需要补充,以便使用 `OrderBy` 和 `File.WriteAllText`。
2. 如果项目中对输出格式有统一要求(例如换行结尾),可以在 `content` 生成后根据需要追加 `Environment.NewLine`。帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- When exporting characters with the "仅导出字符集到 TXT" option, consider sorting the
charsset (e.g., by code point) before writing so the output is deterministic and easier to inspect or diff. - The
Runmethod inProgram.csis becoming quite large and now contains multiple interactive loops for different import/export modes; consider extracting the new "从字体导出 TXT 读取" and "仅导出字符集到 TXT" flows into dedicated helper methods to keep the CLI entrypoint easier to follow and maintain.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When exporting characters with the "仅导出字符集到 TXT" option, consider sorting the `chars` set (e.g., by code point) before writing so the output is deterministic and easier to inspect or diff.
- The `Run` method in `Program.cs` is becoming quite large and now contains multiple interactive loops for different import/export modes; consider extracting the new "从字体导出 TXT 读取" and "仅导出字符集到 TXT" flows into dedicated helper methods to keep the CLI entrypoint easier to follow and maintain.
## Individual Comments
### Comment 1
<location path="TRPEFontGen/WriterExtensions.cs" line_range="27-34" />
<code_context>
}
}
+ extension(BinaryReader br)
+ {
+ public Rectangle ReadRectangle()
+ {
+ return new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
+ }
+
+ public Vector3 ReadVector3()
+ {
+ return new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
</code_context>
<issue_to_address>
**issue (bug_risk):** The `extension(BinaryReader br)` block is not valid C# and will prevent the project from compiling; these should be standard extension methods.
To make these valid extension methods, move them into the static `WriterExtensions` class as `public static` methods with a `this BinaryReader` first parameter, e.g.
```csharp
public static Rectangle ReadRectangle(this BinaryReader br)
=> new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
public static Vector3 ReadVector3(this BinaryReader br)
=> new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
```
This will restore compilation and allow `br.ReadRectangle()` / `br.ReadVector3()` to work as intended.
</issue_to_address>
### Comment 2
<location path="FontGeneratorCLI/Program.cs" line_range="188-194" />
<code_context>
+ return;
+ }
+ var exportPath = AnsiConsole.Ask<string>("请输入 [blue]导出 TXT 文件路径[/]:", "chars_export.txt");
+ var sb = new System.Text.StringBuilder();
+ foreach (var c in chars)
+ {
+ sb.Append(c);
+ }
+ File.WriteAllText(exportPath, sb.ToString());
+ AnsiConsole.MarkupLine($"[green]已导出 [yellow]{chars.Count}[/] 个字符到: {exportPath}[/]");
+ return;
+ }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Exporting characters from a `HashSet<char>` yields a non-deterministic order, which may make the TXT output unstable between runs.
Since `chars` is a `HashSet<char>`, its iteration order is not stable. For TXT export, a deterministic order (e.g., by code point) is preferable. Consider ordering before writing:
```csharp
var orderedChars = chars.OrderBy(c => c).ToArray();
File.WriteAllText(exportPath, new string(orderedChars));
```
This ensures consistent output across runs.
Suggested implementation:
```csharp
if (charOptions.Contains("仅导出字符集到 TXT"))
{
if (chars.Count == 0)
{
AnsiConsole.MarkupLine("[red]错误: 未选择或未识别到任何字符,程序退出。[/]");
return;
}
var exportPath = AnsiConsole.Ask<string>("请输入 [blue]导出 TXT 文件路径[/]:", "chars_export.txt");
// 将 HashSet<char> 按字符码点排序,保证导出顺序稳定
var orderedChars = chars.OrderBy(c => c).ToArray();
var content = new string(orderedChars);
File.WriteAllText(exportPath, content);
AnsiConsole.MarkupLine($"[green]已导出 [yellow]{orderedChars.Length}[/] 个字符到: {exportPath}[/]");
}
if (charOptions.Contains("从字体导出 TXT 读取"))
```
1. 确保文件顶部已包含 `using System.Linq;` 和 `using System.IO;`,如果没有,需要补充,以便使用 `OrderBy` 和 `File.WriteAllText`。
2. 如果项目中对输出格式有统一要求(例如换行结尾),可以在 `content` 生成后根据需要追加 `Environment.NewLine`。
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| extension(BinaryReader br) | ||
| { | ||
| public Rectangle ReadRectangle() | ||
| { | ||
| return new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); | ||
| } | ||
|
|
||
| public Vector3 ReadVector3() |
There was a problem hiding this comment.
issue (bug_risk): extension(BinaryReader br) 代码块不是合法的 C# 语法,会导致项目无法编译;这里应该使用标准的扩展方法。
要将其改为合法的扩展方法,请将这些方法移动到静态的 WriterExtensions 类中,并将其声明为 public static,同时使用 this BinaryReader 作为第一个参数,例如:
public static Rectangle ReadRectangle(this BinaryReader br)
=> new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
public static Vector3 ReadVector3(this BinaryReader br)
=> new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());这样可以恢复编译,并使 br.ReadRectangle() / br.ReadVector3() 按预期工作。
Original comment in English
issue (bug_risk): The extension(BinaryReader br) block is not valid C# and will prevent the project from compiling; these should be standard extension methods.
To make these valid extension methods, move them into the static WriterExtensions class as public static methods with a this BinaryReader first parameter, e.g.
public static Rectangle ReadRectangle(this BinaryReader br)
=> new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
public static Vector3 ReadVector3(this BinaryReader br)
=> new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());This will restore compilation and allow br.ReadRectangle() / br.ReadVector3() to work as intended.
| var sb = new System.Text.StringBuilder(); | ||
| foreach (var c in chars) | ||
| { | ||
| sb.Append(c); | ||
| } | ||
| File.WriteAllText(exportPath, sb.ToString()); | ||
| AnsiConsole.MarkupLine($"[green]已导出 [yellow]{chars.Count}[/] 个字符到: {exportPath}[/]"); |
There was a problem hiding this comment.
suggestion (bug_risk): 从 HashSet<char> 导出字符时,其顺序是非确定性的,这可能会导致多次运行间 TXT 输出结果不稳定。
由于 chars 是 HashSet<char>,它的迭代顺序并不稳定。对于 TXT 导出,更理想的方式是使用确定性的顺序(例如按码点排序)。建议在写入前先排序:
var orderedChars = chars.OrderBy(c => c).ToArray();
File.WriteAllText(exportPath, new string(orderedChars));这样可以确保多次运行之间的输出保持一致。
建议实现如下:
if (charOptions.Contains("仅导出字符集到 TXT"))
{
if (chars.Count == 0)
{
AnsiConsole.MarkupLine("[red]错误: 未选择或未识别到任何字符,程序退出。[/]");
return;
}
var exportPath = AnsiConsole.Ask<string>("请输入 [blue]导出 TXT 文件路径[/]:", "chars_export.txt");
// 将 HashSet<char> 按字符码点排序,保证导出顺序稳定
var orderedChars = chars.OrderBy(c => c).ToArray();
var content = new string(orderedChars);
File.WriteAllText(exportPath, content);
AnsiConsole.MarkupLine($"[green]已导出 [yellow]{orderedChars.Length}[/] 个字符到: {exportPath}[/]");
}
if (charOptions.Contains("从字体导出 TXT 读取"))- 确保文件顶部已包含
using System.Linq;和using System.IO;,如果没有,需要补充,以便使用OrderBy和File.WriteAllText。 - 如果项目中对输出格式有统一要求(例如换行结尾),可以在
content生成后根据需要追加Environment.NewLine。
Original comment in English
suggestion (bug_risk): Exporting characters from a HashSet<char> yields a non-deterministic order, which may make the TXT output unstable between runs.
Since chars is a HashSet<char>, its iteration order is not stable. For TXT export, a deterministic order (e.g., by code point) is preferable. Consider ordering before writing:
var orderedChars = chars.OrderBy(c => c).ToArray();
File.WriteAllText(exportPath, new string(orderedChars));This ensures consistent output across runs.
Suggested implementation:
if (charOptions.Contains("仅导出字符集到 TXT"))
{
if (chars.Count == 0)
{
AnsiConsole.MarkupLine("[red]错误: 未选择或未识别到任何字符,程序退出。[/]");
return;
}
var exportPath = AnsiConsole.Ask<string>("请输入 [blue]导出 TXT 文件路径[/]:", "chars_export.txt");
// 将 HashSet<char> 按字符码点排序,保证导出顺序稳定
var orderedChars = chars.OrderBy(c => c).ToArray();
var content = new string(orderedChars);
File.WriteAllText(exportPath, content);
AnsiConsole.MarkupLine($"[green]已导出 [yellow]{orderedChars.Length}[/] 个字符到: {exportPath}[/]");
}
if (charOptions.Contains("从字体导出 TXT 读取"))- 确保文件顶部已包含
using System.Linq;和using System.IO;,如果没有,需要补充,以便使用OrderBy和File.WriteAllText。 - 如果项目中对输出格式有统一要求(例如换行结尾),可以在
content生成后根据需要追加Environment.NewLine。
1.二进制文件获取字符列表
2.导出字符到txt文件
3.1000汉字选项增加(combat text只能用少量字)
Summary by Sourcery
添加新的字符集选项和元数据读取器,以支持在字体元数据与 TXT 文件之间导入/导出字符列表。
新功能:
增强:
Original summary in English
Summary by Sourcery
Add new character set options and metadata readers to support importing/exporting character lists between font metadata and TXT files.
New Features:
Enhancements: