mini-arcade-core 0.7.1__tar.gz → 0.7.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mini-arcade-core
3
- Version: 0.7.1
3
+ Version: 0.7.3
4
4
  Summary: Tiny scene-based game loop core for small arcade games.
5
5
  License: Copyright (c) 2025 Santiago Rincón
6
6
 
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [project]
6
6
  name = "mini-arcade-core"
7
- version = "0.7.1"
7
+ version = "0.7.3"
8
8
  description = "Tiny scene-based game loop core for small arcade games."
9
9
  authors = [
10
10
  { name = "Santiago Rincon", email = "rincores@gmail.com" },
@@ -21,7 +21,10 @@ def run_game(initial_scene_cls: type[Scene], config: GameConfig | None = None):
21
21
  Convenience helper to bootstrap and run a game with a single scene.
22
22
 
23
23
  :param initial_scene_cls: The Scene subclass to instantiate as the initial scene.
24
+ :type initial_scene_cls: type[Scene]
25
+
24
26
  :param config: Optional GameConfig to customize game settings.
27
+ :type config: GameConfig | None
25
28
  """
26
29
  game = Game(config or GameConfig())
27
30
  scene = initial_scene_cls(game)
@@ -11,7 +11,14 @@ from typing import Iterable, Protocol
11
11
 
12
12
 
13
13
  class EventType(Enum):
14
- """High-level event types understood by the core."""
14
+ """
15
+ High-level event types understood by the core.
16
+
17
+ :cvar UNKNOWN: Unknown/unhandled event.
18
+ :cvar QUIT: User requested to quit the game.
19
+ :cvar KEYDOWN: A key was pressed.
20
+ :cvar KEYUP: A key was released.
21
+ """
15
22
 
16
23
  UNKNOWN = auto()
17
24
  QUIT = auto()
@@ -46,20 +53,39 @@ class Backend(Protocol):
46
53
  def init(self, width: int, height: int, title: str) -> None:
47
54
  """
48
55
  Initialize the backend and open a window.
49
-
50
56
  Should be called once before the main loop.
57
+
58
+ :param width: Width of the window in pixels.
59
+ :type width: int
60
+
61
+ :param height: Height of the window in pixels.
62
+ :type height: int
63
+
64
+ :param title: Title of the window.
65
+ :type title: str
51
66
  """
52
67
 
53
68
  def poll_events(self) -> Iterable[Event]:
54
69
  """
55
70
  Return all pending events since last call.
56
-
57
71
  Concrete backends will translate their native events into core Event objects.
72
+
73
+ :return: An iterable of Event objects.
74
+ :rtype: Iterable[Event]
58
75
  """
59
76
 
60
77
  def set_clear_color(self, r: int, g: int, b: int) -> None:
61
78
  """
62
79
  Set the background/clear color used by begin_frame.
80
+
81
+ :param r: Red component (0-255).
82
+ :type r: int
83
+
84
+ :param g: Green component (0-255).
85
+ :type g: int
86
+
87
+ :param b: Blue component (0-255).
88
+ :type b: int
63
89
  """
64
90
 
65
91
  def begin_frame(self) -> None:
@@ -84,8 +110,22 @@ class Backend(Protocol):
84
110
  ) -> None:
85
111
  """
86
112
  Draw a filled rectangle in some default color.
87
-
88
113
  We'll keep this minimal for now; later we can extend with colors/sprites.
114
+
115
+ :param x: X position of the rectangle's top-left corner.
116
+ :type x: int
117
+
118
+ :param y: Y position of the rectangle's top-left corner.
119
+ :type y: int
120
+
121
+ :param w: Width of the rectangle.
122
+ :type w: int
123
+
124
+ :param h: Height of the rectangle.
125
+ :type h: int
126
+
127
+ :param color: RGB color tuple.
128
+ :type color: tuple[int, int, int]
89
129
  """
90
130
 
91
131
  # pylint: enable=too-many-arguments,too-many-positional-arguments
@@ -102,6 +142,18 @@ class Backend(Protocol):
102
142
 
103
143
  Backends may ignore advanced styling for now; this is just to render
104
144
  simple labels like menu items, scores, etc.
145
+
146
+ :param x: X position of the text's top-left corner.
147
+ :type x: int
148
+
149
+ :param y: Y position of the text's top-left corner.
150
+ :type y: int
151
+
152
+ :param text: The text string to draw.
153
+ :type text: str
154
+
155
+ :param color: RGB color tuple.
156
+ :type color: tuple[int, int, int]
105
157
  """
106
158
 
107
159
  def capture_frame(self, path: str | None = None) -> bytes | None:
@@ -109,5 +161,11 @@ class Backend(Protocol):
109
161
  Capture the current frame.
110
162
  If `path` is provided, save to that file (e.g. PNG).
111
163
  Returns raw bytes (PNG) or None if unsupported.
164
+
165
+ :param path: Optional file path to save the screenshot.
166
+ :type path: str | None
167
+
168
+ :return: Raw image bytes if no path given, else None.
169
+ :rtype: bytes | None
112
170
  """
113
171
  raise NotImplementedError
@@ -124,6 +124,15 @@ class Game:
124
124
  ) -> str | None:
125
125
  """
126
126
  Ask backend to save a screenshot. Returns the file path or None.
127
+
128
+ :param label: Optional label to include in the filename.
129
+ :type label: str | None
130
+
131
+ :param directory: Directory to save screenshots in.
132
+ :type directory: str
133
+
134
+ :return: The file path of the saved screenshot, or None on failure.
135
+ :rtype: str | None
127
136
  """
128
137
  os.makedirs(directory, exist_ok=True)
129
138
  stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
@@ -0,0 +1,95 @@
1
+ """
2
+ Base class for game scenes (states/screens).
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from abc import ABC, abstractmethod
8
+ from typing import Callable, List
9
+
10
+ from mini_arcade_core.backend import Backend
11
+
12
+ from .game import Game
13
+
14
+ OverlayFunc = Callable[[Backend], None]
15
+
16
+
17
+ class Scene(ABC):
18
+ """Base class for game scenes (states/screens)."""
19
+
20
+ def __init__(self, game: Game):
21
+ """
22
+ :param game: Reference to the main Game object.
23
+ :type game: Game
24
+ """
25
+ self.game = game
26
+ # overlays drawn on top of the scene
27
+ self._overlays: List[OverlayFunc] = []
28
+
29
+ def add_overlay(self, overlay: OverlayFunc) -> None:
30
+ """
31
+ Register an overlay (drawn every frame, after entities).
32
+
33
+ :param overlay: A callable that takes a Backend and draws on it.
34
+ :type overlay: OverlayFunc
35
+ """
36
+ self._overlays.append(overlay)
37
+
38
+ def remove_overlay(self, overlay: OverlayFunc) -> None:
39
+ """
40
+ Unregister a previously added overlay.
41
+
42
+ :param overlay: The overlay to remove.
43
+ :type overlay: OverlayFunc
44
+ """
45
+ if overlay in self._overlays:
46
+ self._overlays.remove(overlay)
47
+
48
+ def clear_overlays(self) -> None:
49
+ """Clear all registered overlays."""
50
+ self._overlays.clear()
51
+
52
+ def draw_overlays(self, surface: Backend) -> None:
53
+ """
54
+ Call all overlays. Scenes should call this at the end of draw().
55
+
56
+ :param surface: The backend surface to draw on.
57
+ :type surface: Backend
58
+ """
59
+ for overlay in self._overlays:
60
+ overlay(surface)
61
+
62
+ @abstractmethod
63
+ def on_enter(self):
64
+ """Called when the scene becomes active."""
65
+
66
+ @abstractmethod
67
+ def on_exit(self):
68
+ """Called when the scene is replaced."""
69
+
70
+ @abstractmethod
71
+ def handle_event(self, event: object):
72
+ """
73
+ Handle input / events (e.g. pygame.Event).
74
+
75
+ :param event: The event to handle.
76
+ :type event: object
77
+ """
78
+
79
+ @abstractmethod
80
+ def update(self, dt: float):
81
+ """
82
+ Update game logic. ``dt`` is the delta time in seconds.
83
+
84
+ :param dt: Time delta in seconds.
85
+ :type dt: float
86
+ """
87
+
88
+ @abstractmethod
89
+ def draw(self, surface: object):
90
+ """
91
+ Render to the main surface.
92
+
93
+ :param surface: The backend surface to draw on.
94
+ :type surface: object
95
+ """
@@ -1,40 +0,0 @@
1
- """
2
- Base class for game scenes (states/screens).
3
- """
4
-
5
- from __future__ import annotations
6
-
7
- from abc import ABC, abstractmethod
8
-
9
- from .game import Game
10
-
11
-
12
- class Scene(ABC):
13
- """Base class for game scenes (states/screens)."""
14
-
15
- def __init__(self, game: Game):
16
- """
17
- :param game: Reference to the main Game object.
18
- :type game: Game
19
- """
20
- self.game = game
21
-
22
- @abstractmethod
23
- def on_enter(self):
24
- """Called when the scene becomes active."""
25
-
26
- @abstractmethod
27
- def on_exit(self):
28
- """Called when the scene is replaced."""
29
-
30
- @abstractmethod
31
- def handle_event(self, event: object):
32
- """Handle input / events (e.g. pygame.Event)."""
33
-
34
- @abstractmethod
35
- def update(self, dt: float):
36
- """Update game logic. ``dt`` is the delta time in seconds."""
37
-
38
- @abstractmethod
39
- def draw(self, surface: object):
40
- """Render to the main surface."""