Skip to content

已修复按类型枚举。#348

Merged
huan-yp merged 3 commits intoOpenWSGR:mainfrom
yltx:main
Mar 5, 2026
Merged

已修复按类型枚举。#348
huan-yp merged 3 commits intoOpenWSGR:mainfrom
yltx:main

Conversation

@yltx
Copy link
Copy Markdown
Contributor

@yltx yltx commented Mar 5, 2026

No description provided.

yltx added 2 commits March 6, 2026 01:09
- Add CombatStopRequested exception for graceful combat stop

- Add stop_event (threading.Event) to GameContext

- Check stop signal in CombatRecognizer.wait_for_phase()

- Handle CombatStopRequested in CombatEngine.fight() loop

- Use Pydantic Discriminator for multi-type task endpoint

- Change task type fields from TaskType enum to Literal strings

- Bind task_manager._stop_event to ctx.stop_event on task start
NodeConfig.enemy_rules and enemy_formation_rules now accept list[str | list] to support mixed formats found in YAML combat plans.
Copilot AI review requested due to automatic review settings March 5, 2026 17:11
@huan-yp huan-yp merged commit 7f75cfe into OpenWSGR:main Mar 5, 2026
1 check failed
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

该 PR 旨在修复“按类型枚举/分发”的请求解析问题,并补齐任务停止信号在战斗循环中的传播与响应。

Changes:

  • 将各任务请求的 type 字段改为 Literal[...],以支持基于 type 的判别联合(discriminated union)
  • 在 FastAPI 入口使用 Discriminator('type') 统一解析任务请求,并将 TaskManager 的停止事件绑定到 GameContext
  • 在战斗识别/引擎循环中新增对停止信号的检查与退出流程,同时扩展配置规则类型

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
autowsgr/server/schemas.py Literal[TaskType.X] 固化判别字段以支持按类型解析
autowsgr/server/main.py 引入判别联合请求类型,并将停止事件绑定到上下文
autowsgr/infra/config.py 放宽规则列表元素类型以支持更复杂结构
autowsgr/context/game_context.py 在上下文中新增 stop_event 以传递停止信号
autowsgr/combat/recognizer.py 在轮询识别中检查 stop_event 并抛出停止异常
autowsgr/combat/engine.py 捕获取消异常并优雅退出战斗循环

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

Comment thread autowsgr/server/main.py
Comment on lines 198 to 199
if isinstance(request, NormalFightRequest):
return await _start_normal_fight(ctx, request)
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

这里直接访问并暴露 task_manager._stop_event(私有属性)会造成较强的实现耦合,也让后续替换 TaskManager 实现或事件类型变得困难。建议在 TaskManager 上提供公开的 stop_event 属性/方法(返回与 GameContext.stop_event 兼容的事件对象),并在此处改用公开接口进行绑定。

Suggested change
if isinstance(request, NormalFightRequest):
return await _start_normal_fight(ctx, request)
# 将任务管理器的停止事件绑定到游戏上下文,优先使用 TaskManager 的公开接口
stop_event = getattr(task_manager, "stop_event", None)
if stop_event is None:
# 兼容旧实现,退回到私有属性;后续可在 TaskManager 中提供正式接口后移除
stop_event = getattr(task_manager, "_stop_event")
ctx.stop_event = stop_event

Copilot uses AI. Check for mistakes.
Comment thread autowsgr/infra/config.py
Comment on lines +370 to +372
enemy_rules: list[str | list] = Field(default_factory=list)
"""索敌规则列表"""
enemy_formation_rules: list[str] = Field(default_factory=list)
enemy_formation_rules: list[str | list] = Field(default_factory=list)
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

类型 list[str | list] 中的 list 未参数化,导致元素类型变得过于宽泛(等价于 list[Any]),会削弱静态检查与 IDE 提示,也不利于后续维护。建议为嵌套列表明确元素类型(例如元素允许 strlist[str]),或定义一个清晰的类型别名(如 Rule = str | list[str])后复用到两个字段上。

Copilot uses AI. Check for mistakes.
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.

3 participants