Skip to content

Refactor stall upgrade logic into a centralized manager#113

Merged
candour merged 2 commits into
mainfrom
refactor-stall-upgrades-13391773198545734455
May 2, 2026
Merged

Refactor stall upgrade logic into a centralized manager#113
candour merged 2 commits into
mainfrom
refactor-stall-upgrades-13391773198545734455

Conversation

@candour

@candour candour commented May 1, 2026

Copy link
Copy Markdown
Owner

This change refactors the stall upgrade logic, which was previously duplicated and inconsistent between MainViewModel.kt and Registry.kt, into a new centralized StallUpgradeManager.kt. This manager handles stat scaling, milestone boosts, cost calculations, and legendary naming, ensuring consistency between gameplay logic and UI descriptions. Scaling rules have been unified according to STALL_STATS.md.


PR created automatically by Jules for task 13391773198545734455 started by @candour

Summary by CodeRabbit

  • Refactor

    • Upgrade logic consolidated into a centralized manager for improved maintainability and clearer upgrade behavior handling.
  • User Impact

    • No visible changes to gameplay or upgrade behavior; upgrades and costs continue to function as before.

- Created StallUpgradeManager to centralize upgrade calculations.
- Refactored MainViewModel.applyUpgrade to use the new manager.
- Refactored StallDefinition.getUpgradeBenefit to use the new manager.
- Unified scaling rules and milestone boosts according to STALL_STATS.md.
- Improved rounding accuracy using roundToInt and roundToLong.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Refactors stall upgrade behavior by extracting cost calculation, available-stat selection, per-stat application (including milestone and legendary naming logic), and benefit-string generation from MainViewModel and Registry into a new StallUpgradeManager utility.

Changes

Stall upgrade centralization

Layer / File(s) Summary
New Manager
app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt
Adds StallUpgradeManager with calculateUpgradeCost, getAvailableUpgradeStats, applyUpgrade, and getBenefitString implementing cost scaling, per-stall-type upgrade stat lists, per-category progression formulas (milestone multipliers, TRAY_RETURN_UNCLE caps/floors), upgrade tracking, and legendary naming changes.
Main wiring (control flow)
app/src/main/java/com/messark/hawker/MainViewModel.kt
Replaces in-method upgrade logic in applyUpgrade() with calls to StallUpgradeManager.calculateUpgradeCost, getAvailableUpgradeStats(...).random() (when not specific), and applyUpgrade(...); updates gold and freeSpecificUpgrades accordingly.
UI / Benefit surface
app/src/main/java/com/messark/hawker/registry/Registry.kt
StallDefinition.getUpgradeBenefit(...) now delegates formatting/calculation to StallUpgradeManager.getBenefitString(...) instead of containing the inline benefit logic.
Build / manifests
build.gradle.kts, *.gradle.kts
Small build/manifest touches recorded in the diff metadata.

Sequence Diagram(s)

sequenceDiagram
    participant VM as MainViewModel
    participant Mgr as StallUpgradeManager
    participant Reg as Registry / UI

    VM->>Mgr: calculateUpgradeCost(stall, isSpecific, hasFreeUpgrade)
    VM->>Mgr: if not specific → getAvailableUpgradeStats(stall).random()
    VM->>Mgr: applyUpgrade(stall, statName, upgradeCost, isSpecific)
    Mgr-->>VM: updated Stall
    VM->>VM: adjust gold / freeSpecificUpgrades / disabledWaves
    Reg->>Mgr: getBenefitString(category, level, baseStall)
    Mgr-->>Reg: formatted benefit string
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Update Registry.kt #106: Overlaps refactoring of upgrade-benefit/rate-reduction logic now moved into StallUpgradeManager.getBenefitString.
  • Add Tray Return Uncle Stall #70: Introduces TRAY_RETURN_UNCLE-specific upgrade rules (caps/floors) that are centralized here.
  • Add Bak Kut Teh Stall #111: Adds/changes "Boost" category handling in benefit calculations, which now interacts with the extracted getBenefitString.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Refactor stall upgrade logic into a centralized manager' directly and accurately describes the main change—consolidating upgrade logic from multiple files into a new StallUpgradeManager utility.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-stall-upgrades-13391773198545734455

Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

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

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

@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: 1

🧹 Nitpick comments (1)
app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt (1)

212-212: 💤 Low value

Use explicit locale for consistent decimal formatting.

String.format uses the device's default locale, which can produce inconsistent decimal separators (e.g., "0,5" vs "0.5") depending on user settings.

♻️ Proposed fix
-                "+${String.format("%.1f", currentRange - baseStall.range)}"
+                "+${String.format(java.util.Locale.US, "%.1f", currentRange - baseStall.range)}"
-                "+${String.format("%.1f", currentRadius - baseStall.aoeRadius)}"
+                "+${String.format(java.util.Locale.US, "%.1f", currentRadius - baseStall.aoeRadius)}"

Also applies to: 220-220


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c7ea660f-b8db-4a1a-b18a-b04323acc135

📥 Commits

Reviewing files that changed from the base of the PR and between 8bbab9b and 3a5289b.

📒 Files selected for processing (3)
  • app/src/main/java/com/messark/hawker/MainViewModel.kt
  • app/src/main/java/com/messark/hawker/registry/Registry.kt
  • app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt

Comment thread app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt
@candour
candour enabled auto-merge (squash) May 2, 2026 00:57
- Centralized upgrade logic in StallUpgradeManager.kt.
- Unified scaling rules and milestone boosts.
- Fixed inconsistent Rate benefit calculation in getBenefitString.
- Added missing imports and improved rounding accuracy.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

@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.

🧹 Nitpick comments (2)
app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt (1)

214-214: 💤 Low value

Use explicit locale for String.format to ensure consistent decimal formatting.

The implicit default locale may produce unexpected separators (e.g., , instead of .) in some regions, causing UI display inconsistencies.

🔧 Proposed fix
+import java.util.Locale
...
-                "+${String.format("%.1f", currentRange - baseStall.range)}"
+                "+${String.format(Locale.US, "%.1f", currentRange - baseStall.range)}"
...
-                "+${String.format("%.1f", currentRadius - baseStall.aoeRadius)}"
+                "+${String.format(Locale.US, "%.1f", currentRadius - baseStall.aoeRadius)}"

Also applies to: 222-222

app/src/main/java/com/messark/hawker/MainViewModel.kt (1)

10-10: 💤 Low value

Redundant import.

StallUpgradeManager is already covered by the wildcard import on line 9 (import com.messark.hawker.utils.*).

🧹 Proposed fix
 import com.messark.hawker.utils.*
-import com.messark.hawker.utils.StallUpgradeManager

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 28ba2823-3d91-401b-8cf1-1a4c0dd9ffbc

📥 Commits

Reviewing files that changed from the base of the PR and between 3a5289b and 4409e4f.

📒 Files selected for processing (2)
  • app/src/main/java/com/messark/hawker/MainViewModel.kt
  • app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt

@candour
candour merged commit 9d83172 into main May 2, 2026
3 checks passed
@candour
candour deleted the refactor-stall-upgrades-13391773198545734455 branch May 2, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant