Comments (4)
Sorry for not replying sooner. I didn't get notified of this issue ticket.
You can do this with the world.add_compoent
method. There is a type_alias
argument. For example:
entity1 = world.create_entity()
world.add_component(entity1, Lion(), type_alias=Animal)
This means that you can't add components when creating an entity. You have to do it in two steps.
A full example:
import esper
world = esper.World()
# Base class:
class Animal: pass
class Lion(Animal): pass
class Tiger(Animal): pass
class Bear(Animal): pass
entity1 = world.create_entity()
world.add_component(entity1, Lion(), type_alias=Animal)
entity2 = world.create_entity()
world.add_component(entity2, Tiger(), type_alias=Animal)
entity3 = world.create_entity()
world.add_component(entity3, Bear(), type_alias=Animal)
for ent, animal in world.get_component(Animal):
print(ent, animal)
from esper.
Can I use one more type likes type_alias=(Animal, Lion)
?
from esper.
No, that's not possible. It would be difficult to store in the DB, and difficult to query.
from esper.
I'm going to close this for now, but please feel free to reply if you want to discuss further.
from esper.
Related Issues (20)
- get_components does not get entities in order (ascending order). HOT 3
- Depth of an image HOT 5
- I know ECS is largely used for games, but can this specific library also work for database backed CRUD web apps? HOT 3
- A way to index and get Component with parameters HOT 6
- Event system, or how to decouple processors HOT 15
- `lru_cache` swallows type annotation in `get_component` HOT 2
- `get_components` type annotation: accept and return *different* component types, not the same HOT 6
- version 1.5 is not showing on pypi HOT 1
- `py.typed` file is missing. HOT 5
- event handler as function HOT 4
- Create an entity with a specific id HOT 4
- Try another ECS implementation - ecs_pattern library HOT 2
- Typing of world under the processor class HOT 3
- Testing esper HOT 4
- mypy `get_components` gives "object" type HOT 1
- Relationships HOT 8
- `World().create_entity()` does not create entity if no components are given HOT 1
- `remove_component()` method removes entity if no more components left HOT 3
- Add mypy to unit tests HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esper.