Skip to content

ref(launch-right): 重构 GetRandomHint#2636

Merged
LinQingYuu merged 2 commits intodevfrom
ref/GetRandomHint
Mar 24, 2026
Merged

ref(launch-right): 重构 GetRandomHint#2636
LinQingYuu merged 2 commits intodevfrom
ref/GetRandomHint

Conversation

@xrlzu
Copy link
Member

@xrlzu xrlzu commented Mar 22, 2026

Summary by Sourcery

重构随机提示获取逻辑,以同时支持 HTML 转义和原始提示,并将文件/资源的加载与使用集中管理。

新功能:

  • 通过扩展的 GetRandomHint API,允许调用方请求原始(未转义的)随机提示。

增强改进:

  • 统一并简化从外部文件和内嵌资源中加载随机提示的流程,并支持可选的长度限制。
  • 移除左侧启动页面上多余的 GetRandomHint 包装函数,直接使用共享实现。
Original summary in English

Summary by Sourcery

Refactor the random hint retrieval logic to support both HTML-escaped and raw hints while centralizing file/resource loading and usage.

New Features:

  • Allow callers to request raw (unescaped) random hints via an extended GetRandomHint API.

Enhancements:

  • Unify and simplify random hint loading from external files and embedded resources with optional length limiting.
  • Remove the redundant GetRandomHint wrapper on the left launch page and use the shared implementation directly.

新功能:

  • 通过扩展的 GetRandomHint API,允许调用方请求原始(未进行 HTML 转义的)随机提示。

增强改进:

  • 简化并集中处理从外部文件和内嵌资源加载随机提示以及限制长度的逻辑。
  • 移除左侧启动页面中多余的 GetRandomHint 包装器,改为直接调用共享实现。
Original summary in English

Summary by Sourcery

重构随机提示获取逻辑,以同时支持 HTML 转义和原始提示,并将文件/资源的加载与使用集中管理。

新功能:

  • 通过扩展的 GetRandomHint API,允许调用方请求原始(未转义的)随机提示。

增强改进:

  • 统一并简化从外部文件和内嵌资源中加载随机提示的流程,并支持可选的长度限制。
  • 移除左侧启动页面上多余的 GetRandomHint 包装函数,直接使用共享实现。
Original summary in English

Summary by Sourcery

Refactor the random hint retrieval logic to support both HTML-escaped and raw hints while centralizing file/resource loading and usage.

New Features:

  • Allow callers to request raw (unescaped) random hints via an extended GetRandomHint API.

Enhancements:

  • Unify and simplify random hint loading from external files and embedded resources with optional length limiting.
  • Remove the redundant GetRandomHint wrapper on the left launch page and use the shared implementation directly.

@pcl-ce-automation pcl-ce-automation bot added 🚧 正在处理 开发人员正在对该内容进行开发、测试或修复,进展中 size: M PR 大小评估:中型 labels Mar 22, 2026
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 22, 2026

审阅者指南

重构 PageLaunchRight 中的 GetRandomHint 逻辑,以统一外部与内嵌提示的加载方式,新增“返回原始文本 vs HTML 转义文本”的选项,并更新左启动页以使用这一共享实现及其新的方法签名。

统一版 GetRandomHint 流程的时序图

sequenceDiagram
    actor User
    participant PageLaunchLeft
    participant PageLaunchRight
    participant FileSystem
    participant EmbeddedResource

    User->>PageLaunchLeft: OpenLaunchingView
    PageLaunchLeft->>PageLaunchRight: GetRandomHint(enableLengthLimit=True, raw=True)

    alt External hints file exists
        PageLaunchRight->>FileSystem: ReadAllLines(externalPath)
        FileSystem-->>PageLaunchRight: lines
    else External file missing or read failed
        PageLaunchRight->>EmbeddedResource: GetResourceStream(hints.txt)
        EmbeddedResource-->>PageLaunchRight: lines
    end

    alt enableLengthLimit is True
        PageLaunchRight->>PageLaunchRight: Filter lines where length < 50
    end

    PageLaunchRight->>PageLaunchRight: Select random hint from lines

    alt raw is True
        PageLaunchRight-->>PageLaunchLeft: hint (raw)
    else raw is False
        PageLaunchRight->>PageLaunchRight: HtmlEscape(hint)
        PageLaunchRight-->>PageLaunchLeft: escaped hint
    end

    PageLaunchLeft->>PageLaunchLeft: LabLaunchingHint.Text = hint
    PageLaunchLeft-->>User: Show launching page with random hint
Loading

更新后 GetRandomHint 使用方式的类图

classDiagram
    class PageLaunchRight {
        +Shared Function GetRandomHint(enableLengthLimit As Boolean = False, raw As Boolean = False) As String
        -Shared Function LoadExternalHints(externalPath As String) As String[]
        -Shared Function LoadEmbeddedHints() As String[]
        -Shared Function ApplyLengthLimit(lines As String[], enableLengthLimit As Boolean) As String[]
        -Shared Function HtmlEscape(text As String) As String
    }

    class PageLaunchLeft {
        -LabLaunchingHint As Object
        +Sub OpenLaunchingView()
    }

    PageLaunchLeft ..> PageLaunchRight : uses GetRandomHint
    PageLaunchLeft : LabLaunchingHint.Text = PageLaunchRight.GetRandomHint(True, raw=True)
Loading

文件级变更

变更 详情 文件
重构 GetRandomHint,将来自外部和内嵌来源的提示加载逻辑集中到一起,并支持在可选长度限制的基础上返回原始文本或 HTML 转义后的输出。
  • 在保留现有 enableLengthLimit 标志位的同时,扩展 GetRandomHint 方法签名,增加一个新的 raw 参数。
  • 优先从外部 hints.txt 文件加载提示并带有错误处理;当外部文件缺失或读取失败时,回退到从内嵌资源 hints.txt 加载。
  • 在使用提示列表前,先进行标准化处理:对行进行 trim 并过滤掉空行或仅包含空白字符的行。
  • 对已加载的提示应用一次长度限制过滤;如果不存在足够短的提示,则优雅地忽略长度限制,而不是记录日志或进行特殊分支处理。
  • 根据 raw 标志返回原始提示或 HTML 转义后的版本,将转义逻辑整合到单一的返回路径中。
Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchRight.xaml.vb
简化左侧启动页逻辑,直接使用共享的 GetRandomHint 实现,而不是本地包装方法。
  • 从左侧启动页的代码隐藏文件中移除私有的 GetRandomHint 包装方法。
  • 更新启动状态逻辑,通过调用 PageLaunchRight.GetRandomHint(启用长度限制并请求原始输出)来为 LabLaunchingHint.Text 赋值。
Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchLeft.xaml.vb

使用技巧和命令

与 Sourcery 交互

  • 触发一次新的代码审查: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 在某条审查评论下回复,要求 Sourcery 从该评论创建一个 Issue。也可以直接回复 @sourcery-ai issue,从该评论生成 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中任意位置写上 @sourcery-ai,即可随时生成标题。也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文中的任意位置写上 @sourcery-ai summary,即可在精确位置生成 PR 摘要。也可以在 Pull Request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 一次性解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论且不再希望看到它们,这会很有用。
  • 忽略所有 Sourcery 审查: 在 Pull Request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。当你想从头开始一次新的审查时尤其有用——别忘了随后评论 @sourcery-ai review 来触发新的审查!

自定义你的使用体验

前往你的 控制面板 以:

  • 启用或禁用诸如 Sourcery 生成的 Pull Request 摘要、审阅者指南等审查功能。
  • 修改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查相关设置。

获取帮助

Original review guide in English

Reviewer's Guide

Refactors the GetRandomHint logic in PageLaunchRight to unify external and embedded hint loading, add a raw-vs-HTML-escaped return option, and updates the left launch page to call this shared implementation directly with the new signature.

Sequence diagram for the unified GetRandomHint flow

sequenceDiagram
    actor User
    participant PageLaunchLeft
    participant PageLaunchRight
    participant FileSystem
    participant EmbeddedResource

    User->>PageLaunchLeft: OpenLaunchingView
    PageLaunchLeft->>PageLaunchRight: GetRandomHint(enableLengthLimit=True, raw=True)

    alt External hints file exists
        PageLaunchRight->>FileSystem: ReadAllLines(externalPath)
        FileSystem-->>PageLaunchRight: lines
    else External file missing or read failed
        PageLaunchRight->>EmbeddedResource: GetResourceStream(hints.txt)
        EmbeddedResource-->>PageLaunchRight: lines
    end

    alt enableLengthLimit is True
        PageLaunchRight->>PageLaunchRight: Filter lines where length < 50
    end

    PageLaunchRight->>PageLaunchRight: Select random hint from lines

    alt raw is True
        PageLaunchRight-->>PageLaunchLeft: hint (raw)
    else raw is False
        PageLaunchRight->>PageLaunchRight: HtmlEscape(hint)
        PageLaunchRight-->>PageLaunchLeft: escaped hint
    end

    PageLaunchLeft->>PageLaunchLeft: LabLaunchingHint.Text = hint
    PageLaunchLeft-->>User: Show launching page with random hint
Loading

Class diagram for updated GetRandomHint usage

classDiagram
    class PageLaunchRight {
        +Shared Function GetRandomHint(enableLengthLimit As Boolean = False, raw As Boolean = False) As String
        -Shared Function LoadExternalHints(externalPath As String) As String[]
        -Shared Function LoadEmbeddedHints() As String[]
        -Shared Function ApplyLengthLimit(lines As String[], enableLengthLimit As Boolean) As String[]
        -Shared Function HtmlEscape(text As String) As String
    }

    class PageLaunchLeft {
        -LabLaunchingHint As Object
        +Sub OpenLaunchingView()
    }

    PageLaunchLeft ..> PageLaunchRight : uses GetRandomHint
    PageLaunchLeft : LabLaunchingHint.Text = PageLaunchRight.GetRandomHint(True, raw=True)
Loading

File-Level Changes

Change Details Files
Refactor GetRandomHint to centralize hint loading from external and embedded sources and support raw/HTML-escaped output with optional length limiting.
  • Extend GetRandomHint signature with an additional raw parameter while keeping the existing enableLengthLimit flag.
  • Load hints first from an external hints.txt file with error handling, then fall back to an embedded resource hints.txt when needed.
  • Normalize hint lists by trimming and filtering out empty/whitespace-only lines before use.
  • Apply the length limit filter once to the loaded hints and gracefully ignore the limit if no short hints exist, instead of logging and special-casing.
  • Return either the raw hint or an HTML-escaped version based on the raw flag, consolidating the escaping logic into a single return path.
Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchRight.xaml.vb
Simplify the left launch page to use the shared GetRandomHint implementation directly instead of a local wrapper.
  • Remove the private GetRandomHint wrapper method from the left launch page code-behind.
  • Update the launching state to assign LabLaunchingHint.Text by calling PageLaunchRight.GetRandomHint with length limiting enabled and raw output requested.
Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchLeft.xaml.vb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@xrlzu xrlzu marked this pull request as ready for review March 22, 2026 10:58
@pcl-ce-automation pcl-ce-automation bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 and removed 🚧 正在处理 开发人员正在对该内容进行开发、测试或修复,进展中 labels Mar 22, 2026
@xrlzu xrlzu requested a review from a team March 22, 2026 10:58
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些总体反馈:

  • 新的 GetRandomHint 实现不再提供后备字符串,也没有防范外部和内嵌的 hints.txt 同时缺失或为空的情况,这会导致 lines.Length = 0,并在对 lines 索引访问时抛出异常——建议为这种情况添加显式处理,并提供一个默认提示。
  • 在外部文件加载分支中,Catch 代码块现在只记录了一条通用日志消息,同时丢弃了之前会被记录的原始异常细节;建议同时记录异常对象,以保留诊断信息。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- The new `GetRandomHint` implementation no longer provides a fallback string or guards against the case where both external and embedded `hints.txt` are missing/empty, which can lead to `lines.Length = 0` and an exception when indexing into `lines`—consider adding explicit handling and a default hint for this path.
- In the external file loading branch, the `Catch` block now logs only a generic message and drops the original exception details that were previously logged; consider logging the exception object as well to preserve diagnostic information.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • The new GetRandomHint implementation no longer provides a fallback string or guards against the case where both external and embedded hints.txt are missing/empty, which can lead to lines.Length = 0 and an exception when indexing into lines—consider adding explicit handling and a default hint for this path.
  • In the external file loading branch, the Catch block now logs only a generic message and drops the original exception details that were previously logged; consider logging the exception object as well to preserve diagnostic information.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `GetRandomHint` implementation no longer provides a fallback string or guards against the case where both external and embedded `hints.txt` are missing/empty, which can lead to `lines.Length = 0` and an exception when indexing into `lines`—consider adding explicit handling and a default hint for this path.
- In the external file loading branch, the `Catch` block now logs only a generic message and drops the original exception details that were previously logged; consider logging the exception object as well to preserve diagnostic information.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@xrlzu xrlzu requested review from a team and Hill23333 March 23, 2026 11:15
lhx077
lhx077 previously requested changes Mar 24, 2026
@ruattd ruattd dismissed lhx077’s stale review March 24, 2026 08:58

Invalid problem

LinQingYuu

This comment was marked as outdated.

Copy link
Member

@LinQingYuu LinQingYuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pcl-ce-automation pcl-ce-automation bot added 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 and removed 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 labels Mar 24, 2026
@LinQingYuu LinQingYuu merged commit 0f17190 into dev Mar 24, 2026
3 checks passed
@pcl-ce-automation pcl-ce-automation bot added 👌 完成 相关问题已修复或功能已实现,计划在下次版本更新时正式上线 and removed 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 labels Mar 24, 2026
@LinQingYuu LinQingYuu deleted the ref/GetRandomHint branch March 24, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M PR 大小评估:中型 👌 完成 相关问题已修复或功能已实现,计划在下次版本更新时正式上线

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants