Repository navigation
feat(tools): 成就图片生成器改为本地渲染并支持任意语言 [Deepseek-V4.1-Flash] - #3655
Open
meixuan1234 wants to merge 3 commits into
Open
meixuan1234 wants to merge 3 commits into
meixuan1234 wants to merge 3 commits into
Conversation
- RubbishClear 中 natives 目录的判断条件恒为 false,该清理分支从未生效 - CmbHeadSize_SelectionChanged 中 skinPath 判空无效,其初始值是空字符串而非 null
原先调用 minecraft-api.com 生成图片,该接口不支持非 ASCII 字符,输入中文返回 404, 界面因此只能标注「仅支持英文」。改为完全本地渲染后不再依赖第三方接口。 - 用 WPF 本地绘制成就卡片,支持任意语言 - 文字按像素宽度自动换行(含连续 ASCII 串),卡片高度随内容自适应 - 单行超过 67 字符时截取并追加省略号 - 物品图标按实例资源、在线接口、屏障占位依次回退 - 字体可切换为本机已安装的字体 - 在线图标缓存使用 ConcurrentDictionary,生成期间禁用预览与保存按钮 BREAKING CHANGE: 移除对 minecraft-api.com 的依赖
Contributor
审查者指南该 PR 移除成就图片生成对 minecraft-api.com 的依赖,改用 WPF 本地渲染实现任意语言、自适应排版和可选字体,并通过本地资源、在线服务与占位图标提供多级图标回退;同时修复原生目录清理及头像尺寸切换问题。 本地成就图片渲染时序图sequenceDiagram
participant User
participant PageToolsTest
participant IconLoader
participant Renderer
participant AchievementImage
User->>PageToolsTest: BtnAchievementPreview_Click
PageToolsTest->>IconLoader: _LoadAchievementIconAsync(itemId)
IconLoader->>IconLoader: _TryLoadVanillaIcon(itemId)
alt local icon unavailable
IconLoader->>IconLoader: _TryLoadOnlineIcon(itemId)
alt online icon unavailable
IconLoader->>IconLoader: _TryLoadBuiltInBarrier()
alt built-in barrier unavailable
IconLoader->>IconLoader: _LoadOnlineBarrier()
end
end
end
PageToolsTest->>Renderer: _RenderAchievementImage(icon)
Renderer->>Renderer: _WrapTextByWidth(text, typeface, fontSize, maxWidth, pixelsPerDip)
Renderer->>AchievementImage: set Source
成就图标回退流程图flowchart TD
A[Item ID] --> B[_TryLoadVanillaIcon]
B -->|found| E[Render achievement image]
B -->|not found| C[_TryLoadOnlineIcon]
C -->|found| E
C -->|not found| D[_TryLoadBuiltInBarrier]
D -->|found| E
D -->|not found| F[_LoadOnlineBarrier]
F -->|found| E
F -->|not found| G[Draw fallback cube]
G --> E
文件级变更
对照关联 issue 的评估
可能关联的 issue
提示与命令与 Sourcery 交互
自定义使用体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's Guide该 PR 移除成就图片生成对 minecraft-api.com 的依赖,改用 WPF 本地渲染实现任意语言、自适应排版和可选字体,并通过本地资源、在线服务与占位图标提供多级图标回退;同时修复原生目录清理及头像尺寸切换问题。 Sequence diagram for local achievement image renderingsequenceDiagram
participant User
participant PageToolsTest
participant IconLoader
participant Renderer
participant AchievementImage
User->>PageToolsTest: BtnAchievementPreview_Click
PageToolsTest->>IconLoader: _LoadAchievementIconAsync(itemId)
IconLoader->>IconLoader: _TryLoadVanillaIcon(itemId)
alt local icon unavailable
IconLoader->>IconLoader: _TryLoadOnlineIcon(itemId)
alt online icon unavailable
IconLoader->>IconLoader: _TryLoadBuiltInBarrier()
alt built-in barrier unavailable
IconLoader->>IconLoader: _LoadOnlineBarrier()
end
end
end
PageToolsTest->>Renderer: _RenderAchievementImage(icon)
Renderer->>Renderer: _WrapTextByWidth(text, typeface, fontSize, maxWidth, pixelsPerDip)
Renderer->>AchievementImage: set Source
Flow diagram for achievement icon fallbackflowchart TD
A[Item ID] --> B[_TryLoadVanillaIcon]
B -->|found| E[Render achievement image]
B -->|not found| C[_TryLoadOnlineIcon]
C -->|found| E
C -->|not found| D[_TryLoadBuiltInBarrier]
D -->|found| E
D -->|not found| F[_LoadOnlineBarrier]
F -->|found| E
F -->|not found| G[Draw fallback cube]
G --> E
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
嘿——我发现了 3 个问题
面向 AI Agent 的提示
请处理这次代码审查中的评论:
## 单独评论
### 评论 1
<location path="Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.cs" line_range="741" />
<code_context>
+ Media.FormattedText MakeText(string text, Media.Color color) => new(
+ _WrapTextByWidth(text, typeface, fontSize, maxTextWidth, superSample),
+ CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeface, fontSize,
+ new Media.SolidColorBrush(color), superSample)
+ {
+ MaxTextWidth = maxTextWidth,
</code_context>
<issue_to_address>
**问题 (bug_risk):**RTL 成就文本始终按从左到右的方向进行格式化,因此即使该功能声称支持任意语言,阿拉伯语和希伯来语文本仍会以错误的双向文本顺序和方向显示。
**触发条件:**标题或描述包含从右到左的文本时。
**建议修复:**根据文本或输入区域性选择流方向,或者仅对 LTR 内容使用 `FlowDirection.LeftToRight`,对 RTL 内容使用 `FlowDirection.RightToLeft`。
```suggestion
CultureInfo.CurrentUICulture, CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, typeface, fontSize,
```
</issue_to_address>
### 评论 2
<location path="Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.cs" line_range="601-606" />
<code_context>
+ try
+ {
+ await Task.Yield(); // 先把加载指示绘制出来
+ var itemId = AchievementBlockTextBox.Text.Trim();
+ var (icon, notFound) = await _LoadAchievementIconAsync(itemId);
+ if (notFound && !string.IsNullOrEmpty(itemId))
+ HintService.Hint(Lang.Text("Tools.Test.Achievement.IconNotFound", itemId), HintType.Info);
+
+ AchievementImage.Source = _RenderAchievementImage(icon);
+ AchievementImage.Visibility = Visibility.Visible;
+ }
</code_context>
<issue_to_address>
**问题 (bug_risk):**项目 ID 在异步加载图标之前被捕获,但 `_RenderAchievementImage` 在等待完成后又重新读取文本框。因此,在网络请求进行期间编辑项目 ID 或成就文本,会将旧项目的图标与新文本组合在一起,从而生成内容不一致的预览或保存图片。
**触发条件:**在线图标或屏障请求进行期间,用户编辑成就字段时。
**建议修复:**在等待异步操作之前快照保存所有成就输入,并将该不可变快照传递给图标加载和渲染逻辑;或者在操作期间禁用输入控件。
</issue_to_address>
### 评论 3
<location path="Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.cs" line_range="826-844" />
<code_context>
- ModBase.CopyFile(savePath, path);
- File.Delete(savePath);
- HintService.Hint(Lang.Text("Tools.Test.Achievement.Saved"), HintType.Success);
+ foreach (var ch in text)
+ {
+ if (ch == '\n')
+ {
+ result.Append(line).Append('\n');
+ line.Clear();
+ continue;
}
- // 下载成功,返回 True
- else if (response.StatusCode == HttpStatusCode.NotFound)
</code_context>
<issue_to_address>
**问题 (bug_risk):**换行逻辑遍历的是 UTF-16 `char` 值,可能会将代理项对中的一半移动到下一行。这样生成的字符串会在代理项对之间插入换行符,导致表情符号和其他补充平面字符在换行边界处显示为损坏字符或替换字符。
**触发条件:**补充 Unicode 字符恰好位于行宽边界时。
**建议修复:**按 Unicode 标量值或字素簇进行换行,在测量和移动文本时确保每个代理项对保持完整。
</issue_to_address>Original comment in English
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.cs" line_range="741" />
<code_context>
+ Media.FormattedText MakeText(string text, Media.Color color) => new(
+ _WrapTextByWidth(text, typeface, fontSize, maxTextWidth, superSample),
+ CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeface, fontSize,
+ new Media.SolidColorBrush(color), superSample)
+ {
+ MaxTextWidth = maxTextWidth,
</code_context>
<issue_to_address>
**issue (bug_risk):** RTL achievement text is always formatted as left-to-right, so Arabic and Hebrew text is displayed with incorrect bidi ordering and direction despite the feature claiming support for arbitrary languages.
**Triggers:** When the title or description contains right-to-left text.
**Suggested fix:** Choose the flow direction from the text or input culture, or use `FlowDirection.LeftToRight` only for LTR content and `FlowDirection.RightToLeft` for RTL content.
```suggestion
CultureInfo.CurrentUICulture, CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, typeface, fontSize,
```
</issue_to_address>
### Comment 2
<location path="Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.cs" line_range="601-606" />
<code_context>
+ try
+ {
+ await Task.Yield(); // 先把加载指示绘制出来
+ var itemId = AchievementBlockTextBox.Text.Trim();
+ var (icon, notFound) = await _LoadAchievementIconAsync(itemId);
+ if (notFound && !string.IsNullOrEmpty(itemId))
+ HintService.Hint(Lang.Text("Tools.Test.Achievement.IconNotFound", itemId), HintType.Info);
+
+ AchievementImage.Source = _RenderAchievementImage(icon);
+ AchievementImage.Visibility = Visibility.Visible;
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** The item ID is captured before the asynchronous icon load, but `_RenderAchievementImage` reads the text boxes again after the await. Editing the item ID or achievement text while the network request is running therefore combines the old item's icon with the new text, producing an internally inconsistent preview or saved image.
**Triggers:** When the user edits an achievement field while an online icon or barrier request is in progress.
**Suggested fix:** Snapshot all achievement inputs before awaiting and pass that immutable snapshot through icon loading and rendering, or disable the input controls for the duration of the operation.
</issue_to_address>
### Comment 3
<location path="Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.cs" line_range="826-844" />
<code_context>
- ModBase.CopyFile(savePath, path);
- File.Delete(savePath);
- HintService.Hint(Lang.Text("Tools.Test.Achievement.Saved"), HintType.Success);
+ foreach (var ch in text)
+ {
+ if (ch == '\n')
+ {
+ result.Append(line).Append('\n');
+ line.Clear();
+ continue;
}
- // 下载成功,返回 True
- else if (response.StatusCode == HttpStatusCode.NotFound)
</code_context>
<issue_to_address>
**issue (bug_risk):** Wrapping iterates UTF-16 `char` values and can move only one half of a surrogate pair to the next line. The resulting string contains a newline between the pair, so emoji and other supplementary-plane characters render as broken or replacement glyphs at a wrap boundary.
**Triggers:** When a supplementary Unicode character falls exactly at a line-width boundary.
**Suggested fix:** Wrap by Unicode scalar values or grapheme clusters, keeping each surrogate pair together while measuring and moving text.
</issue_to_address>- 书写方向固定为 LeftToRight,阿拉伯文、希伯来文等 RTL 文本会显示反掉; 改为按文本内容检测(U+0590–U+08FF 区段)决定方向 - 图标异步加载完成后才读取文本框,若用户在此期间编辑,会得到 「旧图标配新文字」的不一致结果;改为等待前快照全部输入 - 按 char 遍历换行会从中间拆开代理项对,emoji 等补充平面字符落在 换行边界时会显示为乱码;改为按 Unicode 标量值(Rune)遍历
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
成就图片生成器原先调用
minecraft-api.com,该接口不支持非 ASCII 字符,输入中文返回 404,界面因此只能标注「仅支持英文」。改为 WPF 本地渲染后不再依赖第三方接口。改动
...RubbishClear:dirInfo2.Name == dirInfo2.Name + "-natives"恒为 false,该清理分支从未生效CmbHeadSize_SelectionChanged:skinPath is not null无效(其初始值为空字符串)AI 使用与状态
使用 Deepseek-V4.1-Flash 辅助实现、整理和验证。已使用 GitHub 签名。人工已核查每行代码并测试功能。
Fixes #1566
Summary by Sourcery
将成就图片生成迁移至本地渲染并增强多语言、字体和物品图标支持,同时修复资源清理与头像加载缺陷。
New Features:
Bug Fixes:
Enhancements:
Original summary in English
Summary by Sourcery
将成就图片生成迁移至本地渲染并增强多语言、字体和物品图标支持,同时修复资源清理与头像加载缺陷。
New Features:
Bug Fixes:
Enhancements:
Original summary in English