mini-arcade-native-backend 0.5.0__cp39-cp39-win_amd64.whl → 0.5.3__cp39-cp39-win_amd64.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_native_backend/__init__.py +136 -22
- mini_arcade_native_backend/_native.cp39-win_amd64.pyd +0 -0
- {mini_arcade_native_backend-0.5.0.dist-info → mini_arcade_native_backend-0.5.3.dist-info}/METADATA +1 -1
- mini_arcade_native_backend-0.5.3.dist-info/RECORD +6 -0
- mini_arcade_native_backend-0.5.0.dist-info/RECORD +0 -6
- {mini_arcade_native_backend-0.5.0.dist-info → mini_arcade_native_backend-0.5.3.dist-info}/WHEEL +0 -0
- {mini_arcade_native_backend-0.5.0.dist-info → mini_arcade_native_backend-0.5.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import os
|
|
8
8
|
import sys
|
|
9
|
+
from dataclasses import dataclass
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
from typing import Optional, Union
|
|
11
12
|
|
|
@@ -42,6 +43,7 @@ if sys.platform == "win32":
|
|
|
42
43
|
# pylint: disable=import-error
|
|
43
44
|
from mini_arcade_core.backend import ( # pyright: ignore[reportMissingImports]
|
|
44
45
|
Backend,
|
|
46
|
+
WindowSettings,
|
|
45
47
|
)
|
|
46
48
|
from mini_arcade_core.backend.events import ( # pyright: ignore[reportMissingImports]
|
|
47
49
|
Event,
|
|
@@ -79,23 +81,49 @@ _NATIVE_TO_CORE = {
|
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
|
|
84
|
+
@dataclass
|
|
85
|
+
class BackendSettings:
|
|
86
|
+
"""
|
|
87
|
+
Settings for the NativeBackend.
|
|
88
|
+
|
|
89
|
+
:ivar font_path (Optional[str]): Optional path to a TTF font file to load.
|
|
90
|
+
:ivar font_size (int): Font size in points to use when loading the font.
|
|
91
|
+
:ivar sounds (Optional[dict[str, str]]): Optional dictionary mapping sound IDs to file paths.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
font_path: Optional[str] = None
|
|
95
|
+
font_size: int = 24
|
|
96
|
+
sounds: Optional[dict[str, str]] = None # sound_id -> path
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# TODO: Refactor backend interface into smaller protocols?
|
|
100
|
+
# Justification: Many public methods needed for backend interface
|
|
101
|
+
# pylint: disable=too-many-public-methods,too-many-instance-attributes
|
|
82
102
|
class NativeBackend(Backend):
|
|
83
103
|
"""Adapter that makes the C++ Engine usable as a mini-arcade backend."""
|
|
84
104
|
|
|
85
|
-
def __init__(self,
|
|
105
|
+
def __init__(self, backend_settings: BackendSettings | None = None):
|
|
86
106
|
"""
|
|
87
|
-
:param
|
|
88
|
-
:type
|
|
89
|
-
|
|
90
|
-
:param font_size: Font size in points to use when loading the font.
|
|
91
|
-
:type font_size: int
|
|
107
|
+
:param backend_settings: Optional settings for the backend.
|
|
108
|
+
:type backend_settings: BackendSettings | None
|
|
92
109
|
"""
|
|
93
110
|
self._engine = native.Engine()
|
|
94
|
-
|
|
95
|
-
self.
|
|
111
|
+
|
|
112
|
+
self._font_path = (
|
|
113
|
+
backend_settings.font_path if backend_settings else None
|
|
114
|
+
)
|
|
115
|
+
self._font_size = (
|
|
116
|
+
backend_settings.font_size if backend_settings else 24
|
|
117
|
+
)
|
|
96
118
|
self._default_font_id: int | None = None
|
|
97
119
|
self._fonts_by_size: dict[int, int] = {}
|
|
98
120
|
|
|
121
|
+
self._sounds = backend_settings.sounds if backend_settings else None
|
|
122
|
+
|
|
123
|
+
self._vp_offset_x = 0
|
|
124
|
+
self._vp_offset_y = 0
|
|
125
|
+
self._vp_scale = 1.0
|
|
126
|
+
|
|
99
127
|
def _get_font_id(self, font_size: int | None) -> int:
|
|
100
128
|
# No font loaded -> keep current “no-op” behavior
|
|
101
129
|
if self._font_path is None:
|
|
@@ -122,22 +150,15 @@ class NativeBackend(Backend):
|
|
|
122
150
|
self._fonts_by_size[font_size] = font_id
|
|
123
151
|
return font_id
|
|
124
152
|
|
|
125
|
-
def init(self,
|
|
153
|
+
def init(self, window_settings: WindowSettings):
|
|
126
154
|
"""
|
|
127
155
|
Initialize the backend with a window of given width, height, and title.
|
|
128
156
|
|
|
129
|
-
:param
|
|
130
|
-
:type
|
|
131
|
-
|
|
132
|
-
:param height: Height of the window in pixels.
|
|
133
|
-
:type height: int
|
|
134
|
-
|
|
135
|
-
:param title: Title of the window.
|
|
136
|
-
:type title: Optional[str]
|
|
157
|
+
:param window_settings: Settings for the backend window.
|
|
158
|
+
:type window_settings: WindowSettings
|
|
137
159
|
"""
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
self._engine.init(width, height, title)
|
|
160
|
+
title = ""
|
|
161
|
+
self._engine.init(window_settings.width, window_settings.height, title)
|
|
141
162
|
|
|
142
163
|
# Load font if provided
|
|
143
164
|
if self._font_path is not None:
|
|
@@ -146,6 +167,11 @@ class NativeBackend(Backend):
|
|
|
146
167
|
)
|
|
147
168
|
self._fonts_by_size[self._font_size] = self._default_font_id
|
|
148
169
|
|
|
170
|
+
# Load sounds if provided
|
|
171
|
+
if self._sounds is not None:
|
|
172
|
+
for sound_id, path in self._sounds.items():
|
|
173
|
+
self.load_sound(sound_id, path)
|
|
174
|
+
|
|
149
175
|
def set_window_title(self, title: str):
|
|
150
176
|
"""
|
|
151
177
|
Set the window title.
|
|
@@ -328,7 +354,12 @@ class NativeBackend(Backend):
|
|
|
328
354
|
:type color: tuple[int, ...]
|
|
329
355
|
"""
|
|
330
356
|
r, g, b, a = self._get_color_values(color)
|
|
331
|
-
self.
|
|
357
|
+
sx = int(round(self._vp_offset_x + x * self._vp_scale)) # top-left x
|
|
358
|
+
sy = int(round(self._vp_offset_y + y * self._vp_scale)) # top-left y
|
|
359
|
+
sw = int(round(w * self._vp_scale)) # width
|
|
360
|
+
sh = int(round(h * self._vp_scale)) # height
|
|
361
|
+
self._engine.draw_rect(sx, sy, sw, sh, r, g, b, a)
|
|
362
|
+
# self._engine.draw_rect(x, y, w, h, r, g, b, a)
|
|
332
363
|
|
|
333
364
|
def draw_text(
|
|
334
365
|
self,
|
|
@@ -356,9 +387,22 @@ class NativeBackend(Backend):
|
|
|
356
387
|
"""
|
|
357
388
|
r, g, b, a = self._get_color_values(color)
|
|
358
389
|
font_id = self._get_font_id(font_size)
|
|
390
|
+
sx = int(round(self._vp_offset_x + x * self._vp_scale))
|
|
391
|
+
sy = int(round(self._vp_offset_y + y * self._vp_scale))
|
|
392
|
+
|
|
393
|
+
# optional but recommended: scale font size too
|
|
394
|
+
if font_size is not None:
|
|
395
|
+
scaled = max(8, int(round(font_size * self._vp_scale)))
|
|
396
|
+
else:
|
|
397
|
+
scaled = None
|
|
398
|
+
|
|
399
|
+
font_id = self._get_font_id(scaled)
|
|
359
400
|
self._engine.draw_text(
|
|
360
|
-
text,
|
|
401
|
+
text, sx, sy, int(r), int(g), int(b), int(a), font_id
|
|
361
402
|
)
|
|
403
|
+
# self._engine.draw_text(
|
|
404
|
+
# text, x, y, int(r), int(g), int(b), int(a), font_id
|
|
405
|
+
# )
|
|
362
406
|
|
|
363
407
|
# pylint: enable=too-many-arguments,too-many-positional-arguments
|
|
364
408
|
|
|
@@ -388,3 +432,73 @@ class NativeBackend(Backend):
|
|
|
388
432
|
font_id = self._get_font_id(font_size)
|
|
389
433
|
w, h = self._engine.measure_text(text, font_id)
|
|
390
434
|
return int(w), int(h)
|
|
435
|
+
|
|
436
|
+
def init_audio(
|
|
437
|
+
self, frequency: int = 44100, channels: int = 2, chunk_size: int = 2048
|
|
438
|
+
):
|
|
439
|
+
"""Initialize SDL_mixer audio."""
|
|
440
|
+
self._engine.init_audio(int(frequency), int(channels), int(chunk_size))
|
|
441
|
+
|
|
442
|
+
def shutdown_audio(self):
|
|
443
|
+
"""Shutdown SDL_mixer audio and free loaded sounds."""
|
|
444
|
+
self._engine.shutdown_audio()
|
|
445
|
+
|
|
446
|
+
def load_sound(self, sound_id: str, path: str):
|
|
447
|
+
"""
|
|
448
|
+
Load a WAV sound and store it by ID.
|
|
449
|
+
Example: backend.load_sound("hit", "assets/sfx/hit.wav")
|
|
450
|
+
"""
|
|
451
|
+
if not sound_id:
|
|
452
|
+
raise ValueError("sound_id cannot be empty")
|
|
453
|
+
|
|
454
|
+
p = Path(path)
|
|
455
|
+
if not p.exists():
|
|
456
|
+
raise FileNotFoundError(f"Sound file not found: {p}")
|
|
457
|
+
|
|
458
|
+
self._engine.load_sound(sound_id, str(p))
|
|
459
|
+
|
|
460
|
+
def play_sound(self, sound_id: str, loops: int = 0):
|
|
461
|
+
"""
|
|
462
|
+
Play a loaded sound.
|
|
463
|
+
loops=0 => play once
|
|
464
|
+
loops=-1 => infinite loop
|
|
465
|
+
loops=1 => play twice (SDL convention)
|
|
466
|
+
"""
|
|
467
|
+
self._engine.play_sound(sound_id, int(loops))
|
|
468
|
+
|
|
469
|
+
def set_master_volume(self, volume: int):
|
|
470
|
+
"""
|
|
471
|
+
Master volume: 0..128
|
|
472
|
+
"""
|
|
473
|
+
self._engine.set_master_volume(int(volume))
|
|
474
|
+
|
|
475
|
+
def set_sound_volume(self, sound_id: str, volume: int):
|
|
476
|
+
"""
|
|
477
|
+
Per-sound volume: 0..128
|
|
478
|
+
"""
|
|
479
|
+
self._engine.set_sound_volume(sound_id, int(volume))
|
|
480
|
+
|
|
481
|
+
def stop_all_sounds(self):
|
|
482
|
+
"""Stop all channels."""
|
|
483
|
+
self._engine.stop_all_sounds()
|
|
484
|
+
|
|
485
|
+
def set_viewport_transform(
|
|
486
|
+
self, offset_x: int, offset_y: int, scale: float
|
|
487
|
+
) -> None:
|
|
488
|
+
self._vp_offset_x = int(offset_x)
|
|
489
|
+
self._vp_offset_y = int(offset_y)
|
|
490
|
+
self._vp_scale = float(scale)
|
|
491
|
+
|
|
492
|
+
def clear_viewport_transform(self) -> None:
|
|
493
|
+
self._vp_offset_x = 0
|
|
494
|
+
self._vp_offset_y = 0
|
|
495
|
+
self._vp_scale = 1.0
|
|
496
|
+
|
|
497
|
+
def resize_window(self, width: int, height: int) -> None:
|
|
498
|
+
self._engine.resize_window(int(width), int(height))
|
|
499
|
+
|
|
500
|
+
def set_clip_rect(self, x: int, y: int, w: int, h: int) -> None:
|
|
501
|
+
self._engine.set_clip_rect(int(x), int(y), int(w), int(h))
|
|
502
|
+
|
|
503
|
+
def clear_clip_rect(self) -> None:
|
|
504
|
+
self._engine.clear_clip_rect()
|
|
Binary file
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
mini_arcade_native_backend/__init__.py,sha256=eguv2ESm07S1h8beSRfKKhMFBywfpsUlo-3forhhCoc,16809
|
|
2
|
+
mini_arcade_native_backend/_native.cp39-win_amd64.pyd,sha256=WrgPcECVN5iNqtpQkQcaiM9C0Ky21-PCimV3Sg0vQBQ,243712
|
|
3
|
+
mini_arcade_native_backend-0.5.3.dist-info/METADATA,sha256=Br3ckI1QZuE2tgZ7eKIgkQf_g8z-b69kdcQIe8k4SSs,10517
|
|
4
|
+
mini_arcade_native_backend-0.5.3.dist-info/WHEEL,sha256=9tsL4JT94eZPTkcS3bNng2riasYJMxXndrO9CxUfJHs,104
|
|
5
|
+
mini_arcade_native_backend-0.5.3.dist-info/licenses/LICENSE,sha256=cZRgTdRJ3YASekMxkGAvylB2nROh4ov228DxAogK3yY,1115
|
|
6
|
+
mini_arcade_native_backend-0.5.3.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
mini_arcade_native_backend/__init__.py,sha256=CtzaxGTyVhLBVDB6naaqR0LCCz3CSuUpJP2SXQGCz64,12704
|
|
2
|
-
mini_arcade_native_backend/_native.cp39-win_amd64.pyd,sha256=AWWKVEbfySsajm5OwPUQWi3t4HTVkWrsoiLXNSBOuZ8,226816
|
|
3
|
-
mini_arcade_native_backend-0.5.0.dist-info/METADATA,sha256=BrvJBIkrJ0pxAxOSm1yV9_Ga88JFpOMB6G7mUgRSaZY,10517
|
|
4
|
-
mini_arcade_native_backend-0.5.0.dist-info/WHEEL,sha256=9tsL4JT94eZPTkcS3bNng2riasYJMxXndrO9CxUfJHs,104
|
|
5
|
-
mini_arcade_native_backend-0.5.0.dist-info/licenses/LICENSE,sha256=cZRgTdRJ3YASekMxkGAvylB2nROh4ov228DxAogK3yY,1115
|
|
6
|
-
mini_arcade_native_backend-0.5.0.dist-info/RECORD,,
|
{mini_arcade_native_backend-0.5.0.dist-info → mini_arcade_native_backend-0.5.3.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|