pygame-hotreload


Namepygame-hotreload JSON
Version 0.0.32 PyPI version JSON
download
home_pageNone
SummaryA hot reload enhancer for pygame developement
upload_time2023-06-22 13:23:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords gamedev hotreload pygame
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pygame-hotreload

[![PyPI - Version](https://img.shields.io/pypi/v/pygame-hotreload.svg)](https://pypi.org/project/pygame-hotreload)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pygame-hotreload.svg)](https://pypi.org/project/pygame-hotreload)

-----

**Table of Contents**

- [pygame-hotreload](#pygame-hotreload)
  - [Installation](#installation)
  - [How it work](#how-it-work)
    - [`imports-start-hotreload`](#imports-start-hotreload)
    - [`globals-start-hotreload`](#globals-start-hotreload)
    - [`init-start-hotreload`](#init-start-hotreload)
    - [`loop-start-hotreload`](#loop-start-hotreload)
  - [Example](#example)
    - [game.py](#gamepy)
    - [gen.py](#genpy)
  - [Contributing](#contributing)
    - [Development](#development)
  - [License](#license)

## Installation

```zsh
pip install pygame-hotreload
```

## How it work

The `pygame-hotreload` module is a simple hot-reload module for pygame. It is partialy parse the main python file provided.

It looks for these comments in the main file:

### `imports-start-hotreload`

```python
# imports-start-hotreload
...
# imports-end-hotreload
```
This is where the module will look for the imports that needed for the game loop.

### `globals-start-hotreload`

```python
# globals-start-hotreload
...
# globals-end-hotreload
```
This is where the module will look for the global variables that needed for the game loop.

### `init-start-hotreload`

```python
# init-start-hotreload
...
# init-end-hotreload
```
This is where the module will look for the initialization of the game loop.
There is where you should initialize your global variables.

### `loop-start-hotreload`

```python
# loop-start-hotreload
...
# loop-end-hotreload
```
This is where the module will look for the game loop.

## Example

### game.py
```python
# game.py

from pygame_hotreload import HotReload, set_caption
# imports-start-hotreload
import pygame
# imports-end-hotreload

# Initialize pygame
pygame.init()

# Set the window caption
set_caption("Hot Reload Example")
clock = pygame.time.Clock()
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))

# globals-start-hotreload
global dt
global player_pos
global player_pos_2
# globals-end-hotreload

# init-start-hotreload
def init():
    global dt
    global player_pos
    global player_pos_2
    dt = 0
    player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
    player_pos_2 = pygame.Vector2(screen.get_width() // 3, screen.get_height() // 3)
# init-end-hotreload


# loop-start-hotreload
def loop():
    global dt
    global player_pos
    global player_pos_2
    screen.fill("black")
    pygame.draw.rect(screen, "purple", 
                    pygame.Rect(player_pos.x, player_pos.y, 100, 100))
    pygame.draw.rect(screen, "purple", 
                    pygame.Rect(player_pos_2.x, player_pos_2.y, 100, 100), 1)

    keys = pygame.key.get_pressed()
    if keys[pygame.K_z] or keys[pygame.K_UP]:
        player_pos.y -= 300 * dt
    if keys[pygame.K_s] or keys[pygame.K_DOWN]:
        player_pos.y += 300 * dt
    if keys[pygame.K_q] or keys[pygame.K_LEFT]:
        player_pos.x -= 300 * dt
    if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
        player_pos.x += 300 * dt

    dt = clock.tick(60) / 1000
# loop-end-hotreload

# Initialize the hot reload
hotreload = HotReload(
    main_file=__file__,
    screen=screen,
    clock=clock,
    clock_tick=60,
    gen_script_name="gen.py",
)

hotreload.run()
```

### gen.py

```python
import pygame
global dt
global player_pos
global player_pos_2
def init():
    global dt
    global player_pos
    global player_pos_2
    dt = 0
    player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
    player_pos_2 = pygame.Vector2(screen.get_width() // 3, screen.get_height() // 3)
def loop():
    global dt
    global player_pos
    global player_pos_2
    screen.fill("black")
    pygame.draw.rect(screen, "purple", 
                    pygame.Rect(player_pos.x, player_pos.y, 100, 100))
    pygame.draw.rect(screen, "purple", 
                    pygame.Rect(player_pos_2.x, player_pos_2.y, 100, 100), 1)

    keys = pygame.key.get_pressed()
    if keys[pygame.K_z] or keys[pygame.K_UP]:
        player_pos.y -= 300 * dt
    if keys[pygame.K_s] or keys[pygame.K_DOWN]:
        player_pos.y += 300 * dt
    if keys[pygame.K_q] or keys[pygame.K_LEFT]:
        player_pos.x -= 300 * dt
    if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
        player_pos.x += 300 * dt

    dt = clock.tick(60) / 1000
```

## Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

### Development

To set up `pygame-hotreload` for local development:
  - Fork the `pygame-hotreload` repository.
  - Clone your fork locally
  - Use `pipenv shell` to enter the virtual environment
  - Use `pipenv install` to install all dependencies
  - Make a change, and push your local branch to your fork
  - Make a pull request
  - You can build your own version of the project with `hatch version beta && hatch build --wheel` and install it with `pipenv install dist/pygame_hotreload-<VERSION>-py3-none-any.whl`


## License

`pygame-hotreload` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pygame-hotreload",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "gamedev,hotreload,pygame",
    "author": null,
    "author_email": "luxluth <delphin.blehoussi93@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/63/2d/2591476f125acf7bc1906e16893876051d45210330aedef0c8955c52dd6c/pygame_hotreload-0.0.32.tar.gz",
    "platform": null,
    "description": "# pygame-hotreload\n\n[![PyPI - Version](https://img.shields.io/pypi/v/pygame-hotreload.svg)](https://pypi.org/project/pygame-hotreload)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pygame-hotreload.svg)](https://pypi.org/project/pygame-hotreload)\n\n-----\n\n**Table of Contents**\n\n- [pygame-hotreload](#pygame-hotreload)\n  - [Installation](#installation)\n  - [How it work](#how-it-work)\n    - [`imports-start-hotreload`](#imports-start-hotreload)\n    - [`globals-start-hotreload`](#globals-start-hotreload)\n    - [`init-start-hotreload`](#init-start-hotreload)\n    - [`loop-start-hotreload`](#loop-start-hotreload)\n  - [Example](#example)\n    - [game.py](#gamepy)\n    - [gen.py](#genpy)\n  - [Contributing](#contributing)\n    - [Development](#development)\n  - [License](#license)\n\n## Installation\n\n```zsh\npip install pygame-hotreload\n```\n\n## How it work\n\nThe `pygame-hotreload` module is a simple hot-reload module for pygame. It is partialy parse the main python file provided.\n\nIt looks for these comments in the main file:\n\n### `imports-start-hotreload`\n\n```python\n# imports-start-hotreload\n...\n# imports-end-hotreload\n```\nThis is where the module will look for the imports that needed for the game loop.\n\n### `globals-start-hotreload`\n\n```python\n# globals-start-hotreload\n...\n# globals-end-hotreload\n```\nThis is where the module will look for the global variables that needed for the game loop.\n\n### `init-start-hotreload`\n\n```python\n# init-start-hotreload\n...\n# init-end-hotreload\n```\nThis is where the module will look for the initialization of the game loop.\nThere is where you should initialize your global variables.\n\n### `loop-start-hotreload`\n\n```python\n# loop-start-hotreload\n...\n# loop-end-hotreload\n```\nThis is where the module will look for the game loop.\n\n## Example\n\n### game.py\n```python\n# game.py\n\nfrom pygame_hotreload import HotReload, set_caption\n# imports-start-hotreload\nimport pygame\n# imports-end-hotreload\n\n# Initialize pygame\npygame.init()\n\n# Set the window caption\nset_caption(\"Hot Reload Example\")\nclock = pygame.time.Clock()\nscreen_width = 800\nscreen_height = 600\nscreen = pygame.display.set_mode((screen_width, screen_height))\n\n# globals-start-hotreload\nglobal dt\nglobal player_pos\nglobal player_pos_2\n# globals-end-hotreload\n\n# init-start-hotreload\ndef init():\n    global dt\n    global player_pos\n    global player_pos_2\n    dt = 0\n    player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)\n    player_pos_2 = pygame.Vector2(screen.get_width() // 3, screen.get_height() // 3)\n# init-end-hotreload\n\n\n# loop-start-hotreload\ndef loop():\n    global dt\n    global player_pos\n    global player_pos_2\n    screen.fill(\"black\")\n    pygame.draw.rect(screen, \"purple\", \n                    pygame.Rect(player_pos.x, player_pos.y, 100, 100))\n    pygame.draw.rect(screen, \"purple\", \n                    pygame.Rect(player_pos_2.x, player_pos_2.y, 100, 100), 1)\n\n    keys = pygame.key.get_pressed()\n    if keys[pygame.K_z] or keys[pygame.K_UP]:\n        player_pos.y -= 300 * dt\n    if keys[pygame.K_s] or keys[pygame.K_DOWN]:\n        player_pos.y += 300 * dt\n    if keys[pygame.K_q] or keys[pygame.K_LEFT]:\n        player_pos.x -= 300 * dt\n    if keys[pygame.K_d] or keys[pygame.K_RIGHT]:\n        player_pos.x += 300 * dt\n\n    dt = clock.tick(60) / 1000\n# loop-end-hotreload\n\n# Initialize the hot reload\nhotreload = HotReload(\n    main_file=__file__,\n    screen=screen,\n    clock=clock,\n    clock_tick=60,\n    gen_script_name=\"gen.py\",\n)\n\nhotreload.run()\n```\n\n### gen.py\n\n```python\nimport pygame\nglobal dt\nglobal player_pos\nglobal player_pos_2\ndef init():\n    global dt\n    global player_pos\n    global player_pos_2\n    dt = 0\n    player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)\n    player_pos_2 = pygame.Vector2(screen.get_width() // 3, screen.get_height() // 3)\ndef loop():\n    global dt\n    global player_pos\n    global player_pos_2\n    screen.fill(\"black\")\n    pygame.draw.rect(screen, \"purple\", \n                    pygame.Rect(player_pos.x, player_pos.y, 100, 100))\n    pygame.draw.rect(screen, \"purple\", \n                    pygame.Rect(player_pos_2.x, player_pos_2.y, 100, 100), 1)\n\n    keys = pygame.key.get_pressed()\n    if keys[pygame.K_z] or keys[pygame.K_UP]:\n        player_pos.y -= 300 * dt\n    if keys[pygame.K_s] or keys[pygame.K_DOWN]:\n        player_pos.y += 300 * dt\n    if keys[pygame.K_q] or keys[pygame.K_LEFT]:\n        player_pos.x -= 300 * dt\n    if keys[pygame.K_d] or keys[pygame.K_RIGHT]:\n        player_pos.x += 300 * dt\n\n    dt = clock.tick(60) / 1000\n```\n\n## Contributing\n\nContributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.\n\n### Development\n\nTo set up `pygame-hotreload` for local development:\n  - Fork the `pygame-hotreload` repository.\n  - Clone your fork locally\n  - Use `pipenv shell` to enter the virtual environment\n  - Use `pipenv install` to install all dependencies\n  - Make a change, and push your local branch to your fork\n  - Make a pull request\n  - You can build your own version of the project with `hatch version beta && hatch build --wheel` and install it with `pipenv install dist/pygame_hotreload-<VERSION>-py3-none-any.whl`\n\n\n## License\n\n`pygame-hotreload` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A hot reload enhancer for pygame developement",
    "version": "0.0.32",
    "project_urls": {
        "Documentation": "https://github.com/luxluth/pygame-hotreload#readme",
        "Issues": "https://github.com/luxluth/pygame-hotreload/issues",
        "Source": "https://github.com/luxluth/pygame-hotreload"
    },
    "split_keywords": [
        "gamedev",
        "hotreload",
        "pygame"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "27e820acb7f81c14f2d4bab46ff5d13773b2075a64ae662a1280314f96e2a152",
                "md5": "e3ea95a20548f8fe14434e78d3d4ae86",
                "sha256": "8f5a4b45ca4762397bc5d66ee664d8a22f664ebac95e9eeff6a274b9bf5b27f0"
            },
            "downloads": -1,
            "filename": "pygame_hotreload-0.0.32-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e3ea95a20548f8fe14434e78d3d4ae86",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6686,
            "upload_time": "2023-06-22T13:23:17",
            "upload_time_iso_8601": "2023-06-22T13:23:17.508797Z",
            "url": "https://files.pythonhosted.org/packages/27/e8/20acb7f81c14f2d4bab46ff5d13773b2075a64ae662a1280314f96e2a152/pygame_hotreload-0.0.32-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "632d2591476f125acf7bc1906e16893876051d45210330aedef0c8955c52dd6c",
                "md5": "d4692315f933016b851d2a8eff1e1722",
                "sha256": "d5af1da2a7f8eb27c3541fad997b3fff31d5c5b378613cab45aece8fc6cd7f85"
            },
            "downloads": -1,
            "filename": "pygame_hotreload-0.0.32.tar.gz",
            "has_sig": false,
            "md5_digest": "d4692315f933016b851d2a8eff1e1722",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 17037,
            "upload_time": "2023-06-22T13:23:15",
            "upload_time_iso_8601": "2023-06-22T13:23:15.556134Z",
            "url": "https://files.pythonhosted.org/packages/63/2d/2591476f125acf7bc1906e16893876051d45210330aedef0c8955c52dd6c/pygame_hotreload-0.0.32.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-22 13:23:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "luxluth",
    "github_project": "pygame-hotreload#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pygame-hotreload"
}
        
Elapsed time: 0.08273s