Skip to content
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

adding support to p5 instance mode with one singleton #17

Closed

Conversation

guilhermesilveira
Copy link

This commit adds support for p5 instance mode, allowing the user to record one canvas at a time (any p5 canvas within the page).

Usage is straightforward. As expected, after the canvas is set up, P5Capture is told to use that p5 instance and canvas instead of window.

const s = ( sketch ) => {

    sketch.setup = () => {
        // your setup
        P5Capture.setDefaultOptions({p5 : sketch});
    };

    sketch.draw = () => {
        // your draw
    };
};

new p5(s);```

That is all. I have also included:
- the proper end to end tests
- A safety check to warn if one tries to load p5.capture before the document body has been created. You can't load it before document.body as there would be nowhere for the recording window to be appended to

If this implementation makes sense I can add this example to the Readme to finish it.

I did not choose to support multiple recording sessions running at the same time inside a single page since:
- it seems to be an even more rare situation
- it would require to remove the singleton pattern of the P5.Capture, which is not a minor feature

I guess that is all, thanks for the great work.

@tapioca24
Copy link
Owner

tapioca24 commented Nov 18, 2022

Hi, @guilhermesilveira. Thank you for opening this one!
I checked the behavior and found that the option setting by P5Capture.setDefaultOptions() did not work. This was due to the code execution order difference between global and instance modes.
By using other approaches inspired by your code, the options work, and the mode can be auto-detected without additional options.

I will close this as I have created a new one as #20.
Once again, my deepest thanks for your contribution 💚

@tapioca24 tapioca24 closed this Nov 18, 2022
@guilhermesilveira
Copy link
Author

guilhermesilveira commented Nov 18, 2022 via email

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.

None yet

2 participants