Skip to content

Description

Control Panel is used as an entry point to ECS storages and runner.

API

Commands

Source code in encosy/storage/typings.py
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
class Commands:
    def __init__(self, control_panel):
        """
        Commands layer to use control panel inside a system

        Args:
            control_panel:
        """
        self._control_panel = control_panel

    def register_entities(self, *entities) -> 'Commands':
        """
        Register entities for control panel

        Args:
            *entities: any entities

        Returns:
            self

        """
        self._control_panel.register_entities(*entities)
        return self

    def drop_entities(self, *components) -> 'Commands':
        """
        Drop entities by components

        Args:
            *components: drop entities by components

        Returns:
            self

        """
        self._control_panel.remove_entities(*components)
        return self

    def drop_entities_with_expression(self, expression: Callable[[Any], Any]) -> 'Commands':
        """
        Drop entities using expression of type (entity: Entity) -> bool
        ex:
            lambda entity: entity[Position].x == 17.0
                            and entity[Position].y == 21.0
            where Position is a component of a given entity

        Args:
            expression: (Entity) -> True or False

        Returns:
            self

        """
        self._control_panel.drop_entities_with_expression(expression)
        return self

    def stop_systems(self, *systems) -> 'Commands':
        """
        Prevents systems from executing

        Args:
            *systems: any callable

        Returns:
            self

        """
        self._control_panel.stop_systems(*systems)
        return self

    def start_systems(self, *systems) -> 'Commands':
        """
        Allows systems to be executed

        Args:
            *systems: any callable

        Returns:
            self

        """
        self._control_panel.start_systems(*systems)
        return self

    def schedule_drop_systems(self, *systems) -> 'Commands':
        """
        Completely remove system, but only after current tick

        Args:
            *systems: any callable

        Returns:
            self

        """
        self._control_panel.schedule_drop_systems(*systems)
        return self

    def pause_control_panel(self) -> 'Commands':
        """
        Exits from run at the next tick and prevents tick to be executed
        until resume_control_panel is called

        Returns:
            self

        """
        self._control_panel.pause()
        return self

    def resume_control_panel(self) -> 'Commands':
        """
        Resume run but only after control_panel.run() is called

        Returns:
            self

        """
        self._control_panel.resume()
        return self

__init__(control_panel)

Commands layer to use control panel inside a system

Parameters:

Name Type Description Default
control_panel required
Source code in encosy/storage/typings.py
44
45
46
47
48
49
50
51
def __init__(self, control_panel):
    """
    Commands layer to use control panel inside a system

    Args:
        control_panel:
    """
    self._control_panel = control_panel

drop_entities(*components)

Drop entities by components

Parameters:

Name Type Description Default
*components

drop entities by components

()

Returns:

Type Description
Commands

self

Source code in encosy/storage/typings.py
67
68
69
70
71
72
73
74
75
76
77
78
79
def drop_entities(self, *components) -> 'Commands':
    """
    Drop entities by components

    Args:
        *components: drop entities by components

    Returns:
        self

    """
    self._control_panel.remove_entities(*components)
    return self

drop_entities_with_expression(expression)

Drop entities using expression of type (entity: Entity) -> bool

ex

lambda entity: entity[Position].x == 17.0 and entity[Position].y == 21.0 where Position is a component of a given entity

Parameters:

Name Type Description Default
expression Callable[[Any], Any]

(Entity) -> True or False

required

Returns:

Type Description
Commands

self

Source code in encosy/storage/typings.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def drop_entities_with_expression(self, expression: Callable[[Any], Any]) -> 'Commands':
    """
    Drop entities using expression of type (entity: Entity) -> bool
    ex:
        lambda entity: entity[Position].x == 17.0
                        and entity[Position].y == 21.0
        where Position is a component of a given entity

    Args:
        expression: (Entity) -> True or False

    Returns:
        self

    """
    self._control_panel.drop_entities_with_expression(expression)
    return self

pause_control_panel()

Exits from run at the next tick and prevents tick to be executed until resume_control_panel is called

Returns:

Type Description
Commands

self

Source code in encosy/storage/typings.py
141
142
143
144
145
146
147
148
149
150
151
def pause_control_panel(self) -> 'Commands':
    """
    Exits from run at the next tick and prevents tick to be executed
    until resume_control_panel is called

    Returns:
        self

    """
    self._control_panel.pause()
    return self

register_entities(*entities)

Register entities for control panel

Parameters:

Name Type Description Default
*entities

any entities

()

Returns:

Type Description
Commands

self

Source code in encosy/storage/typings.py
53
54
55
56
57
58
59
60
61
62
63
64
65
def register_entities(self, *entities) -> 'Commands':
    """
    Register entities for control panel

    Args:
        *entities: any entities

    Returns:
        self

    """
    self._control_panel.register_entities(*entities)
    return self

resume_control_panel()

Resume run but only after control_panel.run() is called

Returns:

Type Description
Commands

self

Source code in encosy/storage/typings.py
153
154
155
156
157
158
159
160
161
162
def resume_control_panel(self) -> 'Commands':
    """
    Resume run but only after control_panel.run() is called

    Returns:
        self

    """
    self._control_panel.resume()
    return self

schedule_drop_systems(*systems)

Completely remove system, but only after current tick

Parameters:

Name Type Description Default
*systems

any callable

()

Returns:

Type Description
Commands

self

Source code in encosy/storage/typings.py
127
128
129
130
131
132
133
134
135
136
137
138
139
def schedule_drop_systems(self, *systems) -> 'Commands':
    """
    Completely remove system, but only after current tick

    Args:
        *systems: any callable

    Returns:
        self

    """
    self._control_panel.schedule_drop_systems(*systems)
    return self

start_systems(*systems)

Allows systems to be executed

Parameters:

Name Type Description Default
*systems

any callable

()

Returns:

Type Description
Commands

self

Source code in encosy/storage/typings.py
113
114
115
116
117
118
119
120
121
122
123
124
125
def start_systems(self, *systems) -> 'Commands':
    """
    Allows systems to be executed

    Args:
        *systems: any callable

    Returns:
        self

    """
    self._control_panel.start_systems(*systems)
    return self

stop_systems(*systems)

Prevents systems from executing

Parameters:

Name Type Description Default
*systems

any callable

()

Returns:

Type Description
Commands

self

Source code in encosy/storage/typings.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
def stop_systems(self, *systems) -> 'Commands':
    """
    Prevents systems from executing

    Args:
        *systems: any callable

    Returns:
        self

    """
    self._control_panel.stop_systems(*systems)
    return self

Entities

Bases: list[Entity[T]]

Simple class for typing in systems

def my_system( entities: Entities[Entity[Name]] ): pass

Source code in encosy/storage/typings.py
30
31
32
33
34
35
36
37
38
39
40
class Entities(list[Entity[T]]):
    """
    Simple class for typing in systems

    def my_system(
        entities: Entities[Entity[Name]]
    ):
        pass
    """

    pass

Entity

Bases: dict[type, T]

Source code in encosy/storage/typings.py
16
17
18
19
20
21
22
23
24
25
26
27
class Entity(dict[type, T]):
    def __init__(self, *components: Any):
        """
        Basic class for storing components by their type

        If duplicated types passed no error will be raised
        instead duplicate value replace existing one

        Args:
            *components: any items
        """
        super().__init__({type(com): com for com in components})

__init__(*components)

Basic class for storing components by their type

If duplicated types passed no error will be raised instead duplicate value replace existing one

Parameters:

Name Type Description Default
*components Any

any items

()
Source code in encosy/storage/typings.py
17
18
19
20
21
22
23
24
25
26
27
def __init__(self, *components: Any):
    """
    Basic class for storing components by their type

    If duplicated types passed no error will be raised
    instead duplicate value replace existing one

    Args:
        *components: any items
    """
    super().__init__({type(com): com for com in components})