wecs.core module

class wecs.core.UID

Bases: object

Object for referencing a wecs.core.Entity

exception wecs.core.NoSuchUID

Bases: Exception

class wecs.core.World

Bases: object

Has a set of wecs.core.Entity

and a set of wecs.core.System

create_entity(*args, name=None)
*args
Initial Components.
name
Entity name string.
get_entity(uid)
uid
The :core:’wecs.core.UID’ of entity to return
Returns:‘wecs.core.Entity’
destroy_entity(uid_or_entity)
remove_entity(uid_or_entity)
add_system(system, sort, add_duplicates=False)
system
System to add
sort
Order the system should run
Returns:Entity
has_system(system_type)
get_systems()
get_system(system_type)
remove_system(system_type)
get_system_component_dependencies()
register_entity_for_components_update(entity)
flush_component_updates()
update_entity_filters(entities)
update()
update_system(system)
class wecs.core.Entity(world, name=None)

Bases: object

Everything in a wecs.core.World is an Entity. They have a set of wecs.core.Component and are, with regard to how they are processed, type- and stateless.

They are usually created with wecs.core.World.create_entity()

add_component(component)
get_components()
get_component(component_type)
has_component(component_type)
remove_component(component_type)
update_components()
get_dropped_components_by_type()
drop_component_updates()
destroy()
class wecs.core.Component(unique=True)

Bases: object

New components should inherrit from this class like so:

@Component()
class SomeNewComponent:
    some_variable: int = 0
class wecs.core.System(throw_exc=False)

Bases: object

Example of a system:

class Print(System):
    # Filter all entities in the world described as Printer
    entity_filters = {
        'printers' : and_filter([Printer])
    }

    def update(self, entities_by_filter):
        # Iterate over all filtered entities
        for entity in entities_by_filter['printers']:
            # Print their message
            print(entity[Printer].message)

Then add it with wecs.core.World.add_system()

init_entity(filter_name, entity)
destroy_entity(filter_name, entity, components_by_type)
update(entities_by_filter)
get_component_dependencies()
class wecs.core.Filter

Bases: object

get_component_dependencies()
class wecs.core.AndFilter(types_and_filters)

Bases: wecs.core.Filter

wecs.core.and_filter(types_and_filters)
class wecs.core.OrFilter(types_and_filters)

Bases: wecs.core.Filter

wecs.core.or_filter(types_and_filters)