fix(fleet): support ship-type selector and alias-safe search#444
fix(fleet): support ship-type selector and alias-safe search#444
Conversation
- add ship_type to FleetRuleRequest and slot selector - normalize search_name for first search and in-compare matching - filter choose-ship hits by OCR-detected ship type
There was a problem hiding this comment.
Pull request overview
This PR extends the fleet replacement flow to better handle same-name ships and type-constrained fleet slots by carrying a ship_type constraint through the rule schema, selector extraction, and choose-ship UI selection logic (including OCR-based ship-type recognition).
Changes:
- Add
ship_typetoFleetRuleRequestand propagate it through fleet slot selector extraction into the choose-ship selection path. - Normalize choose-ship search keyword inputs (strip
·改and trailing alias parentheses) to improve matching. - Add OCR-based ship-type detection near matched rows and enforce
ship_typefiltering (includingss_or_ssg), plus bump backend version.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| autowsgr/ui/choose_ship_page.py | Normalize search keyword input; add OCR ship-type detection + ship_type filtering in list selection. |
| autowsgr/ui/battle/fleet_change/_change.py | Extend selector extraction and same-name matching logic to support ship_type and alias-safe comparisons. |
| autowsgr/server/schemas.py | Add ship_type field to the API request schema for fleet rules. |
| autowsgr/init.py | Bump package version to 2.1.9.post7. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| candidates: list[str] = Field(min_length=1, description='候选舰船名(按优先级)') | ||
| search_name: str | None = Field(default=None, description='选船搜索关键词(用于同名舰船区分)') | ||
| ship_type: str | None = Field(default=None, description='舰种约束(如 cl/cav/ss)') | ||
| min_level: int | None = Field(default=None, ge=1, description='等级下限(含)') | ||
| max_level: int | None = Field(default=None, ge=1, description='等级上限(含)') |
There was a problem hiding this comment.
FleetRuleRequest.ship_type currently accepts any string. If an unknown value is provided (typo, unsupported code), the UI filtering will never match and the user will only see a late runtime failure. Consider adding a field_validator('ship_type') to normalize (strip/lower) and validate against an allowed set (e.g. the supported codes plus ss_or_ssg), raising a clear ValueError on invalid input.
| class FleetSlotSelector(TypedDict, total=False): | ||
| """编队槽位规则。""" | ||
|
|
||
| candidates: list[str] | ||
| search_name: str | ||
| ship_type: str | ||
| min_level: int | ||
| max_level: int |
There was a problem hiding this comment.
FleetSlotSelector now supports ship_type, but the change_fleet() docstring still lists only candidates/search_name/min_level/max_level for selector rules. Please update the docstring (and any related docs) to include ship_type so callers discover the new option.
| if ship_type is not None: | ||
| detected_ship_type = self._detect_ship_type_near_hit( | ||
| screen, | ||
| cx, | ||
| cy, | ||
| row_key, | ||
| ) | ||
| if not self._is_ship_type_in_rule(detected_ship_type, ship_type): | ||
| _log.warning( | ||
| "[UI] 命中 '{}' 舰种 '{}' 不满足要求 '{}'", | ||
| matched, | ||
| detected_ship_type if detected_ship_type is not None else '未知', | ||
| ship_type, | ||
| ) | ||
| continue |
There was a problem hiding this comment.
When ship_type filtering rejects all hits (e.g. OCR can’t reliably detect the type, or the rule value is unsupported), the eventual failure in change_single_ship() only reports candidates/level constraints and doesn’t mention ship_type. Consider including the ship_type constraint in the final error message/log so this is diagnosable.
|
Superseded by the new PR with review fixes. |
Summary
This PR improves fleet replacement and choose-ship matching for same-name ships and type-constrained slots.
Changes
ship_typefield toFleetRuleRequestship_typethrough fleet slot selector extractionsearch_namewhen comparing current members (·改and trailing alias parentheses)ship_typefilter (includingss_or_ssg)Release
2.1.9.post6to2.1.9.post7to trigger backend update pipeline