thenuke02/cs2-analyzer
0
1"""CS2 map metadata for coordinate transformation.2 3Thin wrapper around visualization.radar.MAP_DATA to avoid duplication.4All coordinate data is defined once in radar.py (the authoritative source).5 6To convert game coordinates to radar pixel coordinates:7 pixel_x = (game_x - pos_x) / scale8 pixel_y = (pos_y - game_y) / scale # Y is inverted9 10Radar images are 1024x1024 pixels.11"""12 13from opensight.visualization.radar import MAP_DATA14 15# Derive MAP_METADATA from the authoritative MAP_DATA in radar.py16MAP_METADATA: dict[str, dict[str, float]] = {17 map_name: {"pos_x": data["pos_x"], "pos_y": data["pos_y"], "scale": data["scale"]}18 for map_name, data in MAP_DATA.items()19}20 21# Image dimensions (all CS2 radar images are 1024x1024)22RADAR_IMAGE_SIZE = 102423 24 25def get_map_metadata(map_name: str) -> dict | None:26 """Get coordinate transformation metadata for a map.27 28 Args:29 map_name: Map name with or without 'de_' prefix30 31 Returns:32 Dict with pos_x, pos_y, scale, or None if unknown map33 """34 # Normalize map name35 if not map_name.startswith("de_") and not map_name.startswith("cs_"):36 map_name = f"de_{map_name}"37 map_name = map_name.lower().strip()38 39 return MAP_METADATA.get(map_name)40 41 42def game_to_pixel(game_x: float, game_y: float, map_name: str) -> tuple[float, float] | None:43 """Convert game world coordinates to radar pixel coordinates.44 45 Args:46 game_x: X position in game world units47 game_y: Y position in game world units48 map_name: CS2 map name49 50 Returns:51 Tuple of (pixel_x, pixel_y) or None if unknown map52 """53 meta = get_map_metadata(map_name)54 if meta is None:55 return None56 57 pixel_x = (game_x - meta["pos_x"]) / meta["scale"]58 pixel_y = (meta["pos_y"] - game_y) / meta["scale"] # Y inverted59 60 return (pixel_x, pixel_y)61 