pygbag_builder
This is a module to support people who want to make browser game with pygame. Normaly, pygame won't work on web browser but by using pygbag(wasm for pygame), we can publish pygame programs on the internet.
When we use pygbag, we should pay attention to some points.
- name the main file as
main.py - call main function with asyncio.run
- insert await asyncio.sleep(0) into while loops
- remake some functions into async functions
These points are not fatal probrem if there aren't many while loops. But when we make a little complex games, these points become cumbersome. So, this module aims to support making those game.(This module may not enough to support highly complex game...sorry.)
Install
pip install pygbag-builder
How To
preparation
You should make folder for your project at first. The main file must be main.py and contain main function.
These are sample programs. main.py can import other .pyfiles. The only thing that you should care about is to make main function.
import pygame, sys
import module
pygame.init()
screen = pygame.display.set_mode((512, 512))
pygame.display.set_caption('template')
clock = pygame.time.Clock()
class Class:
def __init__(self):
pass
def loop(self):
while True:
break
instance = Class()
def loop():
while True:
break
def main():
color = 0
while True:
screen.fill((color, color, color))
color = min(255, color+1)
loop()
instance.loop()
module.loop()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
clock.tick(30)
if __name__ == '__main__':
main()
def loop():
while True:
break
commands
pygbag-builder offers these three commands
- pygbag_builder main_flow
- pygbag_builder make_repo
- pygbag_builder set_page
pygbag_builder main_flow
This is a command to create needed files for pygbag.
please use this command in your project folder
python -m pygbag_builder main_flow
By using this command, your python files are automatically modified like this.
import asyncio
import pygame, sys
import module
pygame.init()
screen = pygame.display.set_mode((512, 512))
pygame.display.set_caption('template')
clock = pygame.time.Clock()
class Class:
def __init__(self):
pass
async def loop(self):
while True:
await asyncio.sleep(0)
break
instance = Class()
async def loop():
while True:
await asyncio.sleep(0)
break
async def main():
color = 0
while True:
await asyncio.sleep(0)
screen.fill((color, color, color))
color = min(255, color + 1)
await loop()
await instance.loop()
await module.loop()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
clock.tick(30)
if __name__ == '__main__':
asyncio.run(main())
import asyncio
async def loop():
while True:
await asyncio.sleep(0)
break
:::note warn This part may not work compleately in complex program. In that case, please modify some parts manually. :::
Also, this command creates 'pygbag.yml'(.github/workflows/pygbag.yml)
These files are put in pygbag_builder_build folder which created in your project folder.
pygbag_builder make_repo
This is a command to make repository automatically. It uses GitHub API so you need GitHub token. This command not only make repository but also runs workflow(pygbag_build).So, You Don't have to change settings. Instead, you have to get GitHub token with necessary permissions. You can get your token from Developer settings in Settings of your account.
Personal access tokens
[Repository access] Select All repositories
[Permissions]
These permissions must be Read and Write
- Actions
- Administration
- Contents
- Pages
- Webhooks
- Workflows
please use this command in your project folder
python -m pygbag_builder make_repo
:::note warn
Depending on the timing of the process, sometimes the workflow may not execute properly, In that case, run this command again. You will get an error because the repository already exist, but no problem. Or you can run pygbag_build manually from Action.
:::
If you don't want to use token. You have to create repository manually.
https://pygame-web.github.io/wiki/publishing/github.io/
summary
- run pygbag_build from Action
- set gh-pages to branch from Settings → pages
pygbag_builder set_page
This is a command to set gh-pages to branch. It also uses GitHub API.
Before using this command, you must check whether pygbag_build workflow is finished.(You can check it from Action)
please use this command in your project folder
python -m pygbag_builder set_page
If you want to test on https://localhost:8000 before uploading your game, you can use this command.
pygbag pygbag_builder_build
License
This project follows MIT. If you need more information, please look at LICENSE.
pygbag
Metadata
Release files for pygbag-builder 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pygbag_builder-0.1.5.tar.gz | 9.9 kB | Without provenance | Details for pygbag_builder-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pygbag_builder-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for pygbag_builder-0.1.5-py3-none-any.whl |
Total release size: 20.4 kB
Release files / pygbag_builder-0.1.5.tar.gz
| Download URL | pygbag_builder-0.1.5.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66f84af3244092da5d0551384436f19275aef0230fa8d61d40fcf6f289364567
|
|
BLAKE2b-256 checksum How to use checksums |
7a8afa2767c1957e6c3690c46a0b8720f891565a5230233d29b3eb17d748b346
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Release files / pygbag_builder-0.1.5-py3-none-any.whl
| Download URL | pygbag_builder-0.1.5-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f2c4bc406e5de7ec31949d73cab7fd380eaa7c0f98af80d543248f925b7f7449
|
|
BLAKE2b-256 checksum How to use checksums |
24ae073307c4eafbfdf14ba5b6192ef3870fda82f9254147dbfb2cad2da74cb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Security for pygbag-builder 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.