tinyecs-compsys-base 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,132 @@
1
+ from collections.abc import Callable
2
+ from dataclasses import dataclass, InitVar
3
+
4
+ import tinyecs as ecs
5
+
6
+ from aenum import extend_enum
7
+ from pgcooldown import CronD, Cooldown
8
+ from tinyecs import EntityID
9
+ from tinyecs.compsys import Comp
10
+
11
+
12
+ extend_enum(Comp, 'CROND')
13
+ extend_enum(Comp, 'FOLLOWUP')
14
+ extend_enum(Comp, 'IS_KILLED')
15
+ extend_enum(Comp, 'KILL_WITH_PARENT')
16
+ extend_enum(Comp, 'TIMER')
17
+
18
+
19
+ @dataclass
20
+ class Timer:
21
+ """An optionally repeating timer component.
22
+
23
+ :param cooldown: The actual timer object
24
+ :param callback: The function to run when the timer fires
25
+ :param repeat: Decides if the timer is reoccurring
26
+
27
+ The prototype of the callback function is::
28
+
29
+ def callback()
30
+
31
+ .. note:: If ``repeat`` is false, when using :func:`sys_timer`, the
32
+ component will be removed after it fired.
33
+ """
34
+
35
+ cooldown: InitVar[float | Cooldown]
36
+ callback: Callable[None, []]
37
+ repeat: bool = False
38
+
39
+ def __post_init__(self, cooldown: Cooldown | float) -> None:
40
+ self.cooldown = cooldown if isinstance(cooldown, Cooldown) else Cooldown(cooldown)
41
+
42
+
43
+ def sys_crond(eid: EntityID, crond: CronD) -> None:
44
+ """Update a pgcooldown.CronD queue.
45
+
46
+ :param eid: The entity ID
47
+ :param crond: The schedule queue for the entity. See :class:`pgcooldown.CronD`
48
+
49
+ pgcooldown's ``CronD`` class needs to have its ``update`` method called
50
+ frequently. Running this system will ensure exactly that.
51
+
52
+ """
53
+
54
+ crond.update()
55
+
56
+
57
+ def sys_followup(eid: EntityID, is_killed: bool, followup: Callable[[], None]) -> None:
58
+ """Run a followup function after an entity is marked as dead.
59
+
60
+ :param eid: The entity ID
61
+ :param is_killed: The boolean flag component to mark this as killed
62
+ :param followup: A callback to run
63
+
64
+ The prototype for the callback is::
65
+
66
+ def callback() -> None
67
+
68
+ Once the followup has fired, its component is removed.
69
+ """
70
+
71
+ ecs.remove_component(eid, Comp.FOLLOWUP)
72
+ followup(eid)
73
+
74
+
75
+ def sys_kill_with_parent(eid: EntityID, parent: EntityID):
76
+ """Mark this entity as "killed" if its parent is killed as well.
77
+
78
+ :param eid: The entity ID
79
+ :param parent: The parent entity to watch
80
+
81
+ Relies on :func:`sys_reap` or your own system to actually remove the entity.
82
+ """
83
+
84
+ if ecs.eid_has(parent, Comp.IS_KILLED):
85
+ ecs.add_component(eid, Comp.IS_KILLED, True)
86
+
87
+
88
+ def sys_lifetime(eid: EntityID, lifetime: Cooldown) -> None:
89
+ """Update position based on a LerpPosition object.
90
+
91
+ :param eid: The entity ID
92
+ :param lifetime: A `pgcooldown.Cooldown` instance
93
+
94
+ Relies on :func:`sys_reap` or your own system to actually remove the entity.
95
+ """
96
+
97
+ if lifetime.cold():
98
+ ecs.add_component(eid, Comp.IS_KILLED, True)
99
+
100
+
101
+ def sys_reap(eid: EntityID, is_killed: bool) -> None:
102
+ """Remove entities that have a Comp.IS_KILLED component.
103
+
104
+ :param eid: The entity ID
105
+ :param is_killed: Exactly that
106
+
107
+ """
108
+
109
+ ecs.remove_entity(eid)
110
+
111
+
112
+ def sys_timer(eid: EntityID, timer: Cooldown) -> None:
113
+ """Run a callback function after a timer runs out.
114
+
115
+ :param eid: The entity ID
116
+ :param timer: A :class:`Timer` object
117
+
118
+ .. note:: If timer.repeat is not set, the component is removed after the
119
+ timer has run out. Otherwise the timer is reset.
120
+
121
+ The prototype for the callback is::
122
+
123
+ def callback() -> None
124
+ """
125
+
126
+ if timer.cooldown.cold():
127
+ if timer.repeat:
128
+ timer.cooldown.reset()
129
+ else:
130
+ ecs.remove_component(eid, Comp.TIMER)
131
+
132
+ timer.callback()
@@ -0,0 +1,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: tinyecs-compsys-base
3
+ Version: 0.0.1
4
+ Summary: Foundational component and system library for tinyecs
5
+ Author-email: Michael Lamertz <michael.lamertz@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: homepage, https://github.com/dickerdackel/tinyecs-compsys-base
8
+ Project-URL: bugtracker, https://github.com/dickerdackel/tinyecs-compsys-base/issues
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Games/Entertainment
12
+ Classifier: Topic :: Software Development :: Libraries :: pygame
13
+ Description-Content-Type: text/x-rst
14
+ License-File: LICENSE
15
+ Requires-Dist: aenum
16
+ Requires-Dist: pgcooldown
17
+ Requires-Dist: tinyecs>=0.5.0
18
+ Dynamic: license-file
19
+
20
+ tinyecs-compsys-base
21
+ ====================
22
+
23
+ Thise are some very basic and framework independent components.
24
+
25
+ Synopsis
26
+ --------
27
+
28
+ .. code:: python
29
+
30
+ from tinyecs.compsys.base import ...
31
+
32
+ Usage
33
+ -----
34
+
35
+ This package has no direct functionality, but all sub modules will register
36
+ their component IDs in the ``tinyecs.compsys.Comp`` enum.
37
+
38
+ Installation
39
+ ------------
40
+
41
+ Installation instructions + requirements (should come automagically with
42
+ pyproject.toml)
43
+
44
+ .. code:: console
45
+
46
+ pip install tinyecs[base]
47
+ # or
48
+ pip install tinyecs
49
+ pip install tinyecs-compsys
50
+ pip install tinyecs-compsys-base
51
+
52
+ Support / Contributing
53
+ ----------------------
54
+
55
+ Issues can be opened on `github issues`_
56
+
57
+ .. _github issues: https://forgejo.indieandmore.photography/dickerdackel/tinyecs-compsys/issues
58
+
59
+
60
+ License
61
+ -------
62
+
63
+ This software is provided under the MIT license.
64
+
65
+ See LICENSE file for details.
@@ -0,0 +1,6 @@
1
+ tinyecs/compsys/base/__init__.py,sha256=MOJ5JEPO_ydlHpjlChDqUMD3SbFJJxrSNsPP0egTAtE,3537
2
+ tinyecs_compsys_base-0.0.1.dist-info/licenses/LICENSE,sha256=Ov4pwsg4S7PmyeyUVABYYBtwaBxK1LdI8Y9--FajuMk,1072
3
+ tinyecs_compsys_base-0.0.1.dist-info/METADATA,sha256=EWOxUEzQQQXJixCZwPJX8nlzBkm8BJ4Vb2PLEtxr0eQ,1605
4
+ tinyecs_compsys_base-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ tinyecs_compsys_base-0.0.1.dist-info/top_level.txt,sha256=lMaXjtnpZvawjp5Re5jZOY_Yki_mB1QkM_PTRUig0O4,8
6
+ tinyecs_compsys_base-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Michael Lamertz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ tinyecs