-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Scheduler Implementation for Pause and Resume Mechanic (FM-806) #1897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
…udio from pausable
# Conflicts: # src/components/prompt-text/prompt-text.ts # src/components/timer-ticking.ts
…er starts. (FM-817)
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
Note
|
| Cohort / File(s) | Summary |
|---|---|
Version & Public Assets public/index.html |
Bumps version from v1.3.1 to v1.3.2 in version-info elements and fixes trailing newline. |
New Scheduler Service src/services/scheduler.ts |
Adds delta-time-based scheduler for managing one-shot and repeating callbacks via setTimeout/setInterval equivalents; exported as singleton instance. |
Event System & Utilities src/events/index.ts, src/common/utils.ts, src/common/index.ts |
Removes EventManager class; adds unsubscribeAll utility function to bulk-invoke cleanup callbacks; exports unsubscribeAll from common module. |
GameState Service Enhancement src/gameStateService/gameStateService.ts |
Exposes LOADPUZZLE and STONEDROP event identifiers in the EVENTS interface; enables gameStateService subscriptions for core game events. |
Audio System Enhancements src/components/audio-player.ts, src/components/__mocks__/audio-player.ts |
Introduces non-pausable AudioContext, playUIAudio method (with volume/onEnded support), pauseAllAudios/resumeAllAudios methods; uses scheduler for prompt audio; adds mock methods. |
Core Animation Timing src/common/stone-config/stone-config.ts, src/common/stone-config/stone-config.spec.ts |
Changes draw signature from draw(shouldResize) to draw(deltaTime, shouldResize); replaces elapsed-time calculation with frame-based progress; adds isAnimating getter; updates test calls. |
Event-Driven Component Refactoring src/components/level-indicator/level-indicator.ts, src/components/level-indicator/level-indicator.spec.ts |
Removes EventManager inheritance; replaces with gameStateService.subscribe; stores unsubscribe function; updates tests to use subscription callbacks and verify cleanup. |
Prompt Text & Animation src/components/prompt-text/prompt-text.ts, src/components/prompt-text/prompt-text.spec.ts, src/components/prompt-text/prompt-text.scss |
Replaces EventManager with gameStateService subscriptions; uses scheduler.setTimeout; introduces handleGamePause for pause class toggling; adds paused animation-play-state CSS; updates test mocks. |
Stone Handler Refactoring src/components/stone-handler/stone-handler.ts, src/components/stone-handler/stone-handler.spec.ts |
Removes EventManager inheritance; uses gameStateService subscriptions; draw(deltaTime) now accepts and forwards deltaTime to stones; drawWordPuzzleLetters signature updated; uses unsubscribeAll for cleanup. |
Timer & Animation Components src/components/timer-ticking.ts, src/components/timerHtml/timerHtml.spec.ts, src/components/riveComponent/rive-component.ts |
TimerTicking removes EventManager, uses scheduler and gameStateService subscriptions; TimerHtml tests use scheduler.update; RiveComponent gains pause()/resume() methods. |
Monster & Mini-Game Refactoring src/components/riveMonster/rive-monster-component.ts, src/miniGame/miniGames/miniGameHandler.ts, src/miniGame/miniGames/treasureChest/\\* |
RiveMonsterComponent removes hitbox logic; MiniGameHandler.draw() renamed to start() with new update(deltaTime); TreasureChest classes refactored to use deltaTime instead of timestamp-based animations. |
Pause Popup & UI src/components/popups/pause-popup/pause-popup-component.ts |
Replaces playAudio with playUIAudio; updates base handler invocation with explicit arguments for pause/resume handling. |
Feedback & Puzzle Handlers src/gamepuzzles/feedbackAudioHandler/feedbackAudioHandler.ts, src/gamepuzzles/puzzleHandler/puzzleHandler.ts |
Replace setTimeout with scheduler.setTimeout for timing delayed callbacks in audio feedback and letter-drop animations. |
Global API & Scene Setup src/feedTheMonster.ts, src/scenes/levelend-scene/levelend-scene.ts, src/scenes/progress-scene/progress-scene.ts |
Adds setupMonsterEvolutionStateAPI for global getMonsterEvolutionState access; LevelEndScene coerces currentLevel to number; ProgressionScene introduces newScoreEarned field. |
Tutorial Scheduler Integration src/tutorials/index.ts |
Replaces setTimeout/clearTimeout with scheduler equivalents; adjusts TimerId type; normalizes levelNumber extraction. |
New Gameplay Controllers & Managers src/scenes/gameplay-scene/monster-controller.ts, src/scenes/gameplay-scene/gameplay-input-manager.ts, src/scenes/gameplay-scene/gameplay-flow-manager.ts, src/scenes/gameplay-scene/gameplay-ui-manager.ts |
Introduces four new manager/controller classes: MonsterController (Rive animation & hitbox), GameplayInputManager (input event dispatch), GameplayFlowManager (puzzle progression & flow orchestration), GameplayUIManager (UI component lifecycle & events). |
GameplayScene Major Restructuring src/scenes/gameplay-scene/gameplay-scene.ts, src/scenes/gameplay-scene/gameplay-scene.spec.ts |
Replaces direct UI component properties with manager/controller instances; introduces dispose, pauseGamePlay, resumeGame, handleVisibilityChange, and UI event handlers; restructures initialization, draw loop, and event handling; updates all tests to use new mocks and scheduler; integrates flow manager for puzzle progression. |
Sequence Diagrams
sequenceDiagram
participant App as Application
participant GS as GameStateService
participant Comp as Component
participant Unsub as Unsubscribe Fn
Note over App,Unsub: OLD: EventManager-Based Pattern
App->>Comp: new Component(handler)
Comp->>Comp: super(handler)<br/>register callbacks
Comp->>Comp: addEventListener<br/>STONEDROP/LOADPUZZLE
Note over App,Unsub: NEW: Pub-Sub Service Pattern
App->>Comp: new Component()
Comp->>GS: subscribe(STONEDROP)
GS-->>Comp: Unsub Fn
Comp->>Comp: store unsubscribe
GS->>Comp: emit STONEDROP event
Comp->>Comp: handle event
App->>Comp: dispose()
Comp->>Unsub: invoke stored<br/>unsubscribe
sequenceDiagram
participant User as User Input
participant IM as GameplayInputManager
participant GS as GameStateService
participant FM as GameplayFlowManager
participant SH as StoneHandler
participant PH as PuzzleHandler
User->>IM: mouse click on stone
IM->>IM: pickStone()
IM->>GS: publish INPUT_DRAG_START
GS->>FM: event received
User->>IM: drag stone
IM->>SH: updateStonePosition()
IM->>GS: publish INPUT_STONE_DROP_ON_TARGET
GS->>FM: handleStoneDropResult()
FM->>PH: check answer
PH-->>FM: isCorrect
FM->>FM: determineNextStep()
FM->>SH: loadPuzzle()
sequenceDiagram
participant Sched as Scheduler
participant Anim as AnimationComponent
participant DrawLoop as Game Draw Loop
Note over Sched,DrawLoop: Delta-Time-Based Animation Flow
DrawLoop->>Sched: update(deltaTime)
Sched->>Sched: advance all timers
Sched->>Anim: callback() if ready
Anim->>Anim: state transition
DrawLoop->>Anim: draw(deltaTime)
Anim->>Anim: frame += deltaTime/frameDuration
Anim->>Anim: render based on frame progress
Estimated code review effort
🎯 5 (Critical) | ⏱️ ~120 minutes
This PR introduces an entirely new architectural layer (scheduler, four new manager/controller classes), refactors event handling across 15+ components from inheritance-based to pub-sub-based, changes timing mechanisms throughout the codebase from timestamp-based to delta-time-based, and substantially restructures GameplayScene. The complexity is heightened by the interdependencies between the new managers, the cascading refactors across event-driven components, and the integration with multiple subsystems (audio, animation, input, UI). Heterogeneous changes demand separate reasoning for each manager and component refactoring pattern.
Possibly related PRs
- Refactor Gameplay Scene (FM-799) #1883 — Modifies GameplayScene architecture and GameplayInputManager with overlapping input/scene refactors, directly related at code level.
- chore: Test to Production deployment #1847 — Modifies src/components/audio-player.ts with overlapping AudioPlayer enhancements (volume/onEnded support), related at audio subsystem level.
- Test to Production Deployment #1861 — Modifies src/scenes/gameplay-scene/gameplay-scene.ts initialization and audio asset preloading, related through shared GameplayScene restructuring.
Suggested reviewers
- bernhardccodev
- ashwinnair-chimple
- miguelccodev
Poem
🐰 A new scheduler hops in time,
Delta flows in perfect rhyme,
EventManager bids adieu,
Managers orchestrate anew,
Pub-sub threads the grand design,
Gameplay's gears align! ⚙️✨
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | 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 (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly and concisely summarizes the primary architectural change: implementing a Scheduler for pause/resume mechanics, which is reflected throughout the changeset (scheduler service added, integrated into gameplay components, timer/animation logic refactored). |
✏️ 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 @coderabbitai help to get the list of available commands and usage tips.
miguelccodev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments. Please have a look.
bernhardccodev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @janfb-codev looks good to me. I have reviewed it carefully and I am alright with the overall implementation.
I left some comments but it is more polishing and clean up and optional. Thanks!
Renamed clearTimeout to cancelTimeout Removed clearInterval since it is same with cancelTimeout Used cancelTimeout instead of manually deleting timer in update
src/miniGame/miniGames/treasureChest/treasureChestMiniGame.spec.ts
Outdated
Show resolved
Hide resolved
added a destroy on cleanup scene
Changes
How to test
Ref: FM-806
Summary by CodeRabbit
New Features
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.