Skip to content

fix(fleet): support ship-type selector and alias-safe search#444

Closed
yltx wants to merge 2 commits intomainfrom
fix/fleet-rule-shiptype-searchname-post7
Closed

fix(fleet): support ship-type selector and alias-safe search#444
yltx wants to merge 2 commits intomainfrom
fix/fleet-rule-shiptype-searchname-post7

Conversation

@yltx
Copy link
Copy Markdown
Contributor

@yltx yltx commented Apr 15, 2026

Summary

This PR improves fleet replacement and choose-ship matching for same-name ships and type-constrained slots.

Changes

  • add ship_type field to FleetRuleRequest
  • pass ship_type through fleet slot selector extraction
  • normalize search_name when comparing current members (·改 and trailing alias parentheses)
  • normalize first search keyword input in choose-ship page
  • add OCR-based ship-type recognition around matched row and enforce ship_type filter (including ss_or_ssg)

Release

  • bump backend version from 2.1.9.post6 to 2.1.9.post7 to trigger backend update pipeline

yltx added 2 commits April 15, 2026 18:55
- 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
Copilot AI review requested due to automatic review settings April 15, 2026 11:47
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 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_type to FleetRuleRequest and 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_type filtering (including ss_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.

Comment on lines 72 to 76
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='等级上限(含)')
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 42 to 49
class FleetSlotSelector(TypedDict, total=False):
"""编队槽位规则。"""

candidates: list[str]
search_name: str
ship_type: str
min_level: int
max_level: int
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +438 to +452
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
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@yltx
Copy link
Copy Markdown
Contributor Author

yltx commented Apr 15, 2026

Superseded by the new PR with review fixes.

@yltx yltx closed this Apr 15, 2026
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