mini-arcade-core 0.8.1__py3-none-any.whl → 0.9.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mini_arcade_core/__init__.py +3 -0
- mini_arcade_core/backend.py +59 -3
- mini_arcade_core/keymaps/__init__.py +0 -0
- mini_arcade_core/keymaps/sdl.py +98 -0
- mini_arcade_core/keys.py +160 -0
- {mini_arcade_core-0.8.1.dist-info → mini_arcade_core-0.9.1.dist-info}/METADATA +1 -1
- {mini_arcade_core-0.8.1.dist-info → mini_arcade_core-0.9.1.dist-info}/RECORD +9 -6
- {mini_arcade_core-0.8.1.dist-info → mini_arcade_core-0.9.1.dist-info}/WHEEL +0 -0
- {mini_arcade_core-0.8.1.dist-info → mini_arcade_core-0.9.1.dist-info}/licenses/LICENSE +0 -0
mini_arcade_core/__init__.py
CHANGED
|
@@ -19,6 +19,7 @@ from .collision2d import RectCollider
|
|
|
19
19
|
from .entity import Entity, KinematicEntity, SpriteEntity
|
|
20
20
|
from .game import Game, GameConfig
|
|
21
21
|
from .geometry2d import Bounds2D, Position2D, Size2D
|
|
22
|
+
from .keys import Key, keymap
|
|
22
23
|
from .kinematics2d import KinematicData
|
|
23
24
|
from .physics2d import Velocity2D
|
|
24
25
|
from .scene import Scene
|
|
@@ -69,6 +70,8 @@ __all__ = [
|
|
|
69
70
|
"VerticalWrap",
|
|
70
71
|
"RectSprite",
|
|
71
72
|
"RectKinematic",
|
|
73
|
+
"Key",
|
|
74
|
+
"keymap",
|
|
72
75
|
]
|
|
73
76
|
|
|
74
77
|
PACKAGE_NAME = "mini-arcade-core" # or whatever is in your pyproject.toml
|
mini_arcade_core/backend.py
CHANGED
|
@@ -7,7 +7,9 @@ from __future__ import annotations
|
|
|
7
7
|
|
|
8
8
|
from dataclasses import dataclass
|
|
9
9
|
from enum import Enum, auto
|
|
10
|
-
from typing import Iterable, Protocol, Tuple, Union
|
|
10
|
+
from typing import Iterable, Optional, Protocol, Tuple, Union
|
|
11
|
+
|
|
12
|
+
from .keys import Key
|
|
11
13
|
|
|
12
14
|
Color = Union[Tuple[int, int, int], Tuple[int, int, int, int]]
|
|
13
15
|
|
|
@@ -20,14 +22,33 @@ class EventType(Enum):
|
|
|
20
22
|
:cvar QUIT: User requested to quit the game.
|
|
21
23
|
:cvar KEYDOWN: A key was pressed.
|
|
22
24
|
:cvar KEYUP: A key was released.
|
|
25
|
+
:cvar MOUSEMOTION: The mouse was moved.
|
|
26
|
+
:cvar MOUSEBUTTONDOWN: A mouse button was pressed.
|
|
27
|
+
:cvar MOUSEBUTTONUP: A mouse button was released.
|
|
28
|
+
:cvar MOUSEWHEEL: The mouse wheel was scrolled.
|
|
29
|
+
:cvar WINDOWRESIZED: The window was resized.
|
|
30
|
+
:cvar TEXTINPUT: Text input event (for IME support).
|
|
23
31
|
"""
|
|
24
32
|
|
|
25
33
|
UNKNOWN = auto()
|
|
26
34
|
QUIT = auto()
|
|
35
|
+
|
|
27
36
|
KEYDOWN = auto()
|
|
28
37
|
KEYUP = auto()
|
|
29
38
|
|
|
39
|
+
# Mouse
|
|
40
|
+
MOUSEMOTION = auto()
|
|
41
|
+
MOUSEBUTTONDOWN = auto()
|
|
42
|
+
MOUSEBUTTONUP = auto()
|
|
43
|
+
MOUSEWHEEL = auto()
|
|
44
|
+
|
|
45
|
+
# Window / text
|
|
46
|
+
WINDOWRESIZED = auto()
|
|
47
|
+
TEXTINPUT = auto()
|
|
30
48
|
|
|
49
|
+
|
|
50
|
+
# Justification: Simple data container for now
|
|
51
|
+
# pylint: disable=too-many-instance-attributes
|
|
31
52
|
@dataclass(frozen=True)
|
|
32
53
|
class Event:
|
|
33
54
|
"""
|
|
@@ -38,11 +59,46 @@ class Event:
|
|
|
38
59
|
- key: integer key code (e.g. ESC = 27), or None if not applicable
|
|
39
60
|
|
|
40
61
|
:ivar type (EventType): The type of event.
|
|
41
|
-
:ivar key (
|
|
62
|
+
:ivar key (Key | None): The key associated with the event, if any.
|
|
63
|
+
:ivar key_code (int | None): The key code associated with the event, if any.
|
|
64
|
+
:ivar scancode (int | None): The hardware scancode of the key, if any.
|
|
65
|
+
:ivar mod (int | None): Modifier keys bitmask, if any.
|
|
66
|
+
:ivar repeat (bool | None): Whether this key event is a repeat, if any.
|
|
67
|
+
:ivar x (int | None): Mouse X position, if any.
|
|
68
|
+
:ivar y (int | None): Mouse Y position, if any.
|
|
69
|
+
:ivar dx (int | None): Mouse delta X, if any.
|
|
70
|
+
:ivar dy (int | None): Mouse delta Y, if any.
|
|
71
|
+
:ivar button (int | None): Mouse button number, if any.
|
|
72
|
+
:ivar wheel (Tuple[int, int] | None): Mouse wheel scroll (x, y), if any.
|
|
73
|
+
:ivar size (Tuple[int, int] | None): New window size (width, height), if any.
|
|
74
|
+
:ivar text (str | None): Text input, if any.
|
|
42
75
|
"""
|
|
43
76
|
|
|
44
77
|
type: EventType
|
|
45
|
-
key:
|
|
78
|
+
key: Key | None = None # Use Key enum for better clarity
|
|
79
|
+
key_code: Optional[int] = None
|
|
80
|
+
|
|
81
|
+
# Keyboard extras (optional)
|
|
82
|
+
scancode: Optional[int] = None
|
|
83
|
+
mod: Optional[int] = None
|
|
84
|
+
repeat: Optional[bool] = None
|
|
85
|
+
|
|
86
|
+
# Mouse (optional)
|
|
87
|
+
x: Optional[int] = None
|
|
88
|
+
y: Optional[int] = None
|
|
89
|
+
dx: Optional[int] = None
|
|
90
|
+
dy: Optional[int] = None
|
|
91
|
+
button: Optional[int] = None
|
|
92
|
+
wheel: Optional[Tuple[int, int]] = None # (wheel_x, wheel_y)
|
|
93
|
+
|
|
94
|
+
# Window (optional)
|
|
95
|
+
size: Optional[Tuple[int, int]] = None # (width, height)
|
|
96
|
+
|
|
97
|
+
# Text input (optional)
|
|
98
|
+
text: Optional[str] = None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# pylint: enable=too-many-instance-attributes
|
|
46
102
|
|
|
47
103
|
|
|
48
104
|
class Backend(Protocol):
|
|
File without changes
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SDL keymap for mini arcade core.
|
|
3
|
+
Maps SDL keycodes to mini arcade core Key enums.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from mini_arcade_core.keys import Key
|
|
9
|
+
|
|
10
|
+
# SDL keycodes you need (minimal set)
|
|
11
|
+
SDLK_ESCAPE = 27
|
|
12
|
+
SDLK_RETURN = 13
|
|
13
|
+
SDLK_SPACE = 32
|
|
14
|
+
SDLK_TAB = 9
|
|
15
|
+
SDLK_BACKSPACE = 8
|
|
16
|
+
|
|
17
|
+
SDLK_UP = 1073741906
|
|
18
|
+
SDLK_DOWN = 1073741905
|
|
19
|
+
SDLK_LEFT = 1073741904
|
|
20
|
+
SDLK_RIGHT = 1073741903
|
|
21
|
+
|
|
22
|
+
F1 = 1073741882
|
|
23
|
+
F2 = 1073741883
|
|
24
|
+
F3 = 1073741884
|
|
25
|
+
F4 = 1073741885
|
|
26
|
+
F5 = 1073741886
|
|
27
|
+
F6 = 1073741887
|
|
28
|
+
F7 = 1073741888
|
|
29
|
+
F8 = 1073741889
|
|
30
|
+
F9 = 1073741890
|
|
31
|
+
F10 = 1073741891
|
|
32
|
+
F11 = 1073741892
|
|
33
|
+
F12 = 1073741893
|
|
34
|
+
|
|
35
|
+
SDL_KEYCODE_TO_KEY: dict[int, Key] = {
|
|
36
|
+
# Letters
|
|
37
|
+
ord("a"): Key.A,
|
|
38
|
+
ord("b"): Key.B,
|
|
39
|
+
ord("c"): Key.C,
|
|
40
|
+
ord("d"): Key.D,
|
|
41
|
+
ord("e"): Key.E,
|
|
42
|
+
ord("f"): Key.F,
|
|
43
|
+
ord("g"): Key.G,
|
|
44
|
+
ord("h"): Key.H,
|
|
45
|
+
ord("i"): Key.I,
|
|
46
|
+
ord("j"): Key.J,
|
|
47
|
+
ord("k"): Key.K,
|
|
48
|
+
ord("l"): Key.L,
|
|
49
|
+
ord("m"): Key.M,
|
|
50
|
+
ord("n"): Key.N,
|
|
51
|
+
ord("o"): Key.O,
|
|
52
|
+
ord("p"): Key.P,
|
|
53
|
+
ord("q"): Key.Q,
|
|
54
|
+
ord("r"): Key.R,
|
|
55
|
+
ord("s"): Key.S,
|
|
56
|
+
ord("t"): Key.T,
|
|
57
|
+
ord("u"): Key.U,
|
|
58
|
+
ord("v"): Key.V,
|
|
59
|
+
ord("w"): Key.W,
|
|
60
|
+
ord("x"): Key.X,
|
|
61
|
+
ord("y"): Key.Y,
|
|
62
|
+
ord("z"): Key.Z,
|
|
63
|
+
# Arrows
|
|
64
|
+
SDLK_UP: Key.UP,
|
|
65
|
+
SDLK_DOWN: Key.DOWN,
|
|
66
|
+
SDLK_LEFT: Key.LEFT,
|
|
67
|
+
SDLK_RIGHT: Key.RIGHT,
|
|
68
|
+
# Common
|
|
69
|
+
SDLK_ESCAPE: Key.ESCAPE,
|
|
70
|
+
SDLK_SPACE: Key.SPACE,
|
|
71
|
+
SDLK_RETURN: Key.ENTER,
|
|
72
|
+
SDLK_TAB: Key.TAB,
|
|
73
|
+
SDLK_BACKSPACE: Key.BACKSPACE,
|
|
74
|
+
# Numbers
|
|
75
|
+
ord("0"): Key.NUM_0,
|
|
76
|
+
ord("1"): Key.NUM_1,
|
|
77
|
+
ord("2"): Key.NUM_2,
|
|
78
|
+
ord("3"): Key.NUM_3,
|
|
79
|
+
ord("4"): Key.NUM_4,
|
|
80
|
+
ord("5"): Key.NUM_5,
|
|
81
|
+
ord("6"): Key.NUM_6,
|
|
82
|
+
ord("7"): Key.NUM_7,
|
|
83
|
+
ord("8"): Key.NUM_8,
|
|
84
|
+
ord("9"): Key.NUM_9,
|
|
85
|
+
# Function keys
|
|
86
|
+
F1: Key.F1,
|
|
87
|
+
F2: Key.F2,
|
|
88
|
+
F3: Key.F3,
|
|
89
|
+
F4: Key.F4,
|
|
90
|
+
F5: Key.F5,
|
|
91
|
+
F6: Key.F6,
|
|
92
|
+
F7: Key.F7,
|
|
93
|
+
F8: Key.F8,
|
|
94
|
+
F9: Key.F9,
|
|
95
|
+
F10: Key.F10,
|
|
96
|
+
F11: Key.F11,
|
|
97
|
+
F12: Key.F12,
|
|
98
|
+
}
|
mini_arcade_core/keys.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Mini Arcade Core key definitions.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from enum import Enum, auto
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Key(Enum):
|
|
12
|
+
"""
|
|
13
|
+
Enumeration of common keyboard keys.
|
|
14
|
+
|
|
15
|
+
:ivar A-Z: Letter keys.
|
|
16
|
+
:ivar arrow_up, arrow_down, arrow_left, arrow_right: Arrow keys.
|
|
17
|
+
:ivar escape, space, enter, tab, backspace: Common control keys.
|
|
18
|
+
:ivar num_0 - num_9: Number keys.
|
|
19
|
+
:ivar f1 - f12: Function keys.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
# Letters
|
|
23
|
+
A = auto()
|
|
24
|
+
B = auto()
|
|
25
|
+
C = auto()
|
|
26
|
+
D = auto()
|
|
27
|
+
E = auto()
|
|
28
|
+
F = auto()
|
|
29
|
+
G = auto()
|
|
30
|
+
H = auto()
|
|
31
|
+
I = auto()
|
|
32
|
+
J = auto()
|
|
33
|
+
K = auto()
|
|
34
|
+
L = auto()
|
|
35
|
+
M = auto()
|
|
36
|
+
N = auto()
|
|
37
|
+
O = auto()
|
|
38
|
+
P = auto()
|
|
39
|
+
Q = auto()
|
|
40
|
+
R = auto()
|
|
41
|
+
S = auto()
|
|
42
|
+
T = auto()
|
|
43
|
+
U = auto()
|
|
44
|
+
V = auto()
|
|
45
|
+
W = auto()
|
|
46
|
+
X = auto()
|
|
47
|
+
Y = auto()
|
|
48
|
+
Z = auto()
|
|
49
|
+
|
|
50
|
+
# Arrows
|
|
51
|
+
UP = auto()
|
|
52
|
+
DOWN = auto()
|
|
53
|
+
LEFT = auto()
|
|
54
|
+
RIGHT = auto()
|
|
55
|
+
|
|
56
|
+
# Common
|
|
57
|
+
ESCAPE = auto()
|
|
58
|
+
SPACE = auto()
|
|
59
|
+
ENTER = auto()
|
|
60
|
+
TAB = auto()
|
|
61
|
+
BACKSPACE = auto()
|
|
62
|
+
|
|
63
|
+
# Numbers
|
|
64
|
+
NUM_0 = auto()
|
|
65
|
+
NUM_1 = auto()
|
|
66
|
+
NUM_2 = auto()
|
|
67
|
+
NUM_3 = auto()
|
|
68
|
+
NUM_4 = auto()
|
|
69
|
+
NUM_5 = auto()
|
|
70
|
+
NUM_6 = auto()
|
|
71
|
+
NUM_7 = auto()
|
|
72
|
+
NUM_8 = auto()
|
|
73
|
+
NUM_9 = auto()
|
|
74
|
+
|
|
75
|
+
# Function keys
|
|
76
|
+
F1 = auto()
|
|
77
|
+
F2 = auto()
|
|
78
|
+
F3 = auto()
|
|
79
|
+
F4 = auto()
|
|
80
|
+
F5 = auto()
|
|
81
|
+
F6 = auto()
|
|
82
|
+
F7 = auto()
|
|
83
|
+
F8 = auto()
|
|
84
|
+
F9 = auto()
|
|
85
|
+
F10 = auto()
|
|
86
|
+
F11 = auto()
|
|
87
|
+
F12 = auto()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# Justification: Simple alias object for keys
|
|
91
|
+
# pylint: disable=too-many-instance-attributes
|
|
92
|
+
@dataclass(frozen=True)
|
|
93
|
+
class _Keys:
|
|
94
|
+
# alias object so user code can do keys.w, keys.arrow_up, etc.
|
|
95
|
+
a: Key = Key.A
|
|
96
|
+
b: Key = Key.B
|
|
97
|
+
c: Key = Key.C
|
|
98
|
+
d: Key = Key.D
|
|
99
|
+
e: Key = Key.E
|
|
100
|
+
f: Key = Key.F
|
|
101
|
+
g: Key = Key.G
|
|
102
|
+
h: Key = Key.H
|
|
103
|
+
i: Key = Key.I
|
|
104
|
+
j: Key = Key.J
|
|
105
|
+
k: Key = Key.K
|
|
106
|
+
l: Key = Key.L
|
|
107
|
+
m: Key = Key.M
|
|
108
|
+
n: Key = Key.N
|
|
109
|
+
o: Key = Key.O
|
|
110
|
+
p: Key = Key.P
|
|
111
|
+
q: Key = Key.Q
|
|
112
|
+
r: Key = Key.R
|
|
113
|
+
s: Key = Key.S
|
|
114
|
+
t: Key = Key.T
|
|
115
|
+
u: Key = Key.U
|
|
116
|
+
v: Key = Key.V
|
|
117
|
+
w: Key = Key.W
|
|
118
|
+
x: Key = Key.X
|
|
119
|
+
y: Key = Key.Y
|
|
120
|
+
z: Key = Key.Z
|
|
121
|
+
|
|
122
|
+
up: Key = Key.UP
|
|
123
|
+
down: Key = Key.DOWN
|
|
124
|
+
left: Key = Key.LEFT
|
|
125
|
+
right: Key = Key.RIGHT
|
|
126
|
+
|
|
127
|
+
escape: Key = Key.ESCAPE
|
|
128
|
+
space: Key = Key.SPACE
|
|
129
|
+
enter: Key = Key.ENTER
|
|
130
|
+
tab: Key = Key.TAB
|
|
131
|
+
backspace: Key = Key.BACKSPACE
|
|
132
|
+
|
|
133
|
+
num_0: Key = Key.NUM_0
|
|
134
|
+
num_1: Key = Key.NUM_1
|
|
135
|
+
num_2: Key = Key.NUM_2
|
|
136
|
+
num_3: Key = Key.NUM_3
|
|
137
|
+
num_4: Key = Key.NUM_4
|
|
138
|
+
num_5: Key = Key.NUM_5
|
|
139
|
+
num_6: Key = Key.NUM_6
|
|
140
|
+
num_7: Key = Key.NUM_7
|
|
141
|
+
num_8: Key = Key.NUM_8
|
|
142
|
+
num_9: Key = Key.NUM_9
|
|
143
|
+
|
|
144
|
+
f1: Key = Key.F1
|
|
145
|
+
f2: Key = Key.F2
|
|
146
|
+
f3: Key = Key.F3
|
|
147
|
+
f4: Key = Key.F4
|
|
148
|
+
f5: Key = Key.F5
|
|
149
|
+
f6: Key = Key.F6
|
|
150
|
+
f7: Key = Key.F7
|
|
151
|
+
f8: Key = Key.F8
|
|
152
|
+
f9: Key = Key.F9
|
|
153
|
+
f10: Key = Key.F10
|
|
154
|
+
f11: Key = Key.F11
|
|
155
|
+
f12: Key = Key.F12
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# pylint: enable=too-many-instance-attributes
|
|
159
|
+
|
|
160
|
+
keymap = _Keys()
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
mini_arcade_core/__init__.py,sha256=
|
|
2
|
-
mini_arcade_core/backend.py,sha256=
|
|
1
|
+
mini_arcade_core/__init__.py,sha256=7Ioji-MpfSQq4Ok3agVzP4mvcTNiThrY-DTDmVYFKo0,2609
|
|
2
|
+
mini_arcade_core/backend.py,sha256=tmMLv0H0rTGgo_hitIKfHU9S9oqtR3qUAwAgKGZS2-w,6505
|
|
3
3
|
mini_arcade_core/boundaries2d.py,sha256=H1HkCR1422MkQIEve2DFKvnav4RpvtLx-qTMxzmdDMQ,2610
|
|
4
4
|
mini_arcade_core/collision2d.py,sha256=iq800wsoYQNft3SA-W4jeY1wXhbpz2E7IkIorZBI238,1718
|
|
5
5
|
mini_arcade_core/entity.py,sha256=1AuE-_iMJYHxSyG783fsyByKK8Gx4vWWKMCEPjtgHXw,1776
|
|
6
6
|
mini_arcade_core/game.py,sha256=2DaFRdu7ogrwukh2MRnTh0Hy2r1XcaGSHEpLBNxfqIU,7273
|
|
7
7
|
mini_arcade_core/geometry2d.py,sha256=js791mMpsE_YbEoqtTOsOxNSflvKgSk6VeVKhj9N318,1282
|
|
8
|
+
mini_arcade_core/keymaps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
mini_arcade_core/keymaps/sdl.py,sha256=lRBvgTfdT7enN0qV7S2ZoLsPAWpaiSHzsyVGDlyTzQA,1924
|
|
10
|
+
mini_arcade_core/keys.py,sha256=LTg20SwLBI3kpPIiTNpq2yBft_QUGj-iNFSNm9M-Fus,3010
|
|
8
11
|
mini_arcade_core/kinematics2d.py,sha256=twBx-1jEwdknIJEyYBUg4VZyAvw1d7pGHaGFd36TPbo,2085
|
|
9
12
|
mini_arcade_core/physics2d.py,sha256=qIq86qWVuvcnLIMEPH6xx7XQO4tQhfiMZY6FseuVOR8,1636
|
|
10
13
|
mini_arcade_core/scene.py,sha256=e0E81aHt6saYiGfA-1V2II1yWwcZfvqGTRAv8pZnQtY,3865
|
|
11
14
|
mini_arcade_core/ui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
15
|
mini_arcade_core/ui/menu.py,sha256=2CbsMvqebZWbUdhilhyTNDL1LGcdaPqHFsIM_J2MWK8,3636
|
|
13
|
-
mini_arcade_core-0.
|
|
14
|
-
mini_arcade_core-0.
|
|
15
|
-
mini_arcade_core-0.
|
|
16
|
-
mini_arcade_core-0.
|
|
16
|
+
mini_arcade_core-0.9.1.dist-info/METADATA,sha256=pMU44fJcpjxG-7prQYQO8hbq55soJx39FWxw6Ro8qyc,8188
|
|
17
|
+
mini_arcade_core-0.9.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
18
|
+
mini_arcade_core-0.9.1.dist-info/licenses/LICENSE,sha256=3lHAuV0584cVS5vAqi2uC6GcsVgxUijvwvtZckyvaZ4,1096
|
|
19
|
+
mini_arcade_core-0.9.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|