Skip to content

refactor(selectionxlat): Split switch cases of SelectionTranslator::translateGameMessage into separate functions#2819

Open
xezon wants to merge 1 commit into
TheSuperHackers:mainfrom
xezon:xezon/refactor-selectionxlat
Open

refactor(selectionxlat): Split switch cases of SelectionTranslator::translateGameMessage into separate functions#2819
xezon wants to merge 1 commit into
TheSuperHackers:mainfrom
xezon:xezon/refactor-selectionxlat

Conversation

@xezon

@xezon xezon commented Jun 21, 2026

Copy link
Copy Markdown

This change splits the switch cases of SelectionTranslator::translateGameMessage into separate functions to ease readability and maintainability for humans.

I tested all regular messages and it worked correctly.

Tip: Disable whitespace in diff viewer to make it reviewable.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing labels Jun 21, 2026
@greptile-apps

greptile-apps Bot commented Jun 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refactors SelectionTranslator::translateGameMessage by extracting each switch-case handler into its own private member function. The motivations are improved readability and easier future maintenance of the large switch block.

  • Each case in the switch is replaced by a single dispatch call (disp = onXxx(msg)), and the logic is moved into correspondingly named private methods on the class.
  • break statements that previously exited the switch now become return KEEP_MESSAGE or return DESTROY_MESSAGE at the appropriate exit points inside each helper, preserving all the original message disposition semantics.
  • Conditional-compilation guards (#if defined(RTS_DEBUG) / #if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)) are maintained in both the header declarations and the switch dispatch, mirroring the original structure.

Confidence Score: 5/5

Safe to merge. The change is a straightforward mechanical extraction of switch-case bodies into named private methods; all message disposition paths, early exits, and conditional-compilation guards are faithfully preserved.

Traced every handler in the diff: each original break with an implicit KEEP_MESSAGE disposition maps to an explicit return KEEP_MESSAGE, and every disp = DESTROY_MESSAGE / break maps to a return DESTROY_MESSAGE. The clearAttackMoveToMode() call in onMouseLeftClick remains on the same reachable paths as before. The inverted condition in onMouseoverDrawableHint is logically identical to the original guard. No functional differences were found.

No files require special attention. Both files are straightforward: the header adds private declarations and the source moves bodies into new functions.

Important Files Changed

Filename Overview
Core/GameEngine/Include/GameClient/SelectionXlat.h Adds a new private section declaring 15 handler methods (plus conditional debug variants). Access specifiers and preprocessor guards correctly match the existing class structure.
Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp Extracts all switch-case bodies into separate handler functions. Dispositions, early-exit paths, and debug-guarded blocks are faithfully translated from break/disp assignments to explicit return values.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Caller
    participant translateGameMessage
    participant Handler as on<EventName>()

    Caller->>translateGameMessage: translateGameMessage(msg)
    translateGameMessage->>translateGameMessage: "switch(msg->getType())"
    Note over translateGameMessage: Each case now dispatches to a helper
    translateGameMessage->>Handler: "disp = onXxx(msg)"
    Handler-->>translateGameMessage: KEEP_MESSAGE or DESTROY_MESSAGE
    translateGameMessage-->>Caller: return disp
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Caller
    participant translateGameMessage
    participant Handler as on<EventName>()

    Caller->>translateGameMessage: translateGameMessage(msg)
    translateGameMessage->>translateGameMessage: "switch(msg->getType())"
    Note over translateGameMessage: Each case now dispatches to a helper
    translateGameMessage->>Handler: "disp = onXxx(msg)"
    Handler-->>translateGameMessage: KEEP_MESSAGE or DESTROY_MESSAGE
    translateGameMessage-->>Caller: return disp
Loading

Reviews (1): Last reviewed commit: "refactor(selectionxlat): Split switch ca..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant