Skip to content

refactor: 重构 Mod Loader 合并安装提交部分 - #3498

Open
Pigeon0v0 wants to merge 3 commits into
devfrom
refactor/mod-loader-install
Open

refactor: 重构 Mod Loader 合并安装提交部分#3498
Pigeon0v0 wants to merge 3 commits into
devfrom
refactor/mod-loader-install

Conversation

@Pigeon0v0

@Pigeon0v0 Pigeon0v0 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Generated by GPT-5.6 Terra Medium

Summary by Sourcery

在安装流程中重构模组加载器的选择逻辑,引入专用枚举并集中处理互斥的加载器。

增强内容:

  • 引入 ModLoaderType 枚举,用于表示在实例安装过程中使用的主要、互斥的模组加载器。
  • 更新实例安装和下载安装逻辑,通过 ModLoaderType 跟踪所选的主要模组加载器,而不是使用原始字符串。
  • 添加辅助方法,在选择新加载器时重置存在冲突的主要模组加载器选择及其相关组件,同时保留与之兼容的附加组件,例如 OptiFine 和 LiteLoader。
Original summary in English

Summary by Sourcery

Refactor mod loader selection in the install flows to use a dedicated enum and centralize mutually exclusive loader handling.

Enhancements:

  • Introduce a ModLoaderType enum representing the primary, mutually exclusive mod loaders used during instance installation.
  • Update instance and download installation logic to track the selected primary mod loader via ModLoaderType instead of raw strings.
  • Add a helper method to reset conflicting primary mod loader selections and their related components when choosing a new loader, while preserving compatible add-ons like OptiFine and LiteLoader.

@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: L PR 大小评估:大型 labels Aug 4, 2026
@sourcery-ai

sourcery-ai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

审阅者指南

重构实例安装和下载安装流程中的模组加载器选择逻辑,使用强类型枚举来表示主加载器,并集中管理互斥加载器的清理逻辑,从而改进与 OptiFine 和 LiteLoader 的兼容性检查的正确性。

SelectModLoader 互斥逻辑流程图

flowchart TD
    A[SelectModLoader ModLoaderType loaderName] --> B{loaderName == Forge}
    B -->|yes| B1[keep selectedForge]
    B -->|no| B2[clear selectedForge]

    A --> C{loaderName == NeoForge}
    C -->|yes| C1[keep selectedNeoForge, selectedNeoForgeVersion]
    C -->|no| C2[clear selectedNeoForge, selectedNeoForgeVersion]

    A --> D{loaderName == Cleanroom}
    D -->|yes| D1[keep selectedCleanroom, selectedCleanroomVersion]
    D -->|no| D2[clear selectedCleanroom, selectedCleanroomVersion]

    A --> E{loaderName == Fabric}
    E -->|yes| E1[keep Fabric components]
    E -->|no| E2[clear selectedFabric, selectedFabricApi, selectedOptiFabric, autoSelectedFabricApi, autoSelectedOptiFabric]

    A --> F{loaderName == LegacyFabric}
    F -->|yes| F1[keep LegacyFabric components]
    F -->|no| F2[clear selectedLegacyFabric, selectedLegacyFabricApi, autoSelectedLegacyFabricApi]

    A --> G{loaderName == LabyMod}
    G -->|yes| G1[keep LabyMod components]
    G -->|no| G2[clear selectedLabyModChannel, selectedLabyModCommitRef, selectedLabyModVersion]

    A --> H[set selectedLoaderName = loaderName]
    H --> I[set selectedAPIName = null]
Loading

文件级变更

变更 细节 文件
引入强类型的主模组加载器表示方式,并更新选择/兼容性逻辑以使用该类型。
  • 新增 ModLoaderType 枚举,用于定义互斥的主加载器(Forge、NeoForge、Cleanroom、Fabric、LegacyFabric、LabyMod)。
  • 将安装页面中的 selectedLoaderName 字段从可空字符串改为可空 ModLoaderType,并相应调整文档注释。
  • 用 ModLoaderType 枚举比较替换字符串相等和 ReferenceEquals 检查,包括在 OptiFine 和 LiteLoader 错误路径中使用模式匹配处理不兼容的加载器组合。
  • 更新 GetCurrentInfo 以及所有加载器选择处理程序(Forge、NeoForge、Cleanroom、Fabric、LegacyFabric、LabyMod),使其分配 ModLoaderType 值而非字符串名称,并保持 LabyMod 的清理逻辑与新类型一致。
Plain Craft Launcher 2/Modules/Minecraft/ModLoaderType.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs
Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.cs
集中管理互斥的主模组加载器选择及其相关状态的清理。
  • 新增 SelectModLoader 辅助方法,当选择一个主加载器时,清理所有其他主加载器的状态和自动选择标记,同时保留可以共存的 OptiFine 和 LiteLoader。
  • 在实例安装页面中,从 Forge、NeoForge、Cleanroom、Fabric、LegacyFabric 和 LabyMod 的选择处理程序中调用 SelectModLoader,以确保状态管理的一致性。
  • 确保在更换主加载器时重置 selectedAPIName,避免保留与前一个加载器绑定的过期 API 选择。
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs

技巧与命令

与 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 来触发新的审查!

自定义你的体验

在你的 dashboard 中可以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、审阅者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查指令。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

Refactors Mod Loader selection in instance and download install flows to use a strongly-typed enum for the main loader and centralizes mutually-exclusive loader clearing logic, improving correctness of compatibility checks with OptiFine and LiteLoader.

Flow diagram for SelectModLoader mutual-exclusion logic

flowchart TD
    A[SelectModLoader ModLoaderType loaderName] --> B{loaderName == Forge}
    B -->|yes| B1[keep selectedForge]
    B -->|no| B2[clear selectedForge]

    A --> C{loaderName == NeoForge}
    C -->|yes| C1[keep selectedNeoForge, selectedNeoForgeVersion]
    C -->|no| C2[clear selectedNeoForge, selectedNeoForgeVersion]

    A --> D{loaderName == Cleanroom}
    D -->|yes| D1[keep selectedCleanroom, selectedCleanroomVersion]
    D -->|no| D2[clear selectedCleanroom, selectedCleanroomVersion]

    A --> E{loaderName == Fabric}
    E -->|yes| E1[keep Fabric components]
    E -->|no| E2[clear selectedFabric, selectedFabricApi, selectedOptiFabric, autoSelectedFabricApi, autoSelectedOptiFabric]

    A --> F{loaderName == LegacyFabric}
    F -->|yes| F1[keep LegacyFabric components]
    F -->|no| F2[clear selectedLegacyFabric, selectedLegacyFabricApi, autoSelectedLegacyFabricApi]

    A --> G{loaderName == LabyMod}
    G -->|yes| G1[keep LabyMod components]
    G -->|no| G2[clear selectedLabyModChannel, selectedLabyModCommitRef, selectedLabyModVersion]

    A --> H[set selectedLoaderName = loaderName]
    H --> I[set selectedAPIName = null]
Loading

File-Level Changes

Change Details Files
Introduce strongly-typed main Mod Loader representation and update selection/compatibility logic to use it.
  • Add ModLoaderType enum defining the mutually exclusive primary loaders (Forge, NeoForge, Cleanroom, Fabric, LegacyFabric, LabyMod).
  • Change selectedLoaderName field from nullable string to nullable ModLoaderType in install pages and adjust documentation comments accordingly.
  • Replace string equality and ReferenceEquals checks with ModLoaderType enum comparisons, including pattern matching for incompatible loader combinations in OptiFine and LiteLoader error paths.
  • Update GetCurrentInfo and all loader selection handlers (Forge, NeoForge, Cleanroom, Fabric, LegacyFabric, LabyMod) to assign ModLoaderType values instead of string names and keep LabyMod clear logic consistent with the new type.
Plain Craft Launcher 2/Modules/Minecraft/ModLoaderType.cs
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs
Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.cs
Centralize mutually-exclusive main Mod Loader selection and clearing of related state.
  • Add SelectModLoader helper that, when a main loader is chosen, clears state and auto-selection flags for all other primary loaders while preserving OptiFine and LiteLoader which may coexist.
  • Invoke SelectModLoader from Forge, NeoForge, Cleanroom, Fabric, LegacyFabric, and LabyMod selection handlers in the instance install page to ensure consistent state management.
  • Ensure selectedAPIName is reset when changing the primary loader to avoid stale API selections tied to previous loaders.
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - 我留下了一些总体反馈:

  • PageInstanceInstall 中新增的 SelectModLoader 辅助函数很好地集中处理了互斥逻辑;建议在 PageDownloadInstall 中也引入一个类似的辅助函数,以保持两个流程中加载器选择/清除行为的一致性。
  • 既然 selectedLoaderName 现在保存的是 ModLoaderType 枚举值,可以考虑重命名(例如改为 selectedLoaderType),以更好地体现它的用途,并避免与之前基于字符串的旧用法混淆。
  • SelectModLoader 当前使用了一长串 if 语句;将其改为 switch 表达式或基于表驱动的方式,可能会让以后新增加载器类型时的维护更轻松。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- PageInstanceInstall 中新增的 SelectModLoader 辅助函数很好地集中处理了互斥逻辑;建议在 PageDownloadInstall 中也引入一个类似的辅助函数,以保持两个流程中加载器选择/清除行为的一致性。
- 既然 selectedLoaderName 现在保存的是 ModLoaderType 枚举值,可以考虑重命名(例如改为 selectedLoaderType),以更好地体现它的用途,并避免与之前基于字符串的旧用法混淆。
- SelectModLoader 当前使用了一长串 if 语句;将其改为 switch 表达式或基于表驱动的方式,可能会让以后新增加载器类型时的维护更轻松。

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

Hey - I've left some high level feedback:

  • The new SelectModLoader helper in PageInstanceInstall centralizes mutual‑exclusion logic nicely; consider introducing a similar helper in PageDownloadInstall to keep loader selection/clearing behavior consistent between the two flows.
  • Now that selectedLoaderName holds a ModLoaderType enum, you might want to rename it (e.g., selectedLoaderType) to better reflect its purpose and avoid confusion with the legacy string-based usage.
  • SelectModLoader currently uses a long chain of if statements; converting this to a switch expression or table-driven approach could make future additions of new loader types easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new SelectModLoader helper in PageInstanceInstall centralizes mutual‑exclusion logic nicely; consider introducing a similar helper in PageDownloadInstall to keep loader selection/clearing behavior consistent between the two flows.
- Now that selectedLoaderName holds a ModLoaderType enum, you might want to rename it (e.g., selectedLoaderType) to better reflect its purpose and avoid confusion with the legacy string-based usage.
- SelectModLoader currently uses a long chain of if statements; converting this to a switch expression or table-driven approach could make future additions of new loader types easier to maintain.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: L PR 大小评估:大型 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant