[tool.ruff]
line-length = 79
-lint.select = ["E", "F", "UP", "B", "SIM", "I", "ARG", "N", "D", "ANN", "PYI"]
+#lint.select = ["E", "F", "UP", "B", "SIM", "I", "ARG", "N", "D", "ANN", "PYI"]
+lint.select = ["E", "F", "UP", "B", "SIM", "I", "ARG", "N", "ANN", "PYI"]
[tool.ruff.lint.pydocstyle]
convention = "google"
-from collections.abc import Callable, Generator, Iterable
from dataclasses import dataclass
from pathlib import Path
-from time import time
-from typing import Any, Literal, cast, overload
import pygame
from pygame import Vector2, Vector3
from pacman.ecs.hierarchy import (
- Children,
Parent,
hierachy_plugins,
traverse_hierarchy,
)
from pacman.ecs.schedule import (
MainSchedule,
- Schedule,
- ScheduleLabel,
StartupSchedule,
SystemSet,
UpdateSchedule,
def move_sprites(world: World) -> None:
import math
- time = pygame.time.get_ticks() / 100
+ tick = pygame.time.get_ticks() / 100
for coord, _ in world[tuple[Coord2D, WiggleSprite]]:
- pos = max(time - coord.z * 0.3, 0.0)
+ pos = max(tick - coord.z * 0.3, 0.0)
coord.y = 500.0 + math.sin(pos) * 30.0
def move_root(world: World) -> None:
import math
- time = pygame.time.get_ticks() / 100
+ tick = pygame.time.get_ticks() / 100
for coord, _ in world[tuple[Coord2D, WiggleRoot]]:
- coord.x = 30.0 + math.cos(time) * 30.0
+ coord.x = 30.0 + math.cos(tick) * 30.0
if __name__ == "__main__":
@property
def children(self) -> Generator[Entity]:
- for child in self._children:
- yield child
+ yield from self._children
__no_hook = False
"""Generate parents of entity including self"""
yield entity
while Parent in world[entity]:
- entity: Entity = world[entity][Parent]._parent
+ nxt: Entity = world[entity][Parent]._parent
+ entity = nxt
yield entity
def parent_remove_hook(
world: World, entity: Entity, component: Parent
) -> None:
- global __no_hook
if __no_hook:
return
world[component.parent][Children]._children.remove(entity)
params = sorted(
get_args(query), key=lambda e: len(world._components.get(e, {}))
)
- work = []
+ work: list[Entity] = []
for e in world.query(query, without=tuple[Parent, Children]):
yield (None, e)
for entity, children in world.query(
pre: Iterable[T | SystemSet],
post: Iterable[T | SystemSet],
group: Iterable[SystemSet],
- ):
+ ) -> None:
def get_pre(e: T | SystemSet) -> T | DAGLabel:
if isinstance(e, SystemSet):
return e._pre
+import contextlib
from collections.abc import Callable, Generator
from dataclasses import dataclass
from typing import Any, Literal, cast, get_args, overload
storage: type[T]
-class SkipSystem(Exception):
+class SkipSystemError(Exception):
pass
@overload
def __getitem__[T](self, arg: Resource[T]) -> T: ...
+
@overload
def __getitem__[*T](
self, arg: type[tuple[*T]]
) -> Generator[tuple[*T]]: ...
+
@overload
def __getitem__(self, arg: Entity) -> EntityThunk: ...
+
def __getitem__(
self,
arg: Any,
@overload
def __setitem__[T](self, key: Resource[T], val: T) -> None: ...
+
@overload
def __setitem__[*T](self, key: Entity, val: tuple[*T]) -> None: ...
+
def __setitem__(self, key: Any, val: Any) -> None:
if isinstance(key, Entity) and isinstance(val, tuple):
if key in self:
@overload
def __delitem__[T](self, key: Resource[T]) -> None: ...
+
@overload
def __delitem__(self, key: Entity) -> None: ...
+
def __delitem__[T](self, key: Entity | Resource[T]) -> None:
if isinstance(key, Entity):
components = self._entities[key]
if schedule not in self._schedules:
return
for system in self._schedules[schedule].traverse(self._run_cond):
- try:
+ with contextlib.suppress(SkipSystemError):
system(self)
- except SkipSystem:
- pass
def res_s[T](self, ty: type[T]) -> T:
if Resource(ty) not in self:
- raise SkipSystem()
+ raise SkipSystemError()
return self[Resource(ty)]
def run(
d[ty] = hook
else:
old = d[ty]
- d[ty] = lambda world, entity, component: (
- old(world, entity, component),
- hook(world, entity, component),
- )[1]
+
+ def new(world: World, entity: Entity, component: T) -> None:
+ old(world, entity, component)
+ hook(world, entity, component)
+ pass
+
+ d[ty] = new
return self
def with_plugins(self, *plugins: Plugin) -> "World":
)
sched.add_ordering((label,), self._pre, self._post, self._in_set)
if self._chain:
- prev = ()
+ prev: tuple[SystemSet | System] | tuple[()] = ()
for system in systems:
sched.add_ordering((system,), prev, (), (label,))
prev = (system,)