Refine start menu difficulty and preview workflow
This commit is contained in:
+46
-2
@@ -2,6 +2,7 @@ import os
|
||||
import random
|
||||
import ctypes
|
||||
from ctypes import *
|
||||
from pathlib import Path
|
||||
|
||||
import sdl2
|
||||
import sdl2.ext
|
||||
@@ -72,8 +73,15 @@ class GameWindow:
|
||||
|
||||
print(f"Screen size: {self.width}x{self.height}")
|
||||
|
||||
self.joystick_enabled = os.environ.get("MICE_DISABLE_JOYSTICK", "").strip().lower() not in {
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
"on",
|
||||
}
|
||||
|
||||
# SDL2 initialization
|
||||
sdl2.ext.init(joystick=True)
|
||||
sdl2.ext.init(joystick=self.joystick_enabled)
|
||||
sdl2.SDL_Init(sdl2.SDL_INIT_AUDIO)
|
||||
|
||||
# Window and renderer setup
|
||||
@@ -119,7 +127,8 @@ class GameWindow:
|
||||
self._init_audio_system()
|
||||
self.audio = True
|
||||
# Input devices
|
||||
self.load_joystick()
|
||||
if self.joystick_enabled:
|
||||
self.load_joystick()
|
||||
|
||||
def _init_audio_system(self):
|
||||
"""Initialize audio devices for different audio channels"""
|
||||
@@ -579,6 +588,8 @@ class GameWindow:
|
||||
|
||||
def load_joystick(self):
|
||||
"""Initialize joystick and game controller support."""
|
||||
if not getattr(self, "joystick_enabled", True):
|
||||
return
|
||||
sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK | sdl2.SDL_INIT_GAMECONTROLLER)
|
||||
sdl2.SDL_JoystickEventState(sdl2.SDL_ENABLE)
|
||||
if hasattr(sdl2, "SDL_GameControllerEventState"):
|
||||
@@ -844,6 +855,39 @@ class GameWindow:
|
||||
"""Placeholder for cycle management (not implemented)"""
|
||||
pass
|
||||
|
||||
def capture_frame(self):
|
||||
"""Capture the current renderer output as a PIL image."""
|
||||
width, height = self.target_size
|
||||
pitch = width * 4
|
||||
pixel_buffer = (ctypes.c_ubyte * (pitch * height))()
|
||||
result = sdl2.SDL_RenderReadPixels(
|
||||
self.renderer.sdlrenderer,
|
||||
None,
|
||||
sdl2.SDL_PIXELFORMAT_RGBA32,
|
||||
pixel_buffer,
|
||||
pitch,
|
||||
)
|
||||
if result != 0:
|
||||
raise RuntimeError(f"Failed to capture frame: {sdl2.SDL_GetError()}")
|
||||
|
||||
return Image.frombuffer(
|
||||
"RGBA",
|
||||
(width, height),
|
||||
bytes(pixel_buffer),
|
||||
"raw",
|
||||
"RGBA",
|
||||
0,
|
||||
1,
|
||||
).copy()
|
||||
|
||||
def save_frame(self, path):
|
||||
"""Save the current renderer output to an image file."""
|
||||
output_path = Path(path).expanduser()
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
image = self.capture_frame()
|
||||
image.save(output_path)
|
||||
return output_path
|
||||
|
||||
def full_screen(self, flag):
|
||||
"""Toggle fullscreen mode"""
|
||||
sdl2.SDL_SetWindowFullscreen(self.window.window, flag)
|
||||
|
||||
Reference in New Issue
Block a user