refactor: Refactor evaluateContextCommand phase 1 (#1192)#2714
Conversation
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp | Three new private methods extracted from evaluateContextCommand (normalizeContextInputs, handleWaypointModeCommand, normalizeGuiCommandTarget); all previously-reported missing-call and orphaned-else-if issues appear resolved; minor bool/Bool style inconsistency introduced. |
| GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h | Three new private method declarations added; uses #pragma once correctly; no issues found. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[evaluateContextCommand] --> B[normalizeContextInputs]
B --> C{prefer selection mode?}
C -->|yes| D[return MSG_INVALID]
C -->|no| E{PLACE_BEACON command?}
E -->|yes| F[return MSG_VALID_GUICOMMAND_HINT]
E -->|no| G{canPerformActions?}
G -->|no| H[return MSG_INVALID]
G -->|yes| I{isInWaypointMode?}
I -->|yes| J[handleWaypointModeCommand - return]
I -->|no| K{command and isContextCommand or SPECIAL_POWER?}
K -->|yes| L[normalizeGuiCommandTarget]
L --> M[switch on command type - build hint or issue command]
K -->|no| N[else-if CONSTRUCT branches]
N --> O[else-if action branches - attack, repair, dock, enter, etc.]
O --> P[else - issueMoveToLocation]
M --> R[return msgType]
P --> R
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp:1679-1682
The surrounding codebase uses the `Bool` typedef throughout (see `Bool currentlyValid = FALSE;` just below), but `canPerformActions` is declared with the built-in `bool`. Prefer `Bool` here for consistency.
```suggestion
const Bool canPerformActions = (
TheInGameUI->areSelectedObjectsControllable() ||
(command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT)
);
```
### Issue 2 of 2
GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp:1700
The `normalizeGuiCommandTarget` call is indented with spaces while the rest of the block uses tabs, leaving a visible indentation mismatch. Align with the surrounding tab-indented code.
Reviews (2): Last reviewed commit: "fix: Revert incorrectly changed logic du..." | Re-trigger Greptile
- Refactor context input normalization into separate function - Refactor GUI command target normalization into separate function - Refactor waypoint mode command into separate function - Clarify intent of early returns
3712493 to
4fd400f
Compare
|
Brackets need to be on their own line. |
Relates to: #1192
Initial plan is to extract the context command handling into focused sub-functions, so the decision path in
evaluateContextCommandbecomes immediately legible as a dispatcher. Once the structure is clear, the aim is to simplify the logical flow by eliminating redundant branching and guard conditions that no longer need to live at the top levelTODO: