"""Check progress colors in actual guest frames, including enlarged map views.""" import re from pathlib import Path ROOT = Path(__file__).resolve().parents[1] LIGHT = (85, 170, 170) DARK = (85, 85, 170) RED = (255, 85, 85) YELLOW = (255, 255, 0) NORTHEAST = {6, 7, 18, 19, 20, 28, 29, 31, 37, 38, 44} SOURCE = (ROOT / 'src/map_data.c').read_text() def numbers(pattern): return list(map(int, re.search(pattern, SOURCE)[1].replace('\n', '').split(','))) GEOMETRY = { view: (numbers(view + r'_spans\[\] = \{\s*([\d,\s]+)'), numbers(view + r'_offsets\[51\] = \{([\d,]+)')) for view in ('national', 'northeast', 'hawaii') } def check_map_colors(screen, current, outcomes): """outcomes maps answered state IDs to correctness; None selects title mode.""" views = [('national', 6, 33)] if current in NORTHEAST: views.append(('northeast', 211, 42)) elif current == 10: views.append(('hawaii', 211, 53)) checked = {} for view, ox, oy in views: spans, offsets = GEOMETRY[view] pixels = 0 for state in range(50): expected = LIGHT if current is not None: if state == current: expected = YELLOW elif state in outcomes: expected = DARK if outcomes[state] else RED for k in range(offsets[state], offsets[state + 1], 3): y, x, count = spans[k:k + 3] for dx in range(count): xx, yy = ox + x + dx, oy + y # Labels and the northeast overview marker cover map pixels. if view == 'national': if 134 <= yy < 142 and (8 <= xx < 20 or 62 <= xx < 74): continue if current in NORTHEAST and ( (xx in (158, 199) and 44 <= yy <= 88) or (yy in (44, 88) and 158 <= xx <= 199) ): continue actual = screen.guest(xx, yy) assert actual == expected, (view, state, current, xx, yy, actual, expected) pixels += 1 checked[view] = pixels return checked