-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_logging.py
84 lines (64 loc) · 3.12 KB
/
game_logging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from loguru import logger
from events import (
EventsManager,
OnKeyPress,
OnKeyRelease,
OnLeftMousePress,
OnRightMousePress,
OnLeftMouseRelease,
OnRightMouseRelease,
)
from utils import coordinate_to_grid
from layout import layout_manager, LAYOUTS
import arcade
def log_left_mouse_press(game, event: OnLeftMousePress, em: EventsManager):
if layout_manager.on_layout(LAYOUTS.GRID, event.x, event.y):
row, column = coordinate_to_grid(event.x, event.y)
logger.debug(
f"Left mouse press on cell. Coordinates: ({event.x}, {event.y}). Grid coordinates: ({row}, {column}), Height: {game.map.height_map[row][column]}, Color: {game.cell_sprites_2d[row][column].color}"
)
return
logger.debug(f"Left mouse press on sidebar. Coordinates: ({event.x}, {event.y}).")
def log_right_mouse_press(game, event: OnRightMousePress, em: EventsManager):
if layout_manager.on_layout(LAYOUTS.GRID, event.x, event.y):
row, column = coordinate_to_grid(event.x, event.y)
logger.debug(
f"Right mouse press on cell. Coordinates: ({event.x}, {event.y}). Grid coordinates: ({row}, {column}), Height: {game.map.height_map[row][column]}, Color: {game.cell_sprites_2d[row][column].color}"
)
return
logger.debug(f"Right mouse press on sidebar. Coordinates: ({event.x}, {event.y}).")
def log_left_mouse_release(game, event: OnLeftMouseRelease, em: EventsManager):
if layout_manager.on_layout(LAYOUTS.GRID, event.x, event.y):
row, column = coordinate_to_grid(event.x, event.y)
logger.debug(
f"Left mouse release on cell. Coordinates: ({event.x}, {event.y}). Grid coordinates: ({row}, {column}), Height: {game.map.height_map[row][column]}, Color: {game.cell_sprites_2d[row][column].color}"
)
return
logger.debug(f"Left mouse release on sidebar. Coordinates: ({event.x}, {event.y}).")
def log_right_mouse_release(game, event: OnRightMouseRelease, em: EventsManager):
if layout_manager.on_layout(LAYOUTS.GRID, event.x, event.y):
row, column = coordinate_to_grid(event.x, event.y)
logger.debug(
f"Right mouse release on cell. Coordinates: ({event.x}, {event.y}). Grid coordinates: ({row}, {column}), Height: {game.map.height_map[row][column]}, Color: {game.cell_sprites_2d[row][column].color}"
)
return
logger.debug(
f"Right mouse release on sidebar. Coordinates: ({event.x}, {event.y})."
)
def get_key_by_value(value):
for key, val in arcade.key.__dict__.items():
if val == value:
return key
return None
def log_key_press(game, event: OnKeyPress, em: EventsManager):
logger.debug(f"Key pressed: {get_key_by_value(event.key)}")
def log_key_release(game, event: OnKeyRelease, em: EventsManager):
logger.debug(f"Key released: {get_key_by_value(event.key)}")
subscriptions = {
OnLeftMouseRelease: log_left_mouse_release,
OnRightMouseRelease: log_right_mouse_release,
OnLeftMousePress: log_left_mouse_press,
OnRightMousePress: log_right_mouse_press,
OnKeyPress: log_key_press,
OnKeyRelease: log_key_release,
}