Skip to content

Commit

Permalink
Ready v3.3 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoran56 committed May 28, 2024
1 parent 923533e commit d95def2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 272 deletions.
5 changes: 2 additions & 3 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
select = ["F", "E", "W", "C90", "B", "A", "C4", "G", "T20", "PT", "SLF", "TCH", "RET", "N", "ARG"]
ignore = ["E501"]

lint.select = ["F", "E", "W", "C90", "B", "A", "C4", "G", "T20", "PT", "SLF", "TCH", "RET", "N", "ARG"]
lint.ignore = ["E501"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 Benjamin Moran
Copyright (c) 2024 Benjamin Moran

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 11 additions & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
esper 3.3
=========
Maintenance release

Changes
-------
- Fix unreadable `esper.current_world` property. (#100)
- Minor typing configuration updates.
- Remove outdated pyglet example. (Another one already exists).


esper 3.2
=========
Maintenance release
Expand Down
40 changes: 18 additions & 22 deletions esper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from itertools import count as _count

__version__ = version = '3.2'
__version__ = version = '3.3'


###################
Expand Down Expand Up @@ -131,7 +131,7 @@ def process(self, *args: _Any, **kwargs: _Any) -> None:
# ECS functions
###################

_current_context: str = "default"
_current_world: str = "default"
_entity_count: "_count[int]" = _count(start=1)
_components: _Dict[_Type[_Any], _Set[_Any]] = {}
_entities: _Dict[int, _Dict[_Type[_Any], _Any]] = {}
Expand All @@ -141,8 +141,16 @@ def process(self, *args: _Any, **kwargs: _Any) -> None:
_processors: _List[Processor] = []
process_times: _Dict[str, int] = {}
event_registry: _Dict[str, _Any] = {}
current_world: str = "default"
"""The name of the currently active World context.
# {context_name: (entity_count, components, entities, dead_entities, comp_cache, comps_cache, processors, process_times, event_registry)}
This attribute can be checked to confirm the name of the
currently active World context. Modifying this has no effect;
to switch Worlds, use the :py:func:`~switch_world` function.
"""

# {context_name: (entity_count, components, entities, dead_entities,
# comp_cache, comps_cache, processors, process_times, event_registry)}
_context_map: _Dict[str, _Tuple[
"_count[int]",
_Dict[_Type[_Any], _Set[_Any]],
Expand Down Expand Up @@ -387,9 +395,7 @@ def get_component(component_type: _Type[_C]) -> _List[_Tuple[int, _C]]:
try:
return _get_component_cache[component_type]
except KeyError:
return _get_component_cache.setdefault(
component_type, list(_get_component(component_type))
)
return _get_component_cache.setdefault(component_type, list(_get_component(component_type)))


@_overload
Expand All @@ -404,7 +410,7 @@ def get_components(__c1: _Type[_C], __c2: _Type[_C2], __c3: _Type[_C3]) -> _List

@_overload
def get_components(__c1: _Type[_C], __c2: _Type[_C2], __c3: _Type[_C3], __c4: _Type[_C4]) -> _List[
_Tuple[int, _Tuple[_C, _C2, _C3, _C4]]]:
_Tuple[int, _Tuple[_C, _C2, _C3, _C4]]]:
...


Expand All @@ -413,9 +419,7 @@ def get_components(*component_types: _Type[_Any]) -> _Iterable[_Tuple[int, _Tupl
try:
return _get_components_cache[component_types]
except KeyError:
return _get_components_cache.setdefault(
component_types, list(_get_components(*component_types))
)
return _get_components_cache.setdefault(component_types, list(_get_components(*component_types)))


def try_component(entity: int, component_type: _Type[_C]) -> _Optional[_C]:
Expand Down Expand Up @@ -525,7 +529,7 @@ def delete_world(name: str) -> None:
Raises `PermissionError` if you attempt to delete the currently
active World context.
"""
if _current_context == name:
if _current_world == name:
raise PermissionError("The active World context cannot be deleted.")

del _context_map[name]
Expand All @@ -550,7 +554,7 @@ def switch_world(name: str) -> None:
# Create a new context if the name does not already exist:
_context_map[name] = (_count(start=1), {}, {}, set(), {}, {}, [], {}, {})

global _current_context
global _current_world
global _entity_count
global _components
global _entities
Expand All @@ -560,17 +564,9 @@ def switch_world(name: str) -> None:
global _processors
global process_times
global event_registry
global current_world

# switch the references to the objects in the named context_map:
(_entity_count, _components, _entities, _dead_entities, _get_component_cache,
_get_components_cache, _processors, process_times, event_registry) = _context_map[name]
_current_context = name


@property # type: ignore
def current_world() -> str:
"""The currently active World context.
To switch World contexts, see :py:func:`esper.switch_world`.
"""
return _current_context
_current_world = current_world = name
2 changes: 1 addition & 1 deletion examples/pyglet_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, minx, maxx, miny, maxy):
def process(self, dt):
# This will iterate over every Entity that has BOTH of these components:
for ent, (vel, rend) in esper.get_components(Velocity, Renderable):
# Update the Renderable Component's position by it's Velocity:
# Update the Renderable Component's position by its Velocity:
# An example of keeping the sprite inside screen boundaries. Basically,
# adjust the position back inside screen boundaries if it is outside:
new_x = max(self.minx, rend.sprite.x + vel.x)
Expand Down
245 changes: 0 additions & 245 deletions examples/pyglet_example_batch.py

This file was deleted.

0 comments on commit d95def2

Please sign in to comment.