Refactor Registry.kt with Polymorphic Behavior Model - #153
Conversation
- Introduced `StallBehavior` and `EnemyBehavior` interfaces to encapsulate specific logic. - Implemented `DefaultStallBehavior` and `DefaultEnemyBehavior` classes. - Created specialized behavior classes for each stall and enemy type (e.g., `SatayStallBehavior`, `TouristEnemyBehavior`). - Updated `StallDefinition` and `EnemyDefinition` to delegate logic to their behaviors, eliminating large `when` blocks. - Updated `StallRegistry` and `EnemyRegistry` to instantiate and pass the appropriate behaviors. - Simplified `MainViewModel.kt` to use the updated behavior-based API. - Recorded the refactor in `fixes.md` with ID `REF-007`. 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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR refactors stall and enemy combat behavior from type-based conditional logic into a polymorphic strategy pattern, introducing ChangesBehavior Strategy Pattern and Registry Refactor
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)
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 |
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 50b7d86f-07b1-434d-8cbb-ce3d86fa954f
📒 Files selected for processing (3)
app/src/main/java/com/messark/hawker/MainViewModel.ktapp/src/main/java/com/messark/hawker/registry/Registry.ktfixes.md
|
Initialize Tourist lastStopMs at spawn time to prevent immediate stall. The Enemy model defaults lastStopMs to 0L, and EnemyRegistry.toEnemy() does not override this. When a Tourist spawns at any time after ~8 seconds, the condition on line 203 (currentTimeMs - lastStopMs > 8000) evaluates true immediately, causing the tourist to stall on its first update tick. Initialize lastStopMs = currentTimeMs when spawning tourists, or set it on first behavior update. |
Great catch! I've updated |
…PR feedback - Introduced `StallBehavior` and `EnemyBehavior` interfaces to encapsulate specific logic. - Implemented `DefaultStallBehavior` and `DefaultEnemyBehavior` classes. - Created specialized behavior classes for each stall and enemy type. - Updated `StallDefinition` and `EnemyDefinition` to delegate logic to their behaviors. - Updated registries to assign these behaviors. - Fixed Tourist stalling bug by initializing `lastStopMs` in `TouristEnemyBehavior`. - Simplified `MainViewModel.kt` to use the updated behavior-based API. - Recorded the refactor in `fixes.md` with ID `REF-007`. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
This refactoring replaces a conditional-heavy architecture with a polymorphic behavior model in
Registry.kt. It improves code maintainability and follows clean coding principles by delegating type-specific logic to specialized behavior classes.PR created automatically by Jules for task 9736991352443048903 started by @candour
Summary by CodeRabbit
Bug Fixes
Refactor
Documentation