coord.x = 30.0 + math.cos(tick) * 30.0
-def sprite_despawn_hook() -> RawComponentHook[WiggleSprite]:
- def inner(arg: RawComponentArg[WiggleSprite]) -> None:
- for ent, _ in arg:
- continue
- print("despawn", ent)
-
- return inner
-
-
-def sprite_spawn_hook() -> RawComponentHook[WiggleSprite]:
- def inner(arg: RawComponentArg[WiggleSprite]) -> None:
- for ent, _ in arg:
- continue
- print("spawn", ent)
-
- return inner
-
-
-def unspawn_wiggle(
- queue: CommandQueue, q: Query[Entity, WiggleSprite]
-) -> None:
- lst = [(e, WiggleSprite()) for _, e in zip(range(3), q, strict=False)]
- queue.queue(lambda world: world.insert_many(WiggleSprite, lst))
-
-
-def close_on_empty(world: World, q: Query[Entity, WiggleSprite]) -> None:
- if next(iter(q), None) is None:
- world.spawn(WorldShouldExit, WorldShouldExit())
-
-
if __name__ == "__main__":
world = (
World()
UpdateSchedule,
move_sprites,
move_root,
- unspawn_wiggle,
- close_on_empty,
)
- .with_hook("remove", WiggleSprite, sprite_despawn_hook)
- .with_hook("insert", WiggleSprite, sprite_spawn_hook)
)
assets = list(Path("./asset").rglob("*.png"))
root = world.spawn(
from collections.abc import Callable, Generator
from typing import cast
-type VarargCallable[T, U] = (
- Callable[[T], U]
- | Callable[[T, T], U]
- | Callable[[T, T, T], U]
- | Callable[[T, T, T, T], U]
- | Callable[[T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T, T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T, T, T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T, T, T, T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T, T, T, T, T, T, T, T, T], U]
- | Callable[[T, T, T, T, T, T, T, T, T, T, T, T, T, T, T], U]
-)
-
type RecursiveTuple[T] = T | tuple[RecursiveTuple[T], ...]