Refactor Stall and Enemy Registries - #67
Conversation
Consolidated scattered data and behavioral logic for stalls and enemies into StallRegistry and EnemyRegistry. - Moved base stats, costs, and descriptions to registries. - Relocated behavioral logic (firing, damage modifiers, special behaviors) to registry definitions. - Centralized sprite coordinate mapping. - Simplified MainViewModel, UI components, and tests by delegating to registries. - Fixed a bug where Satay's fire rate was ignored due to rotation updates. - Ensured weapons.png asset is preserved. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
📝 WalkthroughWalkthroughThis PR introduces centralized registry infrastructure for stalls and enemies, migrating from hardcoded configurations and scattered constant maps to registry-based lookups. A new Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (7)
app/src/main/java/com/messark/hawkerrush/ui/components/StallSlot.kt (1)
53-55: Avoid allocatingColorMatrix/ColorFilterinside the draw path.This creates new objects during rendering. Cache the disabled filter once per composition.
♻️ Suggested refactor
fun StallSlot( @@ ) { val spriteRect = StallRegistry.get(stall.stallType).spriteRect + val disabledColorFilter = ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(0f) }) @@ drawImage( @@ - colorFilter = if (!canAfford) { - ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(0f) }) - } else null + colorFilter = if (!canAfford) disabledColorFilter else null )app/src/main/java/com/messark/hawkerrush/ui/components/GameControlPanel.kt (1)
11-12: Unused import:ButtonDefaults.The
Buttoncomposable was replaced withSpriteButton, but theButtonDefaultsimport remains. This import is no longer needed.🧹 Remove unused import
import androidx.compose.material3.Button -import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Textapp/src/main/java/com/messark/hawkerrush/MainViewModel.kt (2)
361-376: Consider simplifying by usingbehaviorUpdatedEnemydirectly.The code extracts
isStopped,stopDurationMs, andlastStopMsfrombehaviorUpdatedEnemybut then doesn't usebehaviorUpdatedEnemyitself. SinceupdateSpecialBehaviorreturns the updated enemy, you could use it more directly to reduce redundancy.
400-402: Redundant parameter ingetPuddleSlowMultipliercall.
enemyDefis retrieved viaEnemyRegistry.get(enemy.type), soenemyDef.typealready equalsenemy.type. ThegetPuddleSlowMultipliermethod takes the enemy type as a parameter, but it should instead use its owntypefield internally. See related comment onRegistry.kt.app/src/main/java/com/messark/hawkerrush/registry/Registry.kt (3)
189-199: Use explicit locale for consistent number formatting.
String.formatuses the implicit default locale, which may cause inconsistent decimal separators (e.g., "1.5" vs "1,5") across different user locales. For UI consistency in a game, use an explicit locale.🌐 Use explicit Locale for formatting
+import java.util.Locale + // In getUpgradeBenefit function: "Range" -> { // ... - "+${String.format("%.1f", currentRange - baseStall.range)}" + "+${String.format(Locale.US, "%.1f", currentRange - baseStall.range)}" } "Radius" -> { // ... - "+${String.format("%.1f", currentRadius - baseStall.aoeRadius)}" + "+${String.format(Locale.US, "%.1f", currentRadius - baseStall.aoeRadius)}" }
235-241: Parameter is redundant; method should use instancetypefield.
getPuddleSlowMultipliertakesenemyTypeas a parameter, but it's called on anEnemyDefinitionthat was already retrieved for that specific enemy type. The method should usethis.typeinstead, consistent withupdateSpecialBehaviorwhich uses the instance field.♻️ Remove redundant parameter
- fun getPuddleSlowMultiplier(enemyType: EnemyType): Float { - return when (enemyType) { + fun getPuddleSlowMultiplier(): Float { + return when (type) { EnemyType.DELIVERY_RIDER -> 0.2f EnemyType.AUNTIE -> 0.8f else -> 0.6f } }Then update the call site in
MainViewModel.kt:- speedMultiplier = enemyDef.getPuddleSlowMultiplier(enemy.type) + speedMultiplier = enemyDef.getPuddleSlowMultiplier()
371-372: All enum values are covered; consider adding validation to prevent future regressions.Both
StallRegistry.get()andEnemyRegistry.get()currently use non-null assertions (!!), and verification confirms all enum values have entries: StallType has 5 values (TEH_TARIK, SATAY, CHICKEN_RICE, DURIAN, ICE_KACHANG) all mapped at lines 288–354, and EnemyType has 4 values (SALARYMAN, TOURIST, AUNTIE, DELIVERY_RIDER) all mapped at lines 377–404. The code is safe today, but consider adding init-time validation to catch missing entries early if new enum values are added.Also applies to: 415-416
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d1f7d3eb-061c-455f-b6ec-a80426fc57cf
⛔ Files ignored due to path filters (1)
app/src/main/res/drawable-nodpi/weapons.pngis excluded by!**/*.png
📒 Files selected for processing (12)
app/src/main/java/com/messark/hawkerrush/MainActivity.ktapp/src/main/java/com/messark/hawkerrush/MainViewModel.ktapp/src/main/java/com/messark/hawkerrush/model/GameModels.ktapp/src/main/java/com/messark/hawkerrush/model/TutorialModels.ktapp/src/main/java/com/messark/hawkerrush/registry/Registry.ktapp/src/main/java/com/messark/hawkerrush/ui/components/GameBoard.ktapp/src/main/java/com/messark/hawkerrush/ui/components/GameControlPanel.ktapp/src/main/java/com/messark/hawkerrush/ui/components/StallConsole.ktapp/src/main/java/com/messark/hawkerrush/ui/components/StallSlot.ktapp/src/main/java/com/messark/hawkerrush/ui/components/TutorialOverlay.ktapp/src/main/java/com/messark/hawkerrush/ui/constants/SpriteConstants.ktapp/src/test/java/com/messark/hawkerrush/MilestoneBoostTest.kt
💤 Files with no reviewable changes (1)
- app/src/main/java/com/messark/hawkerrush/model/TutorialModels.kt
Consolidated scattered data and behavioral logic for stalls and enemies into StallRegistry and EnemyRegistry. - Moved base stats, costs, and descriptions to registries. - Relocated behavioral logic (firing, damage modifiers, special behaviors) to registry definitions. - Centralized sprite coordinate mapping. - Simplified MainViewModel, UI components, and tests by delegating to registries. - Fixed a bug where Satay's fire rate was ignored due to rotation updates. - Rebasing on main to ensure no merge conflicts. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
Refactored the codebase to centralize stall and enemy definitions, stats, and behavioral logic into a new registry system. This improves maintainability by eliminating scattered hardcoded data and logic. Key improvements include modularizing firing mechanics, damage modifiers, and upgrade calculations, as well as fixing a critical firing rate bug for the Satay stall.
PR created automatically by Jules for task 10904571682745949244 started by @candour
Summary by CodeRabbit
Release Notes
New Features
UI Improvements
Refactor