Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relation traversal and propagation #15

Merged
merged 11 commits into from
Oct 21, 2023
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added the `tcod.ecs.IsA` sentinel value.
- Entities will automatically inherit components/tags/relations from entities they have an `IsA` relationship with. https://github.com/HexDecimal/python-tcod-ecs/pull/15
- Entities can be used as prefabs, use `Entity.instantiate()` to make a new entities inheriting the base entities components/tags/relations.

### Removed
- `tcod.ecs.query.Query` removed due to a refactor.
- `abstract_component` decorator removed.

### Fixed
- Fix for `x in Entity.relation_tags_many` not checking the correct values.

## [4.4.0] - 2023-08-11
### Added
Expand Down
5 changes: 5 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ API reference
:undoc-members:
:show-inheritance:

.. automodule:: tcod.ecs.constants
:members:
:undoc-members:
:show-inheritance:

.. automodule:: tcod.ecs.typing
:members:
:undoc-members:
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ classifiers = [
]
dynamic = ["version", "description"]
requires-python = ">=3.8"
dependencies = ["typing-extensions >=4.4.0", "attrs>=23.1.0", "cattrs>=23.1.2"]
dependencies = [
"attrs >=23.1.0",
"cattrs >=23.1.2",
"sentinel-value >=1.0.0",
"typing-extensions >=4.4.0",
]

[tool.setuptools_scm]
write_to = "tcod/ecs/_version.py"
Expand Down
20 changes: 2 additions & 18 deletions tcod/ecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
from __future__ import annotations

import importlib.metadata
import warnings
from collections import defaultdict
from typing import TypeVar

from tcod.ecs.constants import IsA
from tcod.ecs.entity import Entity
from tcod.ecs.world import World

__all__ = (
"__version__",
"Entity",
"IsA",
"World",
"abstract_component",
)

try:
Expand All @@ -22,27 +22,11 @@
__version__ = ""


T = TypeVar("T")
_T1 = TypeVar("_T1")
_T2 = TypeVar("_T2")
_T3 = TypeVar("_T3")


def abstract_component(cls: type[T]) -> type[T]:
"""Register class `cls` as an abstract component and return it.

.. deprecated:: 3.1
This decorator is deprecated since abstract components should always be explicit.
"""
warnings.warn(
"This decorator is deprecated since abstract components should always be explicit.",
FutureWarning,
stacklevel=2,
)
cls._TCOD_BASE_COMPONENT = cls # type: ignore[attr-defined]
return cls


def _defaultdict_of_set() -> defaultdict[_T1, set[_T2]]: # Migrate from <=3.4
"""Return a new defaultdict of sets."""
return defaultdict(set)
Expand Down
7 changes: 7 additions & 0 deletions tcod/ecs/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Special constants and sentinel values."""
from typing import Final

from sentinel_value import sentinel

IsA: Final = sentinel("IsA")
"""The default is-a relationship tag used for entity inheritance."""
Loading