mini-arcade-core 0.7.0__tar.gz → 0.7.2__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.
- {mini_arcade_core-0.7.0 → mini_arcade_core-0.7.2}/PKG-INFO +1 -1
- {mini_arcade_core-0.7.0 → mini_arcade_core-0.7.2}/pyproject.toml +1 -1
- {mini_arcade_core-0.7.0 → mini_arcade_core-0.7.2}/src/mini_arcade_core/backend.py +8 -0
- {mini_arcade_core-0.7.0 → mini_arcade_core-0.7.2}/src/mini_arcade_core/game.py +18 -0
- mini_arcade_core-0.7.2/src/mini_arcade_core/scene.py +69 -0
- mini_arcade_core-0.7.0/src/mini_arcade_core/scene.py +0 -40
- {mini_arcade_core-0.7.0 → mini_arcade_core-0.7.2}/LICENSE +0 -0
- {mini_arcade_core-0.7.0 → mini_arcade_core-0.7.2}/README.md +0 -0
- {mini_arcade_core-0.7.0 → mini_arcade_core-0.7.2}/src/mini_arcade_core/__init__.py +0 -0
- {mini_arcade_core-0.7.0 → mini_arcade_core-0.7.2}/src/mini_arcade_core/entity.py +0 -0
|
@@ -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.
|
|
7
|
+
version = "0.7.2"
|
|
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" },
|
|
@@ -103,3 +103,11 @@ class Backend(Protocol):
|
|
|
103
103
|
Backends may ignore advanced styling for now; this is just to render
|
|
104
104
|
simple labels like menu items, scores, etc.
|
|
105
105
|
"""
|
|
106
|
+
|
|
107
|
+
def capture_frame(self, path: str | None = None) -> bytes | None:
|
|
108
|
+
"""
|
|
109
|
+
Capture the current frame.
|
|
110
|
+
If `path` is provided, save to that file (e.g. PNG).
|
|
111
|
+
Returns raw bytes (PNG) or None if unsupported.
|
|
112
|
+
"""
|
|
113
|
+
raise NotImplementedError
|
|
@@ -4,7 +4,9 @@ Game core module defining the Game class and configuration.
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
+
import os
|
|
7
8
|
from dataclasses import dataclass
|
|
9
|
+
from datetime import datetime
|
|
8
10
|
from time import perf_counter, sleep
|
|
9
11
|
from typing import TYPE_CHECKING
|
|
10
12
|
|
|
@@ -116,3 +118,19 @@ class Game:
|
|
|
116
118
|
|
|
117
119
|
if self._current_scene is not None:
|
|
118
120
|
self._current_scene.on_exit()
|
|
121
|
+
|
|
122
|
+
def screenshot(
|
|
123
|
+
self, label: str | None = None, directory: str = "screenshots"
|
|
124
|
+
) -> str | None:
|
|
125
|
+
"""
|
|
126
|
+
Ask backend to save a screenshot. Returns the file path or None.
|
|
127
|
+
"""
|
|
128
|
+
os.makedirs(directory, exist_ok=True)
|
|
129
|
+
stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
130
|
+
label = label or "shot"
|
|
131
|
+
filename = f"{stamp}_{label}.png"
|
|
132
|
+
path = os.path.join(directory, filename)
|
|
133
|
+
|
|
134
|
+
if self.backend.capture_frame(path):
|
|
135
|
+
return path
|
|
136
|
+
return None
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
"""Register an overlay (drawn every frame, after entities)."""
|
|
31
|
+
self._overlays.append(overlay)
|
|
32
|
+
|
|
33
|
+
def remove_overlay(self, overlay: OverlayFunc) -> None:
|
|
34
|
+
if overlay in self._overlays:
|
|
35
|
+
self._overlays.remove(overlay)
|
|
36
|
+
|
|
37
|
+
def clear_overlays(self) -> None:
|
|
38
|
+
self._overlays.clear()
|
|
39
|
+
|
|
40
|
+
def draw_overlays(self, surface: Backend) -> None:
|
|
41
|
+
"""Call all overlays. Scenes should call this at the end of draw()."""
|
|
42
|
+
for overlay in self._overlays:
|
|
43
|
+
overlay(surface)
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def on_enter(self):
|
|
47
|
+
"""Called when the scene becomes active."""
|
|
48
|
+
|
|
49
|
+
@abstractmethod
|
|
50
|
+
def on_exit(self):
|
|
51
|
+
"""Called when the scene is replaced."""
|
|
52
|
+
|
|
53
|
+
@abstractmethod
|
|
54
|
+
def handle_event(self, event: object):
|
|
55
|
+
"""Handle input / events (e.g. pygame.Event)."""
|
|
56
|
+
|
|
57
|
+
@abstractmethod
|
|
58
|
+
def update(self, dt: float):
|
|
59
|
+
"""Update game logic. ``dt`` is the delta time in seconds."""
|
|
60
|
+
|
|
61
|
+
@abstractmethod
|
|
62
|
+
def draw(self, surface: object):
|
|
63
|
+
"""Render to the main surface."""
|
|
64
|
+
|
|
65
|
+
def draw(self, surface: object):
|
|
66
|
+
"""Render to the main surface."""
|
|
67
|
+
|
|
68
|
+
def draw(self, surface: object):
|
|
69
|
+
"""Render to the main surface."""
|
|
@@ -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."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|