An ECS Library based on the JavaScript geotic library.
Project description
ECStremity
ECStremity is an Entity-Component library. It is a Python port of the JavaScript library geotic by Dalton Mills.
- entity : a unique id and a collection of components
- component : a data container
- query : a way to gather collections of entities that match some criteria, for use in systems
- event : a message to an entity and its components
Installation
pip install ecstremity
Usage
To start using ECStremity, import the library and make some components.
from ecstremity import (Engine, Component)
ecs = Engine()
# Define some simple components to start with.
class Position(Component):
name: str = "POSITION"
def __init__(self, x: int, y: int) -> None:
self.x = x
self.y = y
class Velocity(Component):
name: str = "VELOCITY"
def __init__(self, x: int, y: int) -> None:
self.x = x
self.y = y
class Frozen(Component):
name: str = "FROZEN"
# All components must be registered with the engine.
# Component registration must use the class symbol (i.e. do not use the component name attribute).
ecs.register_component(Position)
ecs.register_component(Velocity)
ecs.register_component(Frozen)
# Tell the engine to make an entity.
# You can call `entity.uid` to get the entity's unique ID.
entity = ecs.create_entity()
# Add components to the entity.
# Once a component is registered, it can be accessed using the class symbol, but the name
# attribute can also be used. The component name is not case-sensitive.
entity.add(Position)
entity.add("Velocity")
entity.add("FROZEN")
# Create a query that tracks all components that have both a `Position` and `Velocity`
# component, but not a a `Frozen` component. A query can have any combination of the
# `all_of`, `any_of`, and `none_of` quantifiers.
kinematics = ecs.create_query(
all_of = ['POSITION', 'VELOCITY'],
none_of = ['FROZEN']
)
def loop(dt):
# Loop over the result set to update the position for all entities in the query.
# The query will always return an up-to-date list containing entities that match.
for entity in kinematics.result:
entity['POSITION'].x += entity['VELOCITY'].x * dt
entity['POSITION'].y += entity['VELOCITY'].y * dt
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ecstremity-1.0.0.tar.gz
(7.8 kB
view hashes)
Built Distribution
ecstremity-1.0.0-py3-none-any.whl
(10.8 kB
view hashes)
Close
Hashes for ecstremity-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7be6edd85b3ef0a50e0bbd5c8b323d27eb15af352f18d7c988e2c277b21d99ce |
|
MD5 | 4e3d9d3c1add61b8942ce1b9d0ba8867 |
|
BLAKE2b-256 | 2097d63b05fe4ea91cf05cc29451c89e2294f6e4293e702c365e0d26a1b29382 |