Skip to content

Conversation

@092vk
Copy link
Member

@092vk 092vk commented Aug 23, 2025

Fixes #564

Describe the changes you have made in this PR -

  1. Added play/pause functionality
  2. Added UI button for Play/Pause in Properties table
  3. Added the space key as a shortcut to toggle the play/pause button
  4. Pause stops the engine, clock, and other circuit element updates.

Screenshots of the changes (If any) -

Screencast.from.08-23-2025.10.28.17.PM.webm

Note: Please check Allow edits from maintainers. if you would like us to assist in the PR.

Summary by CodeRabbit

  • New Features

    • Play/Pause control added to Project settings.
    • Spacebar shortcut to toggle Play/Pause.
  • Improvements

    • Simulation processing stops completely when paused.
    • Resuming playback triggers an immediate canvas update for smoother visual feedback.

@netlify
Copy link

netlify bot commented Aug 23, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 183bd27
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/68ab387affe6360008756eec
😎 Deploy Preview https://deploy-preview-644--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 35 (🔴 down 10 from production)
Accessibility: 73 (no change from production)
Best Practices: 92 (no change from production)
SEO: 82 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 23, 2025

Walkthrough

Adds a simulationPlaying boolean, UI play/pause checkbox, keyboard space toggle, toggleSimulationPlaying() utility, and runtime guards that prevent clock ticks and play() execution when simulationPlaying is false.

Changes

Cohort / File(s) Summary
UI control: Play/Pause toggle
src/components/Panels/PropertiesPanel/ModuleProperty/ProjectProperty/ProjectProperty.vue
Inserts a switch/checkbox bound to simulationArea.simulationPlaying and calls toggleSimulationPlaying on change.
Simulation state: interface & init
src/simulator/src/interface/simulationArea.ts, src/simulator/src/simulationArea.ts
Adds simulationPlaying: boolean to the SimulationArea interface and initializes simulationPlaying: true on the exported simulationArea object.
Playback utilities
src/simulator/src/utils.ts
Adds exported toggleSimulationPlaying() which flips simulationArea.simulationPlaying, calls updateCanvasSet(true) and scheduleUpdate(1) when resuming; clockTick now returns early if simulationPlaying is false.
Engine gating
src/simulator/src/engine.js
Adds early-return guard in play() to exit when simulationArea.simulationPlaying is false.
Keyboard shortcut
src/simulator/src/listeners.js
Imports toggleSimulationPlaying and maps Space (keyCode 32) to call it, preventing default and returning early after toggle.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Add play/pause control to the simulator (#564)

Suggested reviewers

  • Arnabdaz

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4e12cbc and 6963b4a.

📒 Files selected for processing (1)
  • src/simulator/src/listeners.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/simulator/src/listeners.js
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/simulator/src/engine.js (2)

404-410: Paused guard should also flush the simulation queue to match “discard queued updates” promise

Right now, play() returns before clearing pending work. This will let already-queued resolves run immediately after resuming, contradicting the PR description (“including updates already queued”). Reset the queue before returning while paused.

Apply this diff:

     if (errorDetected) return // Don't simulate until error is fixed
     if (loading === true) return // Don't simulate until loaded
-    if (!simulationArea.simulationPlaying) return // Don't simulate when paused
+    // Don't simulate when paused — also discard any pending work as per PR requirements
+    if (!simulationArea.simulationPlaying) {
+        simulationArea.simulationQueue.reset()
+        return
+    }

549-571: Resume may no-op: update() clears updateSimulation even when paused

update() unconditionally sets updateSimulation=false after calling play(). If the app is paused, play() exits early and we still clear the flag. Toggling Play back on (per current summary) only schedules an update; it doesn’t guarantee updateSimulation becomes true again, so the simulation may not actually resume.

Gate clearing the flag behind an actual simulation run.

Apply this diff:

-    if (updateSimulation) {
-        play()
-    }
+    const didSimulate = updateSimulation && simulationArea.simulationPlaying
+    if (didSimulate) {
+        play()
+    }
@@
-    updateSimulationSet(false)
+    if (didSimulate) updateSimulationSet(false)

Follow-up (alternative/complement outside this file):

  • When turning Play on, explicitly set updateSimulationSet(true) in toggleSimulationPlaying().
  • When turning Play off, also clear the queue there for consistency with the behavior added above.

Example (in utils.ts):

export function toggleSimulationPlaying() {
  simulationArea.simulationPlaying = !simulationArea.simulationPlaying;
  if (simulationArea.simulationPlaying) {
    updateSimulationSet(true);
    scheduleUpdate(1);
  } else {
    simulationArea.simulationQueue.reset();
  }
  updateCanvasSet(true);
}
🧹 Nitpick comments (2)
src/simulator/src/interface/simulationArea.ts (1)

9-9: New playback state flag looks good; clarify interplay with clockEnabled.

Adding simulationPlaying: boolean is a clean, minimally invasive way to gate simulation. Consider documenting how it differs from and composes with clockEnabled (e.g., both must be true to tick), so future contributors don’t conflate the two.

src/components/Panels/PropertiesPanel/ModuleProperty/ProjectProperty/ProjectProperty.vue (1)

39-51: UI toggle works; consider controlled update flow and a11y label.

Current pattern uses :checked bound to state and @change to toggle. It works, but two refinements help:

  • Accessibility: add an explicit label for screen readers.
  • Optional: move from “toggle on change” to an idempotent setter, so alternate callers (keyboard, future APIs) can pass a desired state without guessing.

Minimal improvement (adds ARIA without changing behavior):

             <input
                 type="checkbox"
                 class="objectPropertyAttributeChecked"
                 name="changeSimulationPlaying"
                 :checked="simulationArea.simulationPlaying"
-                @change="toggleSimulationPlaying"
+                aria-label="Play or pause the simulation"
+                title="Play/Pause (Space)"
+                @change="toggleSimulationPlaying"
             />

Optional refactor (if you introduce setSimulationPlaying(next: boolean) in utils):

  • Bind :checked="simulationArea.simulationPlaying"
  • Replace handler with @change="(e) => setSimulationPlaying((e.target as HTMLInputElement).checked)"

This avoids accidental double-toggles if other code also flips the flag.

Also applies to: 121-121

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7b1f11f and 4e12cbc.

📒 Files selected for processing (6)
  • src/components/Panels/PropertiesPanel/ModuleProperty/ProjectProperty/ProjectProperty.vue (2 hunks)
  • src/simulator/src/engine.js (1 hunks)
  • src/simulator/src/interface/simulationArea.ts (1 hunks)
  • src/simulator/src/listeners.js (2 hunks)
  • src/simulator/src/simulationArea.ts (1 hunks)
  • src/simulator/src/utils.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/simulator/src/engine.js (2)
src/simulator/src/simulationArea.ts (2)
  • simulationArea (70-70)
  • simulationArea (71-71)
src/simulator/src/embedListeners.js (1)
  • simulationArea (104-104)
src/simulator/src/utils.ts (1)
src/simulator/src/engine.js (2)
  • updateCanvasSet (114-116)
  • scheduleUpdate (466-485)
src/simulator/src/listeners.js (1)
src/simulator/src/utils.ts (1)
  • toggleSimulationPlaying (54-61)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
src/simulator/src/utils.ts (1)

44-45: Correct early-return to pause clock ticks.

The extra guard in clockTick() cleanly halts ticks while paused without affecting layout mode or error handling. Nice.

src/simulator/src/simulationArea.ts (1)

12-12: Good default: start in playing state.

Initializing simulationPlaying: true aligns with current simulator behavior (auto-running after load). If you adopt interval clearing on pause, ensure setup() or resume flow re-arms the clock via changeClockTime(timePeriod).

Please verify resume after page load and after toggling pause→play still ticks by confirming ClockInterval is non-null and increasing cycles.

src/simulator/src/engine.js (1)

404-407: Simulation resume, space‐key handling, and clockTick guards verified—no changes needed

  • toggleSimulationPlaying (src/simulator/src/utils.ts: lines 54–59) flips simulationArea.simulationPlaying and immediately calls scheduleUpdate(1), so resuming never “sticks.”
  • Space key handler (src/simulator/src/listeners.js: lines 563–567) invokes toggleSimulationPlaying() then e.preventDefault(), correctly suppressing scrolling.
  • clockTick (src/simulator/src/utils.ts: lines 1–8) early-returns when simulationPlaying is false, so no further scheduleUpdate calls fire while paused.

Copy link
Member

@niladrix719 niladrix719 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add v-model

Comment on lines +46 to +48
:checked="simulationArea.simulationPlaying"
@change="toggleSimulationPlaying"
/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add v-model here

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.

Adding the play/pause button to the simulator

2 participants