Skip to content

Commit b274701

Browse files
committed
Move DIRECTION_KEYS to constants.py, remove eq=False
Backporting changes from part-3
1 parent d443e6d commit b274701

2 files changed

Lines changed: 39 additions & 35 deletions

File tree

game/constants.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Global constants are stored here."""
2+
3+
from typing import Final
4+
5+
from tcod.event import KeySym
6+
7+
DIRECTION_KEYS: Final = {
8+
# Arrow keys
9+
KeySym.LEFT: (-1, 0),
10+
KeySym.RIGHT: (1, 0),
11+
KeySym.UP: (0, -1),
12+
KeySym.DOWN: (0, 1),
13+
# Arrow key diagonals
14+
KeySym.HOME: (-1, -1),
15+
KeySym.END: (-1, 1),
16+
KeySym.PAGEUP: (1, -1),
17+
KeySym.PAGEDOWN: (1, 1),
18+
# Keypad
19+
KeySym.KP_4: (-1, 0),
20+
KeySym.KP_6: (1, 0),
21+
KeySym.KP_8: (0, -1),
22+
KeySym.KP_2: (0, 1),
23+
KeySym.KP_7: (-1, -1),
24+
KeySym.KP_1: (-1, 1),
25+
KeySym.KP_9: (1, -1),
26+
KeySym.KP_3: (1, 1),
27+
# VI keys
28+
KeySym.h: (-1, 0),
29+
KeySym.l: (1, 0),
30+
KeySym.k: (0, -1),
31+
KeySym.j: (0, 1),
32+
KeySym.y: (-1, -1),
33+
KeySym.b: (-1, 1),
34+
KeySym.u: (1, -1),
35+
KeySym.n: (1, 1),
36+
}

game/states.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,18 @@
11
"""A collection of game states."""
2-
from __future__ import annotations
32

4-
from typing import Final
3+
from __future__ import annotations
54

65
import attrs
76
import tcod.console
87
import tcod.event
9-
from tcod.event import KeySym
108

119
import g
1210
from game.components import Gold, Graphic, Position
11+
from game.constants import DIRECTION_KEYS
1312
from game.tags import IsItem, IsPlayer
1413

15-
DIRECTION_KEYS: Final = {
16-
# Arrow keys
17-
KeySym.LEFT: (-1, 0),
18-
KeySym.RIGHT: (1, 0),
19-
KeySym.UP: (0, -1),
20-
KeySym.DOWN: (0, 1),
21-
# Arrow key diagonals
22-
KeySym.HOME: (-1, -1),
23-
KeySym.END: (-1, 1),
24-
KeySym.PAGEUP: (1, -1),
25-
KeySym.PAGEDOWN: (1, 1),
26-
# Keypad
27-
KeySym.KP_4: (-1, 0),
28-
KeySym.KP_6: (1, 0),
29-
KeySym.KP_8: (0, -1),
30-
KeySym.KP_2: (0, 1),
31-
KeySym.KP_7: (-1, -1),
32-
KeySym.KP_1: (-1, 1),
33-
KeySym.KP_9: (1, -1),
34-
KeySym.KP_3: (1, 1),
35-
# VI keys
36-
KeySym.h: (-1, 0),
37-
KeySym.l: (1, 0),
38-
KeySym.k: (0, -1),
39-
KeySym.j: (0, 1),
40-
KeySym.y: (-1, -1),
41-
KeySym.b: (-1, 1),
42-
KeySym.u: (1, -1),
43-
KeySym.n: (1, 1),
44-
}
45-
4614

47-
@attrs.define(eq=False)
15+
@attrs.define()
4816
class InGame:
4917
"""Primary in-game state."""
5018

0 commit comments

Comments
 (0)