diff --git a/arcade/gl/backends/webgl/framebuffer.py b/arcade/gl/backends/webgl/framebuffer.py index a5bf4a18c..a4d30975b 100644 --- a/arcade/gl/backends/webgl/framebuffer.py +++ b/arcade/gl/backends/webgl/framebuffer.py @@ -256,7 +256,7 @@ def __init__(self, ctx: WebGLContext): @DefaultFrameBuffer.viewport.setter def viewport(self, value: tuple[int, int, int, int]): - # This is the exact same as the WebGLFramebuffer setter + # This is very similar to the OpenGL backend setter # WebGL backend doesn't need to handle pixel scaling for the # default framebuffer like desktop does, the browser does that # for us. However we need a separate implementation for the @@ -264,13 +264,7 @@ def viewport(self, value: tuple[int, int, int, int]): if not isinstance(value, tuple) or len(value) != 4: raise ValueError("viewport shouldbe a 4-component tuple") - ratio = self.ctx.window.get_pixel_ratio() - self._viewport = ( - int(value[0] * ratio), - int(value[1] * ratio), - int(value[2] * ratio), - int(value[3] * ratio), - ) + self._viewport = value if self._ctx.active_framebuffer == self: self._ctx._gl.viewport(*self._viewport) @@ -281,23 +275,11 @@ def viewport(self, value: tuple[int, int, int, int]): @DefaultFrameBuffer.scissor.setter def scissor(self, value): - # This is the exact same as the WebGLFramebuffer setter - # WebGL backend doesn't need to handle pixel scaling for the - # default framebuffer like desktop does, the browser does that - # for us. However we need a separate implementation for the - # function because of ABC if value is None: self._scissor = None if self._ctx.active_framebuffer == self: self._ctx._gl.scissor(*self._viewport) else: - ratio = self.ctx.window.get_pixel_ratio() - self._scissor = ( - int(value[0] * ratio), - int(value[1] * ratio), - int(value[2] * ratio), - int(value[3] * ratio), - ) - + self._scissor = value if self._ctx.active_framebuffer == self: self._ctx._gl.scissor(*self._scissor) diff --git a/webplayground/README.md b/webplayground/README.md index df6b4b0df..1491686e6 100644 --- a/webplayground/README.md +++ b/webplayground/README.md @@ -5,18 +5,30 @@ An http server is provided with the `server.py` file. This file can be run with The index page will provide a list of all Arcade examples. This is generated dynamically on the fly when the page is loaded, and will show all examples in the `arcade.examples` package. This generates links which can be followed to open any example in the browser. -There are some pre-requesites to running this server. It assumes that you have the `development` branch of Pyglet -checked out and in a folder named `pyglet` directly next to your Arcade repo directory. You will also need to have -the `build` and `flit` packages from PyPi installed. These are used by Pyglet and Arcade to build wheel files, -but are not generally installed for local development. +## Testing Local Scripts -Assuming you have Pyglet ready to go, you can then start the server. It will build wheels for both Pyglet and Arcade, and copy them -into this directory. This means that if you make any, you will need to restart this server in order to build new wheels. +You can now test your own local scripts **without restarting the server**! + +1. Navigate to `http://localhost:8000/local` in your browser +2. Place your Python scripts in the `local_scripts/` directory +3. Scripts should have a `main()` function as the entry point +4. The page will automatically list all `.py` files in that directory +5. Click any script to run it in the browser +6. Edit your scripts and refresh the browser page to see changes - no server restart needed! + +See `local_scripts/README.md` and `local_scripts/example_test.py` for more details and examples. + +## Prerequisites + +You will need to have `uv` installed to build the Arcade wheel. You can install it with: + +When you start the server, it will automatically build an Arcade wheel and copy it into this directory. +This means that if you make any changes to Arcade code, you will need to restart the server to build a new wheel with your changes. ## How does this work? The web server itself is built with a nice little HTTP server library named [Bottle](https://github.com/bottlepy/bottle). We need to run an HTTP server locally -to load anything into WASM in the browser, it will not work if we just server it files directly due to browser security constraints. For the Arcade examples specifically, +to load anything into WASM in the browser, as it will not work if we just serve files directly due to browser security constraints. For the Arcade examples specifically, we are taking advantage of the fact that the example code is packaged directly inside of Arcade to enable executing them in the browser. If we need to add extra code that is not part of the Arcade package, that will require extension of this server to handle packaging it properly for loading into WASM, and then diff --git a/webplayground/index.tpl b/webplayground/index.tpl index 4c5a8e11b..66e42fd74 100644 --- a/webplayground/index.tpl +++ b/webplayground/index.tpl @@ -3,9 +3,32 @@ Arcade Examples + +

Arcade Examples

+ 🧪 Test Local Scripts +

Built-in Examples: