LingDong- / q5xjs

A small and fast alternative (experimental) implementation of p5.js
https://q5xjs.netlify.app/
The Unlicense
544 stars 25 forks source link

registerMethod implementation needed for p5play compatibility! #20

Open quinton-ashley opened 1 year ago

quinton-ashley commented 1 year ago

Hi I think this library is really great but I noticed there's no registerMethod implementation. Lots of p5 libraries rely on this feature, including mine, p5.play!

I think making q5 compatible with p5.play would be perfect because my library only needs the 2D p5 functions. p5js is bloated and I think my users would especially benefit from q5 on mobile.

Let me know if you're currently working on a registerMethod implementation. If not I will try doing it.

quinton-ashley commented 1 year ago

I also noticed the q5xjs npm package is outdated. I would really need it to be kept up to date. If you're busy with other projects and aren't interested in maintaining q5xjs anymore, I'd like to submit my candidacy to maintain it for you! You can see how much work I've put into p5.play on my website and I'd be a big advocate for q5.

https://p5play.org

quinton-ashley commented 1 year ago

I would also need anything added by p5.js addon libraries to exist in the global scope or in q5 instances, not (only) in a separate windows.addons object.

quinton-ashley commented 1 year ago

btw I really like your code style! Short and concise. I'm gonna go ahead and try making all the necessary improvements to q5xjs so that it can work with p5.play. If you like what I end up with you can add me as a contributor to this project, otherwise I will make my own repo for it.

quinton-ashley commented 1 year ago

Here's my progress so far, I've made a lot of big upgrades!

https://github.com/quinton-ashley/q5.js

quinton-ashley commented 1 year ago

I added automatic global instance creation to q5.js so p5.js sketches could be fully compatible with q5.js without the user needing new Q5('global'); at the beginning of their sketch. The neat part is I managed to figure out how to also keep your functionality of a user initiated start to the global q5 instance so users can still use q5 functions outside of the setup function!

I did it by adding a variable to check if a global instance of Q5 has been created yet.

function Q5(scope) {
    if (scope == 'global') Q5._global = true;

I put the following code at the end of the q5js file. It creates a new global Q5 instance after all scripts are loaded, if one hasn't been created by the user already.

document.addEventListener('DOMContentLoaded', () => {
    if (!Q5._global) new Q5('global');
});

I'll make a pull request with my changes soon. :)

quinton-ashley commented 1 year ago

Check out my list of what's new in version 1.0 😄

https://github.com/quinton-ashley/q5.js#whats-new-in-version-10

quinton-ashley commented 1 year ago

There's a bug with sprite.rotateTo in p5play when using q5 that I'm gonna try to solve. After that I'll submit a pull request.