fix(fleet): ship_type validation and diagnostics improvements#445
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
- validate and normalize ship_type in FleetRuleRequest - update change_fleet selector docs to include ship_type - include ship_type constraint in choose-ship final failure diagnostics
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
This PR tightens ship_type handling end-to-end for fleet replacement: validating/normalizing ship_type on the server, threading it through fleet slot selectors, and using OCR-based ship-type detection in the choose-ship UI to disambiguate same-name ships while improving diagnostics when selection fails.
Changes:
- Add
ship_typetoFleetRuleRequestwith strict normalization + validation. - Pass
ship_typethrough fleet-change selector extraction and update selector docs. - Add ship-type OCR detection/filtering in choose-ship selection, and include
ship_typein final error/log messages.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| autowsgr/ui/choose_ship_page.py | Adds ship-type OCR detection + filtering during list click selection; improves error diagnostics and normalizes search keywords. |
| autowsgr/ui/battle/fleet_change/_change.py | Extends selector extraction/matching to include ship_type and improves search-name comparison normalization. |
| autowsgr/server/schemas.py | Adds ship_type to FleetRuleRequest with allowed-code validation and normalization. |
| autowsgr/init.py | Bumps version to 2.1.9.post7. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return None | ||
| normalized = text.replace(' ', '') | ||
| for ship_type, keywords in _SHIP_TYPE_KEYWORDS.items(): | ||
| if any(keyword in normalized for keyword in keywords): | ||
| return ship_type | ||
| return None |
There was a problem hiding this comment.
_extract_ship_type_from_text() only removes literal spaces (text.replace(' ', '')). OCR output commonly contains other whitespace (e.g., newlines/tabs), which will prevent keyword matching and make ship_type filtering flaky. Consider normalizing by removing all whitespace characters (not just ASCII spaces) before searching keywords.
| # 舰名尾部别名后缀,如“(苍青幻影)” | ||
| _SHIP_ALIAS_SUFFIX_RE = re.compile(r'\s*[((][^()()]*[))]\s*$') | ||
|
|
There was a problem hiding this comment.
_SHIP_ALIAS_SUFFIX_RE and the associated alias-suffix normalization logic are now duplicated across modules (here and ChooseShipPage). This duplication is easy to let drift and will cause inconsistent matching behavior over time; consider centralizing it in a shared util (or importing the existing helper) so both fleet-change short-circuiting and choose-ship searching stay consistent.
Summary
Address Copilot review comments on PR #444.
Changes
Notes