feat: evolution per player (optional)
This commit is contained in:
@@ -25,22 +25,25 @@ _PALETTE_RGB = [
|
||||
]
|
||||
|
||||
|
||||
def build_evolution_gif(event: Event) -> bytes:
|
||||
def build_evolution_gif(event: Event, usernames: list[str] | None = None) -> bytes:
|
||||
"""Renders `event`'s full placement history as an animated GIF, upscaled
|
||||
for visibility. Returns GIF bytes, even if there are zero placements.
|
||||
|
||||
If `usernames` is given, only those players' placements are replayed
|
||||
(combined on the same board).
|
||||
|
||||
Always replays at the *current* grid dimensions - a placement made
|
||||
before a resize that now falls outside them is skipped rather than
|
||||
raising."""
|
||||
place_settings = PlaceSettings.current(event)
|
||||
width, height = place_settings.width, place_settings.height
|
||||
|
||||
placements = (
|
||||
PixelPlacement.objects.filter(event=event)
|
||||
.order_by("placed_at")
|
||||
.values_list("x", "y", "color_index")
|
||||
placements = PixelPlacement.objects.filter(event=event)
|
||||
if usernames:
|
||||
placements = placements.filter(player__username__in=usernames)
|
||||
placements = list(
|
||||
placements.order_by("placed_at").values_list("x", "y", "color_index")
|
||||
)
|
||||
placements = list(placements)
|
||||
|
||||
grid = bytearray(width * height)
|
||||
frames: list[Image.Image] = []
|
||||
|
||||
Reference in New Issue
Block a user