Skip to content

Feature/random map hidden previews and nation count#4158

Open
noahschmal wants to merge 9 commits into
openfrontio:mainfrom
noahschmal:feature/random-map-hidden
Open

Feature/random map hidden previews and nation count#4158
noahschmal wants to merge 9 commits into
openfrontio:mainfrom
noahschmal:feature/random-map-hidden

Conversation

@noahschmal

Copy link
Copy Markdown
Contributor

Add approved & assigned issue number here:

Resolves #3211

Description:

When a host selects the random map option, the map is resolved in the lobby and leaks into the nation count and preview embeds for the lobby. This PR fixes this by adding a randomMap flag on GameConfig that keeps it hidden on any visual surfaces. This also adjusts the nation slider to show "Map Default" with the fill in the middle of the slider for the random map, and adds a "↺ map default" button to reset it to default. The slider is set to the middle, obscuring which random map it is. The "↺ map default" button may be useful for all maps. Note that there is no provided preview of what a preview embed looks like since I can't access that when hosting locally, however, there is an associated test, and the image is the RandomMap.webp asset.

Default nation count in the middle with no number:
Screenshot 2026-06-04 at 2 59 55 PM

Slider moved from default, with reset to default visible:
Screenshot 2026-06-04 at 3 00 06 PM

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory

Please put your Discord username so you can be contacted if a bug or regression is found:

jetaviz

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a randomMap flag to GameConfig; hides concrete map and default nation counts before game start across client modals, lobby UI, preview builder, server lifecycle, and tests; introduces a FluentSlider hidden-default mode and wires it into game-config settings.

Changes

Random Map Visibility Control

Layer / File(s) Summary
Core Schema and Type Foundation
src/core/Schemas.ts
Adds optional randomMap: boolean to GameConfigSchema with comments about prestart clearing.
Slider Component with Hidden Default
src/client/components/FluentSlider.ts, tests/client/components/FluentSlider.test.ts
FluentSlider adds hideDefaultValue and resetToDefault(); computes masked displayValue to park the thumb and conditionally shows a reset button and default-only label. Tests cover parking, drag behavior, dispatching, and reset.
Config Settings Nations Integration
src/client/components/GameConfigSettings.ts
Adds optional hideDefaultValue?: boolean to options.nations and passes it into fluent-slider (fallback false).
Modal Components Configuration Wiring
src/client/HostLobbyModal.ts, src/client/JoinLobbyModal.ts, src/client/SinglePlayerModal.ts
Host/SinglePlayer set options.nations.hideDefaultValue = useRandomMap. Host emits config.randomMap in "update-game-config". Join/Host supply .randomMap to lobby-player-view; Join shows localized map.random and images/RandomMap.webp for random lobbies.
Lobby Header Display Logic
src/client/components/LobbyPlayerView.ts
Adds randomMap property; effectiveNationCount returns 0 when true; header and team preview recompute to avoid revealing nation count or concrete map.
Server Game Config and Lifecycle
src/server/GameServer.ts
updateGameConfig merges incoming randomMap into stored gameConfig. prestart sets gameConfig.randomMap = false before creating/broadcasting prestart.
Preview Embed Map Masking
src/server/GamePreviewBuilder.ts
buildPreview computes isRandomMap for unstarted random lobbies; when true, skips map normalization/thumbnail, uses RandomMap.webp, and sets display map/title to "Random Map".
Test Coverage
tests/RandomMapConfig.test.ts, tests/client/components/FluentSlider.test.ts, tests/server/GameLifecycle.test.ts, tests/server/GamePreviewRandomMap.test.ts
Vitest suites validate randomMap parsing in intents, FluentSlider hidden-default behavior, server prestart clearing and config merging, and preview masking for random vs non-random lobbies.

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

Feature, UI/UX, Backend

Suggested reviewers

  • Celant

🎲 A random map stays secret in embeds so bright,
Thumbnails switch to dice, spoilers out of sight,
Sliders park at center until players decide,
Prestart lifts the veil and reveals the ride,
Small code, quiet suspense — surprise on the other side.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: adding hidden random map support and adjusting nation count display.
Description check ✅ Passed The description clearly explains the problem, solution, and includes screenshots showing the UI changes for the random map feature.
Linked Issues check ✅ Passed All coding requirements from issue #3211 are met: randomMap flag added to GameConfig, preview embeds hide concrete map, nation count UI adjusted, server clears randomMap at prestart.
Out of Scope Changes check ✅ Passed All changes directly support the randomMap feature and issue #3211 requirements; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@resources/lang/en.json`:
- Line 522: Remove the duplicate "random" key in the "map" object so only a
single "random": "Random" remains; locate the repeated "random" entry in the
"map" section of resources/lang/en.json and delete the earlier occurrence (leave
the later declaration intact) to avoid duplicate JSON keys.

In `@src/client/components/LobbyPlayerView.ts`:
- Around line 89-95: The team preview still shows nation-derived counts even
when randomMap is true; update the render logic in LobbyPlayerView so any place
that uses effectiveNationCount-derived values (notably displayCount and
maxTeamSize used in the team preview) checks this.randomMap and instead renders
the masked placeholder (e.g., translateText("common.map_default") or the same
nation_players label) when randomMap is true; locate usages of displayCount and
maxTeamSize in the component (including the `${displayCount}/${maxTeamSize}`
expression) and replace them with conditional expressions that output the masked
text when this.randomMap is true.

In `@tests/server/GamePreviewRandomMap.test.ts`:
- Around line 20-58: Add a third test in GamePreviewRandomMap.test.ts to cover
the case where randomMap is omitted (undefined): create a test similar to the
"shows the concrete map for a normal lobby" one but call lobby({ gameMap:
"Europe", /* no randomMap */ gameType: "Private", gameMode: "FFA" }) when
invoking buildPreview, and assert that meta.image includes "europe"
(case-insensitive) and meta.title contains "Europe"; reference buildPreview and
lobby to locate where to add this new test case.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f8a60cf7-e859-41c1-bc98-8c9c423aa04c

📥 Commits

Reviewing files that changed from the base of the PR and between bf648a2 and d3212f8.

📒 Files selected for processing (14)
  • resources/lang/en.json
  • src/client/HostLobbyModal.ts
  • src/client/JoinLobbyModal.ts
  • src/client/SinglePlayerModal.ts
  • src/client/components/FluentSlider.ts
  • src/client/components/GameConfigSettings.ts
  • src/client/components/LobbyPlayerView.ts
  • src/core/Schemas.ts
  • src/server/GamePreviewBuilder.ts
  • src/server/GameServer.ts
  • tests/RandomMapConfig.test.ts
  • tests/client/components/FluentSlider.test.ts
  • tests/server/GameLifecycle.test.ts
  • tests/server/GamePreviewRandomMap.test.ts

Comment thread resources/lang/en.json Outdated
Comment thread src/client/components/LobbyPlayerView.ts
Comment thread tests/server/GamePreviewRandomMap.test.ts
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management Jun 4, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 4, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 4, 2026
Selecting "Random" still resolves a concrete map client-side (so nation
count and map loading work as today), but the choice now rides a
`randomMap` flag on GameConfig. While the flag is set, all pre-start
surfaces hide the concrete map so an invite link doesn't spoil it:

- Invite embed (GamePreviewBuilder): generic RandomMap.webp image and a
  "Random Map" title instead of the real thumbnail/name.
- Join screen + lobby player view: map shows "Random", and the nation
  count (which is per-map and would reveal the map) shows "Map default".
- Host's nation slider: FluentSlider gains `hideDefaultValue` so the
  default position reads "Map default" without the revealing number.

The server clears the flag at prestart, which reveals the (already
resolved) map everywhere with no downstream special-casing. Applies to
random lobbies only; concrete-map lobbies are unchanged.

Tests cover the schema round-trip, prestart clearing the flag,
updateGameConfig persisting it, and the embed hiding/showing the map.
Single-player uses the same game-config-settings nation slider, so pass
hideDefaultValue when Random is selected — otherwise the default position
shows the map's real nation count, revealing the randomly chosen map. No
embed/lobby surfaces exist for single-player, so this is the only change.
Hiding the nation count number wasn't enough: the slider thumb still sat
at value/max (the map's real nation count / 400), so the map could be
inferred from the thumb's position. When a slider is at a hidden default
(a Random lobby), render the thumb — and the fill bar and number editor —
at the track center instead. Dragging or typing still reports the real
input value, so the host can still override it.
Once you move a Random lobby's nation slider off the default, the real
default count is hidden, so there's no way to drag back to it. Add a
small "↺ Map default" reset button that appears only in that state
(hideDefaultValue + moved off default); clicking it restores the default
value, which re-parks the thumb at center and hides the button again.
- Remove the duplicate "map.random" en.json key (one already existed);
  reuse the existing entry for translateText("map.random").
- Close the nation-count leak in team mode: the masked header wasn't
  enough — team-card totals and team sizing also derive from the count.
  Make effectiveNationCount return 0 for random lobbies so nothing
  nation-derived reveals the map, and recompute the team preview when the
  randomMap flag flips.
- Add a buildPreview test for randomMap omitted entirely (the common
  normal-lobby case, since the field is optional).
- Add docstrings to the functions touched by this change to satisfy the
  docstring-coverage threshold.
Add docstrings to willUpdate (LobbyPlayerView) and the lobby() test
helper, the two functions in the latest changes that were still
undocumented.
Add a docstring to the cdnBase mock arrow in the preview test — the last
function the coverage scanner flagged.
@noahschmal noahschmal force-pushed the feature/random-map-hidden branch from 385ccd1 to dda3404 Compare June 8, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development

Development

Successfully merging this pull request may close these issues.

Randomized map spoiled in embed of lobby invite link

1 participant