Starting gold input in millions with decimal support ✨#3349
Conversation
WalkthroughRefactored starting gold input handling across game lobby interfaces. Changed UI representation from raw numbers to millions-based input (placeholder "5" represents 5 million). Added float-based validation (0.1–1000), server-side scaling by 1,000,000, and formatted display values for game modifiers. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/client/Utils.ts (1)
155-166: Consider centralizing million-scale conversion in one helper.This logic is now duplicated across
Utils.ts,HostLobbyModal.ts, andSinglePlayerModal.ts. A shared helper would reduce drift risk (rounding, precision, suffix formatting).♻️ Suggested direction
+// utilities/GameConfigHelpers.ts +export const MILLION = 1_000_000; + +export function toMillions(rawGold: number): number { + return parseFloat((rawGold / MILLION).toPrecision(12)); +} + +export function fromMillions(millions: number): number { + return Math.round(millions * MILLION); +}-const millions = parseFloat((modifiers.startingGold / 1_000_000).toPrecision(12)); +const millions = toMillions(modifiers.startingGold);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/client/Utils.ts` around lines 155 - 166, Extract the repeated million-scale conversion into a single helper (e.g., formatMillions or toMillions) and replace the inline logic in Utils.ts, HostLobbyModal.ts, and SinglePlayerModal.ts with calls to that helper; the helper should take the raw numeric value (startingGold), compute the millions using the same parseFloat((value/1_000_000).toPrecision(12)) logic, and return both the numeric millions and the formatted string with an "M" suffix so labelKey/badgeParams/value/formattedValue remain consistent across uses; update the three call sites to use the helper (ensuring they consume {millions, formatted} or similar) and add a small unit test or comment to lock the rounding/precision behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/client/HostLobbyModal.ts`:
- Around line 649-660: The UI clears startingGoldValue to undefined which causes
putGameConfig() to omit updates and leave a stale server value; when
parseBoundedFloatFromInput returns invalid/empty, set startingGoldValue to an
explicit clear marker (e.g. null) and ensure putGameConfig() sends that explicit
clear to the server (include startingGold: null or an explicit clear flag in the
payload) so the server apply path will remove the previous value; update the
handling in HostLobbyModal (the parseBoundedFloatFromInput branch and the
symmetric code around lines ~791-793) and adjust putGameConfig() to serialize
the explicit clear marker for startingGold.
In `@src/client/SinglePlayerModal.ts`:
- Around line 594-605: The UI allows the "starting gold" toggle to be on while
the parsed input becomes undefined, which causes the payload to omit
startingGold and the game to default to 0; update the logic so before starting
the game (e.g., in the start handler / method that builds the payload) you check
if the toggle/flag for starting gold is enabled and this.startingGoldValue is
undefined, and then either (a) block the start and surface validation (disable
the start button / show an error) or (b) restore a last-known-good value by
storing lastValidStartingGold when parseBoundedFloatFromInput returns a number
and reassigning it when value === undefined; ensure the check references the
existing symbols this.startingGoldValue, the input parsing code that uses
parseBoundedFloatFromInput, and the start/send-payload routine so no payload is
sent with an enabled-but-undefined startingGold.
---
Nitpick comments:
In `@src/client/Utils.ts`:
- Around line 155-166: Extract the repeated million-scale conversion into a
single helper (e.g., formatMillions or toMillions) and replace the inline logic
in Utils.ts, HostLobbyModal.ts, and SinglePlayerModal.ts with calls to that
helper; the helper should take the raw numeric value (startingGold), compute the
millions using the same parseFloat((value/1_000_000).toPrecision(12)) logic, and
return both the numeric millions and the formatted string with an "M" suffix so
labelKey/badgeParams/value/formattedValue remain consistent across uses; update
the three call sites to use the helper (ensuring they consume {millions,
formatted} or similar) and add a small unit test or comment to lock the
rounding/precision behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3b741003-e53d-4e83-9e8a-bbede73ad4d4
📒 Files selected for processing (5)
resources/lang/en.jsonsrc/client/HostLobbyModal.tssrc/client/JoinLobbyModal.tssrc/client/SinglePlayerModal.tssrc/client/Utils.ts
Description:
Starting gold input: use millions
Changes the starting gold input in singleplayer and host lobby modals to accept values in millions (e.g. enter
5for 5M gold). Supports decimals like6.6for 6.6M. The value is multiplied by 1,000,000 before being sent to the game config.Previous
Now
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
FloPinguin