-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Module to hold Counter-Strike 2 data.""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
"""Dictionary that holds map data for Counter-Strike 2.""" | ||
|
||
# pos_x is upper left world coordinate | ||
MAP_DATA = { | ||
"ar_baggage": { | ||
"pos_x": -1316, | ||
"pos_y": 1288, | ||
"scale": 2.539062, | ||
"rotate": 1, | ||
"zoom": 1.3, | ||
"selections": [ | ||
{"name": "default", "altitude_max": 10000, "altitude_min": -5}, | ||
{"name": "lower", "altitude_max": -5, "altitude_min": -10000}, | ||
], | ||
}, | ||
"ar_shoots": { | ||
"pos_x": -1368, | ||
"pos_y": 1952, | ||
"scale": 2.687500, | ||
"rotate": None, | ||
"zoom": None, | ||
"selections": [], | ||
}, | ||
"cs_office": { | ||
"pos_x": -1838, | ||
"pos_y": 1858, | ||
"scale": 4.1, | ||
"rotate": None, | ||
"zoom": None, | ||
"selections": [], | ||
}, | ||
"cs_italy": { | ||
"pos_x": -2647, | ||
"pos_y": 2592, | ||
"scale": 4.6, | ||
"rotate": 1, | ||
"zoom": 1.5, | ||
"selections": [], | ||
}, | ||
"de_ancient": { | ||
"pos_x": -2953, | ||
"pos_y": 2164, | ||
"scale": 5, | ||
"rotate": 0, | ||
"zoom": 0, | ||
"selections": [], | ||
}, | ||
"de_anubis": { | ||
"pos_x": -2796, | ||
"pos_y": 3328, | ||
"scale": 5.22, | ||
"rotate": None, | ||
"zoom": None, | ||
"selections": [], | ||
}, | ||
"de_dust": { | ||
"pos_x": -2850, | ||
"pos_y": 4073, | ||
"scale": 6, | ||
"rotate": 1, | ||
"zoom": 1.3, | ||
"selections": [], | ||
}, | ||
"de_dust2": { | ||
"pos_x": -2476, | ||
"pos_y": 3239, | ||
"scale": 4.4, | ||
"rotate": 1, | ||
"zoom": 1.1, | ||
"selections": [], | ||
}, | ||
"de_inferno": { | ||
"pos_x": -2087, | ||
"pos_y": 3870, | ||
"scale": 4.9, | ||
"rotate": None, | ||
"zoom": None, | ||
"selections": [], | ||
}, | ||
"de_inferno_s2": { | ||
"pos_x": -2087, | ||
"pos_y": 3870, | ||
"scale": 4.9, | ||
"rotate": None, | ||
"zoom": None, | ||
"selections": [], | ||
}, | ||
"de_mirage": { | ||
"pos_x": -3230, | ||
"pos_y": 1713, | ||
"scale": 5, | ||
"rotate": 0, | ||
"zoom": 0, | ||
"selections": [], | ||
}, | ||
"de_nuke": { | ||
"pos_x": -3453, | ||
"pos_y": 2887, | ||
"scale": 7, | ||
"rotate": None, | ||
"zoom": None, | ||
"selections": [ | ||
{"name": "default", "altitude_max": 10000, "altitude_min": -495}, | ||
{"name": "lower", "altitude_max": -495, "altitude_min": -10000}, | ||
], | ||
}, | ||
"de_overpass": { | ||
"pos_x": -4831, | ||
"pos_y": 1781, | ||
"scale": 5.2, | ||
"rotate": 0, | ||
"zoom": 0, | ||
"selections": [], | ||
}, | ||
"de_vertigo": { | ||
"pos_x": -3168, | ||
"pos_y": 1762, | ||
"scale": 4, | ||
"rotate": None, | ||
"zoom": None, | ||
"selections": [ | ||
{"name": "default", "altitude_max": 20000, "altitude_min": 11700}, | ||
{"name": "lower", "altitude_max": 11700, "altitude_min": -10000}, | ||
], | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Contains map radar image files.""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"""Awpy visualization module.""" | ||
|
||
SIDE_COLORS = {"ct": "#5d79ae", "t": "#de9b35"} | ||
SUPPORTED_MAPS = ["de_dust2"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Module for plotting Counter-Strike data.""" | ||
|
||
import importlib.resources | ||
|
||
import matplotlib.image as mpimg | ||
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 5 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.10)
|
||
import matplotlib.pyplot as plt | ||
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 6 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.10)
|
||
from matplotlib.axes import Axes | ||
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 7 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.10)
|
||
from matplotlib.figure import Figure | ||
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 8 in awpy/viz/plot.py GitHub Actions / build (windows-latest, 3.10)
|
||
|
||
|
||
def plot_map(map_name: str, *, lower: bool = False) -> tuple[Figure, Axes]: | ||
"""Plot a Counter-Strike map. | ||
Args: | ||
map_name (str): Name of the map to plot. | ||
lower (bool, optional): Allows plotting the lower layer. Defaults to False. | ||
Raises: | ||
FileNotFoundError: Raises a FileNotFoundError if the map image is not found. | ||
Returns: | ||
tuple[Figure, Axes]: Matplotlib Figure and Axes objects. | ||
""" | ||
if lower is True: | ||
map_name += "_lower" | ||
|
||
with importlib.resources.path("awpy.data.maps", f"{map_name}.png") as map_img_path: | ||
if not map_img_path.exists(): | ||
map_img_not_found_msg = f"Map image not found: {map_img_path}" | ||
raise FileNotFoundError(map_img_not_found_msg) | ||
|
||
map_bg = mpimg.imread(map_img_path) | ||
|
||
figure, axes = plt.subplots() | ||
axes.imshow(map_bg, zorder=0) | ||
return figure, axes |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"""Utilities for plotting and visualization.""" | ||
|
||
from typing import Literal | ||
|
||
from awpy.data.map_data import MAP_DATA | ||
|
||
|
||
# Position function courtesy of PureSkill.gg | ||
def position_transform_axis( | ||
map_name: str, position: float, axis: Literal["x", "y"] | ||
) -> float: | ||
"""Transforms an X or Y-axis value. | ||
Args: | ||
map_name (str): Map to search | ||
position (float): X or Y coordinate | ||
axis (str): Either "x" or "y" | ||
Returns: | ||
float: Transformed position | ||
Raises: | ||
ValueError: Raises a ValueError if axis not 'x' or 'y' | ||
""" | ||
axis = axis.lower() | ||
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.10)
Check failure on line 25 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.11)
|
||
if axis not in ["x", "y"]: | ||
msg = f"'axis' has to be 'x' or 'y', not {axis}" | ||
raise ValueError(msg) | ||
start = MAP_DATA[map_name]["pos_" + axis] | ||
scale = MAP_DATA[map_name]["scale"] | ||
|
||
if axis == "x": | ||
return (position - start) / scale | ||
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.10)
Check failure on line 33 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.11)
|
||
return (start - position) / scale | ||
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.10)
Check failure on line 34 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.11)
|
||
|
||
|
||
def position_transform( | ||
map_name: str, position: tuple[float, float, float] | ||
) -> tuple[float, float, float]: | ||
"""Transforms an single coordinate (X,Y,Z). | ||
Args: | ||
map_name (str): Map to transform coordinates. | ||
position (tuple): (X,Y,Z) coordinates. | ||
Returns: | ||
Tuple[float, float, float]: Transformed coordinates (X,Y,Z). | ||
""" | ||
return ( | ||
position_transform_axis(map_name, position[0], "x"), | ||
position_transform_axis(map_name, position[1], "y"), | ||
position[2], | ||
) | ||
|
||
|
||
def is_position_on_lower_level( | ||
map_name: str, position: tuple[float, float, float] | ||
) -> bool: | ||
"""Check if a position is on a lower level of a map. | ||
Args: | ||
map_name (str): Map to check the position level. | ||
position (Tuple[float, float, float]): (X,Y,Z) coordinates. | ||
Returns: | ||
bool: True if the position on the lower level, False otherwise. | ||
""" | ||
metadata = MAP_DATA[map_name] | ||
if len(metadata["selections"]) == 0: | ||
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.10)
Check failure on line 69 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.11)
|
||
return False | ||
|
||
for level in metadata["selections"]: | ||
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.11)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.10)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.12)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.12)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.11)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.10)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (ubuntu-latest, 3.9)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (macos-latest, 3.9)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.12)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.9)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.10)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.10)
Check failure on line 72 in awpy/viz/utils.py GitHub Actions / build (windows-latest, 3.11)
|
||
if position[2] > level["altitude_max"] and position[2] <= level["altitude_min"]: | ||
return True | ||
|
||
return False |