benmoran56 / esper

An ECS (Entity Component System) for Python
MIT License
544 stars 69 forks source link

Expose @component decorator #53

Closed bstrie closed 3 years ago

bstrie commented 3 years ago

While playing around with esper I noticed that making components involved a bit of boilerplate:

class Position:
    def __init__(self, x=0.0, y=0.0, z=0.0):
        self.x = x
        self.y = y
        self.z = z

I solved this by using Python's dataclasses.dataclass decorator, imported as component:

@component
class Position:
    x: float = 0.0
    y: float = 0.0
    z: float = 0.0

I thought this looked a bit nicer, so here's a patch that exposes this as esper.component, adds a note in the readme, and updates some examples to use it.

benmoran56 commented 3 years ago

Thanks for the pull request! I like this idea. The only concern I have is that Python 3.6 is still in support until the end of the year. There is a backported dataclasses module available on PyPi however, so I still think it's OK to move forward with this. I'll just put a note in the README for the next release.

bstrie commented 3 years ago

Rebased.

benmoran56 commented 3 years ago

Thank you very much! I'll try to get a new release out soon.