afterglow/sim/tiles.pyΒΆ

Part of Afterglow.

 1"""Tile legend + flag helpers for the Afterglow logical sim.
 2
 3Pure data + predicates, GPU-free. Logical units are pixels, y-DOWN.
 4Static tiles ('#','^') live in the room grid; every dynamic char
 5('C','O','G','S','*','-','P','E') is spawned as an entity and its grid
 6cell is replaced with empty ('.').
 7
 8Legend (one char per tile):
 9  '.' empty | '#' solid | '^' spike/hazard | 'C' resonance crystal |
10  'O' glow orb | 'G' light-gate (solid only while glowing) | 'S' spring |
11  '*' hidden shard | '-' moving-platform anchor | 'P' player spawn |
12  'E' room exit | ' ' empty (treated as '.').
13"""
14
15from __future__ import annotations
16
17TILE_SIZE = 8
18
19EMPTY = "."
20SOLID = "#"
21HAZARD = "^"
22
23# Static, grid-resident chars.
24SOLID_CHARS: frozenset[str] = frozenset({SOLID})
25HAZARD_CHARS: frozenset[str] = frozenset({HAZARD})
26
27# Dynamic chars: become entities at parse time, leaving '.' in the grid.
28ENTITY_CHARS: frozenset[str] = frozenset({"C", "O", "G", "S", "*", "-", "P", "E"})
29
30# Every char an authored grid may legally contain.
31LEGAL_CHARS: frozenset[str] = frozenset({".", " ", "#", "^"}) | ENTITY_CHARS
32
33
34def is_solid(char: str) -> bool:
35    """True for static solid tiles (light-gates are dynamic entities, not this)."""
36    return char in SOLID_CHARS
37
38
39def is_hazard(char: str) -> bool:
40    """True for static hazard tiles (spikes)."""
41    return char in HAZARD_CHARS