Repository navigation
Defense Post Radius Overlay - #423
kanekane0448 wants to merge 20 commits into
Conversation
|
|
||
| Translators are welcome! Please feel free to help translate into your language. | ||
| How to help? | ||
|
|
There was a problem hiding this comment.
Had to add this or it wouldn't pass the prettier check
# Conflicts: # src/client/graphics/layers/OptionsMenu.ts
# Conflicts: # src/core/configuration/PastelTheme.ts # src/core/configuration/PastelThemeDark.ts
|
kanekane0448 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
WalkthroughA toggleable overlay for defense post range was introduced. New user settings, theme methods, and color constants support the feature. The options menu now includes a toggle button, and the territory rendering logic conditionally displays the defense post range on both border and inner tiles, using a darkened color. The overlay is off by default. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant OptionsMenu
participant UserSettings
participant EventBus
participant TerritoryLayer
User->>OptionsMenu: Clicks "Show Defense Post Range" toggle
OptionsMenu->>UserSettings: toggleShowDefensePostRange()
OptionsMenu->>EventBus: emit(ToggleShowDefensePostRangeEvent)
EventBus-->>TerritoryLayer: ToggleShowDefensePostRangeEvent
TerritoryLayer->>TerritoryLayer: Update rendering logic
TerritoryLayer->>UserSettings: showDefensePostRange()
TerritoryLayer->>Theme: defendedTerritoryColor(player)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Assessment against linked issues
Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/core/configuration/PastelTheme.ts (1)
79-81: Fix parameter name inconsistency.The implementation logic is correct, but the parameter name should match the interface definition for consistency.
- defendedTerritoryColor(player: PlayerView): Colord { - return this.territoryColor(player).darken(defendedTerritoryDarkenPercent); + defendedTerritoryColor(playerInfo: PlayerView): Colord { + return this.territoryColor(playerInfo).darken(defendedTerritoryDarkenPercent);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
src/client/InputHandler.ts(1 hunks)src/client/graphics/layers/OptionsMenu.ts(3 hunks)src/client/graphics/layers/TerritoryLayer.ts(5 hunks)src/core/configuration/Colors.ts(1 hunks)src/core/configuration/Config.ts(1 hunks)src/core/configuration/PastelTheme.ts(2 hunks)src/core/configuration/PastelThemeDark.ts(2 hunks)src/core/game/UserSettings.ts(2 hunks)
🧰 Additional context used
🧠 Learnings (8)
src/core/game/UserSettings.ts (1)
Learnt from: VariableVince
PR: #1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
src/core/configuration/Config.ts (4)
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
Learnt from: devalnor
PR: #1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/Colors.ts:114-330
Timestamp: 2025-06-06T15:36:31.739Z
Learning: In the OpenFrontIO project, color improvements are implemented incrementally. The current focus for player colors is ensuring sufficient unique color availability rather than optimizing for visual distinction or accessibility features.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/PastelThemeDark.ts:20-21
Timestamp: 2025-06-06T15:42:21.903Z
Learning: In ColorAllocator class, all methods (assignBotColor, assignPlayerColor, assignTeamColor) use the constructor colors from this.availableColors. Only the predefined team cases in assignTeamColor use hardcoded global colors, while the default case uses constructor colors.
src/core/configuration/Colors.ts (5)
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
Learnt from: scottanderson
PR: #786
File: src/client/TerritoryPatternsModal.ts:337-338
Timestamp: 2025-06-22T05:48:19.241Z
Learning: In src/client/TerritoryPatternsModal.ts, the bit shifting operators (<<) used in coordinate calculations with decoder.getScale() are intentional and should not be changed to multiplication. The user scottanderson confirmed this is functioning as intended.
Learnt from: devalnor
PR: #1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/PastelThemeDark.ts:20-21
Timestamp: 2025-06-06T15:42:21.903Z
Learning: In ColorAllocator class, all methods (assignBotColor, assignPlayerColor, assignTeamColor) use the constructor colors from this.availableColors. Only the predefined team cases in assignTeamColor use hardcoded global colors, while the default case uses constructor colors.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/Colors.ts:114-330
Timestamp: 2025-06-06T15:36:31.739Z
Learning: In the OpenFrontIO project, color improvements are implemented incrementally. The current focus for player colors is ensuring sufficient unique color availability rather than optimizing for visual distinction or accessibility features.
src/core/configuration/PastelThemeDark.ts (7)
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
Learnt from: devalnor
PR: #1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/Colors.ts:114-330
Timestamp: 2025-06-06T15:36:31.739Z
Learning: In the OpenFrontIO project, color improvements are implemented incrementally. The current focus for player colors is ensuring sufficient unique color availability rather than optimizing for visual distinction or accessibility features.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/Colors.ts:398-411
Timestamp: 2025-06-06T21:43:15.706Z
Learning: In ColorAllocator class, the assignPlayerColor method intentionally allows color duplicates when the humanColors palette is exhausted by resetting availableColors to the full humanColors array. This is done on purpose as an acceptable temporary limitation, with potential palette improvements planned for later.
Learnt from: 1brucben
PR: #977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
Learnt from: scottanderson
PR: #786
File: src/client/TerritoryPatternsModal.ts:337-338
Timestamp: 2025-06-22T05:48:19.241Z
Learning: In src/client/TerritoryPatternsModal.ts, the bit shifting operators (<<) used in coordinate calculations with decoder.getScale() are intentional and should not be changed to multiplication. The user scottanderson confirmed this is functioning as intended.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/PastelThemeDark.ts:20-21
Timestamp: 2025-06-06T15:42:21.903Z
Learning: In ColorAllocator class, all methods (assignBotColor, assignPlayerColor, assignTeamColor) use the constructor colors from this.availableColors. Only the predefined team cases in assignTeamColor use hardcoded global colors, while the default case uses constructor colors.
src/client/graphics/layers/OptionsMenu.ts (1)
Learnt from: VariableVince
PR: #1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
src/client/InputHandler.ts (1)
Learnt from: VariableVince
PR: #1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
src/core/configuration/PastelTheme.ts (7)
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
Learnt from: devalnor
PR: #1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/Colors.ts:114-330
Timestamp: 2025-06-06T15:36:31.739Z
Learning: In the OpenFrontIO project, color improvements are implemented incrementally. The current focus for player colors is ensuring sufficient unique color availability rather than optimizing for visual distinction or accessibility features.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/Colors.ts:398-411
Timestamp: 2025-06-06T21:43:15.706Z
Learning: In ColorAllocator class, the assignPlayerColor method intentionally allows color duplicates when the humanColors palette is exhausted by resetting availableColors to the full humanColors array. This is done on purpose as an acceptable temporary limitation, with potential palette improvements planned for later.
Learnt from: scottanderson
PR: #786
File: src/client/TerritoryPatternsModal.ts:337-338
Timestamp: 2025-06-22T05:48:19.241Z
Learning: In src/client/TerritoryPatternsModal.ts, the bit shifting operators (<<) used in coordinate calculations with decoder.getScale() are intentional and should not be changed to multiplication. The user scottanderson confirmed this is functioning as intended.
Learnt from: 1brucben
PR: #977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
Learnt from: Ble4Ch
PR: #1063
File: src/core/configuration/PastelThemeDark.ts:20-21
Timestamp: 2025-06-06T15:42:21.903Z
Learning: In ColorAllocator class, all methods (assignBotColor, assignPlayerColor, assignTeamColor) use the constructor colors from this.availableColors. Only the predefined team cases in assignTeamColor use hardcoded global colors, while the default case uses constructor colors.
src/client/graphics/layers/TerritoryLayer.ts (3)
Learnt from: devalnor
PR: #1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
Learnt from: scottanderson
PR: #786
File: src/client/TerritoryPatternsModal.ts:337-338
Timestamp: 2025-06-22T05:48:19.241Z
Learning: In src/client/TerritoryPatternsModal.ts, the bit shifting operators (<<) used in coordinate calculations with decoder.getScale() are intentional and should not be changed to multiplication. The user scottanderson confirmed this is functioning as intended.
Learnt from: VariableVince
PR: #1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
🧬 Code Graph Analysis (5)
src/core/configuration/Config.ts (1)
src/core/game/GameView.ts (1)
PlayerView(125-270)
src/core/configuration/PastelThemeDark.ts (2)
src/core/game/GameView.ts (1)
PlayerView(125-270)src/core/configuration/Colors.ts (1)
defendedTerritoryDarkenPercent(12-12)
src/client/graphics/layers/OptionsMenu.ts (1)
src/client/InputHandler.ts (1)
ToggleShowDefensePostRangeEvent(62-62)
src/client/InputHandler.ts (1)
src/core/EventBus.ts (1)
GameEvent(1-1)
src/core/configuration/PastelTheme.ts (2)
src/core/game/GameView.ts (1)
PlayerView(125-270)src/core/configuration/Colors.ts (1)
defendedTerritoryDarkenPercent(12-12)
🔇 Additional comments (16)
src/client/InputHandler.ts (1)
62-63: LGTM! Clean marker event implementation.The new event follows the established pattern for marker events in this file. The naming is clear and consistent with other toggle events.
src/core/game/UserSettings.ts (2)
33-35: LGTM! Consistent with existing settings pattern.The getter method follows the established pattern and correctly defaults to
falseas specified in the PR objectives.
58-60: LGTM! Standard toggle implementation.The toggle method correctly follows the existing pattern used by other settings in this class.
src/core/configuration/Colors.ts (1)
12-12: LGTM! Well-named constant for consistent theming.The 7.5% darkening factor provides a good balance for visual distinction without being too strong. Having this as a shared constant ensures consistency across different theme implementations.
src/core/configuration/Config.ts (1)
129-129: LGTM! Clean interface extension.The new method signature follows the established pattern for theme color methods. The parameter and return types are appropriate for the defended territory color feature.
src/core/configuration/PastelTheme.ts (1)
11-11: LGTM! Proper import for consistent theming.Good use of the shared constant to ensure consistent darkening across all theme implementations.
src/core/configuration/PastelThemeDark.ts (2)
11-11: LGTM: Clean import of configuration constant.The
defendedTerritoryDarkenPercentconstant is properly imported from the Colors configuration file, maintaining separation of concerns.
79-81: LGTM: Simple and consistent implementation.The
defendedTerritoryColormethod follows the established pattern of other color methods in this theme class. The implementation is clean - it reuses the existingterritoryColormethod and applies a consistent darkening effect using the imported configuration constant.src/client/graphics/layers/OptionsMenu.ts (3)
8-12: LGTM: Clean import structure.The import statement properly includes the new
ToggleShowDefensePostRangeEventwhile maintaining the existing structure and formatting.
122-125: LGTM: Consistent toggle method implementation.The
onToggleShowDefensePostRangemethod follows the established pattern of other toggle methods in this class - it toggles the user setting and emits the corresponding event. The implementation is clean and consistent.
226-232: LGTM: Well-integrated settings button.The new defense post range button follows the established pattern of other settings buttons. The shield emoji (🛡️) is appropriate for the defense post feature, and the "Show"/"Hide" text clearly indicates the current state.
src/client/graphics/layers/TerritoryLayer.ts (5)
14-18: LGTM: Clean import structure.The import statement properly includes the new
ToggleShowDefensePostRangeEventwhile maintaining the existing structure and formatting.
73-88: LGTM: Well-structured conditional logic.The defense post handling logic is clean and readable. The distance function selection using a conditional assignment is clear, and the BFS logic properly handles both border tiles (always) and all tiles (when setting is enabled). The owner ID check for border tiles ensures correct behavior.
152-159: LGTM: Efficient event handling.The event listener properly handles the toggle by re-enqueueing all affected tiles using Euclidean distance for the full range display. This ensures the UI updates correctly when the setting is toggled.
267-271: LGTM: Clean boolean extraction improves readability.Extracting
tileIsInDefensePostRangeas a boolean variable makes the subsequent conditional logic much more readable and follows the principle of single responsibility.
296-302: LGTM: Clear conditional color selection.The color selection logic is well-structured with clear conditions. The implementation properly checks both the defense post range status and the user setting before applying the defended territory color, maintaining good separation between border and non-border tile handling.
|
@kanekane0448 could you resolve conflicts? |
|
@TheGiraffe3 This is beneficial, I'm willing to pick this up, this should be extended to all types of buildings. |
|
@DanyPops I'd say go for it, since the original author hasn't responded. |
Description:
This adds an overlay that shows the Defense Post range not only on the border tiles but also on the inner territory tiles, in order to allow the player to spread out their Defense Posts or assess their opponent's Defense Post coverage more effectively. The overlay can be toggled on or off through the settings panel. It's off by default.
Fixes #479
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
kanekane0448