8000 Dispatch `py-game` event right before executing code by WebReflection · Pull Request #2287 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

Dispatch py-game event right before executing code #2287

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 2 commits into from
Feb 27, 2025

Conversation

WebReflection
Copy link
Contributor
@WebReflection WebReflection commented Feb 10, 2025

Description

This MR would like to address @JoshuaLowe1002 feature-request around the ability to listen to an event when py-game type is ready, similarly to how py-editor dispatches an event when found on the page.

This MR currently doesn't use :ready or :done suffixes because a game could run "forever" so it makes little sense to distinguish such events.

On the other hand, this is aligned with py-editor behavior so at least it's somehow consistent with what we already landed.

@JoshuaLowe1002 please feel free to correct me or hint anything that comes to mine, considering you'll have synchronous time to do things right before the code will get executed asynchronously.

Changes

  • dispatch a py-game bubbling event right before the code will get executed
  • pass all relevant details as event.detail su as:
    • canvas, which is the DOM canvas element where the game is going to run
    • code, which is the code that is going to be executed
    • config, which is the currently resolved/parsed config
    • wrap, which is the usual wrapper all hooks receive via polyscript, within itself the interpreter and everything else
  • if the event.preventDefault() is invoked, the code does not get instantly executed

Checklist

  • I have checked make build works locally.
  • I have created / updated documentation for this change (if applicable).

@WebReflection WebReflection force-pushed the py-game-event branch 3 times, most recently from 8b64966 to 11d2c0e Compare February 10, 2025 11:42
@WebReflection
Copy link
Contributor Author

maybe I should've asked before the release but I still think this should be merged (for the next one) ... it's true that this doesn't solve all @JoshuaLowe1002 requirements but as discussed those requirements cannot currently be solved anyway, due our current inability to run py-game in workers, so that the iframe suggested by @ntoll would still be the best approach to avoid blocking, with also the ability to drop that iframe at any time and "exit" the game.

thoughts? it's not urgent, but I think these changes add something to better play around py-game experiment.

Copy link
Member
@ntoll ntoll left a comment

Choose a reason for hiding this comment

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

LGTM

@ntoll
Copy link
Member
ntoll commented Feb 27, 2025

@JoshuaLowe1002 ?

@JoshuaLowe1002
Copy link
Member

After discussing with Andrea, when I eventually get round to adding py-game to EduBlocks i'm going to take the iframe approach due to workers not being available. So this being merged isn't urgent for me, however, I think it will still be useful.

@WebReflection WebReflection merged commit 1d666b9 into pyscript:main Feb 27, 2025
2 checks passed
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.

3 participants
0