Skip to content

Monitor save & load #1686

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

Merged
merged 8 commits into from
Nov 14, 2018
Merged

Conversation

kchadha
Copy link
Contributor

@kchadha kchadha commented Oct 21, 2018

Resolves

Resolves #1501, monitor save/load, also mentioned in scratchfoundation/scratch-gui#3086

Proposed Changes

  • Serialize monitor information when saving a project.
  • Deserialize monitor information when loading an sb3 (this adds a new monitor record to the runtime monitor state and either
    • finds and augments the corresponding monitor block in the monitor block container to set the isMonitored and targetId properties), or
    • creates a new monitor block for the monitor
  • Changes monitor color for extension monitors from the data category color to the extension color.

Known Issues

  • Imported variable monitors and monitors with parameters in the reporter don't display the correct checkbox state in the toolbox when the project is loaded. For variable monitors, the toolbox state becomes in-sync again after switching to a different sprite or tab causing the workspace and toolbox to reload.
  • For the monitors where the reporter has a parameter, switching sprites causes the checkbox in the toolbox to become unchecked (this is a remnant issue from Multi monitors #1742).
  • Monitor information is not currently serialized when exporting a sprite. This was left out of this PR because there is currently still a problem with variables retaining their IDs when serialized and thus importing a sprite3 with local variables (and monitors) back into the project it was exported from causes the local variable IDs to no longer be unique. This creates confusion with the local variable monitors because the monitor block is identified by the variable ID (thus two variables share the same monitor and cannot be displayed at the same time).
  • Monitors that are placed close to the right hand side of the stage, sometimes wrap when the project is saved and loaded.

Reason for Changes

Monitors should get saved and loaded in sb3s.

Test Coverage

Manual testing along with scratchfoundation/scratch-gui#3713.

Testing branch: https://llk.github.io/scratch-gui/monitors/

Added integration test monitor save/load, below is a screenshot of the stage in the fixture project added for this integration test:

integration-test-screenshot

Ensure the following:

  • Can still import monitors from 2.0 projects
  • Stage monitors like loudness and timer load correctly, (are visible, not empty, and update)
  • Imported monitors retain position and mode, list monitors retain height and width
  • Can save and load monitors in .sb3 projects. Monitors should load correctly and should update with changes to their values.
  • Test that non-visible monitors are saved/loaded correctly. E.g. check a monitor, move it somewhere and change its mode, hide the monitor, and then save the project. Check that the monitor is still hidden when that project is uploaded, and that when you show the monitor, it retained its new position and mode.

Related PRs

cc/ @picklesrus

Copy link
Contributor

@paulkaplan paulkaplan left a comment

Choose a reason for hiding this comment

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

Looks like we should add an integration test for loading sb3 files saved with monitors, to parallel the one testing loading sb2 files with monitors

}
// In the case where a monitor block does not already exist, one will get created
// when the target is installed because the toolbox will reload.

This comment was marked as abuse.

@kchadha
Copy link
Contributor Author

kchadha commented Oct 23, 2018

As discussed offline, it looks like this approach of using the monitor block from the runtime monitorBlocks container is not going to work after all since we won't always have monitorBlock information when we need it. In player mode (thus also on the preview page), the toolbox doesn't get loaded when the project does, so the monitorBlocks container does not get populated and monitors appear empty when a project is loaded.

Possible Solutions for The Future™️

  • Extension-ify just the monitor blocks (is this possible)? Specifically they have a handy json serialization function and a minimal specification
  • SB3 -> SB3 specmap (for just the monitor blocks?). Extension monitors would still use their json serialization function
  • Serialize the actual monitor blocks as well as the monitor record in the sb3. We would need to check how much this ends up bloating the file size.

@kchadha
Copy link
Contributor Author

kchadha commented Oct 23, 2018

Closing this until I can come back to it in the future.

@kchadha kchadha closed this Oct 23, 2018
@kchadha kchadha reopened this Nov 8, 2018
@kchadha kchadha force-pushed the monitor-save-load branch 2 times, most recently from 7a9f583 to 08f07fd Compare November 8, 2018 20:00
…from runtime. Fix issue where stage monitors weren't getting loaded correctly.
…y be 0 (e.g. a monitor placed in the top right corner of the stage) does not result in the monitor being treated as a new monitor and get auto-positioned.
…created when the toolbox is loaded. This approach does not work when viewing the project detached from scratch-blocks (e.g. player mode).
…ary when the monitor is the only part of the project that uses the extension. Update extension monitor color category.
Copy link
Contributor

@paulkaplan paulkaplan left a comment

Choose a reason for hiding this comment

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

Apart from the nit and question, looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Monitor Save/Load
2 participants