Skip to content

feat: 新增模型切换事件订阅功能#20

Merged
BAKAOLC merged 1 commit into
mainfrom
develop
Nov 22, 2025
Merged

feat: 新增模型切换事件订阅功能#20
BAKAOLC merged 1 commit into
mainfrom
develop

Conversation

@BAKAOLC
Copy link
Copy Markdown
Collaborator

@BAKAOLC BAKAOLC commented Nov 22, 2025

变更内容

本次更新新增了模型切换事件订阅功能,允许其他模块监听并响应模型切换操作。

主要变更

  • 新增 ModelChangedEventArgs 事件参数类 (DuckovCustomModel.Core/Data/ModelChangedEventArgs.cs)

    • 包含目标类型 (ModelTarget)
    • 模型ID和名称
    • AI角色名称键(如适用)
    • 是否恢复原始模型
    • 操作是否成功
    • 处理器数量
  • ModelListManager 中添加 OnModelChanged 静态事件

    • 支持订阅模型切换、恢复等操作的通知
    • 在成功和失败情况下都会触发事件
  • 在以下方法中触发事件

    • ApplyModelToTarget - 应用模型到目标时
    • ApplyModelToAICharacter - 应用模型到AI角色时
    • RestoreOriginalModelForTarget - 恢复原始模型时

使用示例

// 订阅模型切换事件
ModelListManager.OnModelChanged += OnModelChanged;

// 事件处理函数
private void OnModelChanged(ModelChangedEventArgs args)
{
    if (args.Success)
    {
        if (args.IsRestored)
        {
            ModLogger.Log($"模型已恢复: {args.Target}, 处理器数量: {args.HandlerCount}");
        }
        else
        {
            ModLogger.Log($"模型已切换: {args.ModelName} ({args.ModelID}), 目标: {args.Target}");
        }
    }
}

// 取消订阅
ModelListManager.OnModelChanged -= OnModelChanged;

版本信息

  • 版本号:v1.8.10
  • 已更新 CHANGELOG.md 和 CHANGELOG_EN.md

- 在 `ModelListManager` 中添加 `OnModelChanged` 静态事件,用于订阅模型切换通知
- 新增 `ModelChangedEventArgs` 类,包含模型切换的详细信息
- 在模型切换、恢复等操作中自动触发事件,支持成功和失败的情况
- 支持为角色、宠物和AI角色分别监听模型切换事件
- 更新版本号至 v1.8.10
Copilot AI review requested due to automatic review settings November 22, 2025 11:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR merges the develop branch into main, introducing a new model change event subscription feature that allows external code to subscribe to model switching notifications.

Key changes:

  • Added OnModelChanged event to ModelListManager for real-time model change notifications
  • Created ModelChangedEventArgs class to encapsulate event data including target type, model ID, success status, and handler count
  • Event invocations added to all model application and restoration code paths, covering both success and failure scenarios

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
DuckovCustomModel/Managers/ModelListManager.cs Added OnModelChanged event declaration and invocations in ApplyModelToTarget, RestoreOriginalModelForTarget, and ApplyModelToAICharacter methods for both success and failure cases
DuckovCustomModel.Core/Data/ModelChangedEventArgs.cs New event arguments class containing model change information including target, model ID/name, restoration status, success flag, and handler count
CHANGELOG.md Added v1.8.10 release notes documenting the new model change event subscription feature in Chinese
CHANGELOG_EN.md Added v1.8.10 release notes documenting the new model change event subscription feature in English

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@BAKAOLC BAKAOLC changed the title 合并 develop 到 main feat: 新增模型切换事件订阅功能 Nov 22, 2025
@BAKAOLC BAKAOLC merged commit 063734a into main Nov 22, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants