#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Standard initializations and functions shared by all Storm Games. This module provides core functionality for Storm Games including: - Sound and speech handling - Volume controls - Configuration management - Score tracking - GUI initialization - Game menu systems """ # Import service classes from .services import ( ConfigService, VolumeService, PathService ) # Import Sound class and functions from .sound import ( Sound, play_bgm, play_sound, adjust_bgm_volume, adjust_sfx_volume, adjust_master_volume, play_ambiance, play_random, play_random_positional, play_directional_sound, obj_play, obj_update, obj_stop, cut_scene, play_random_falling, calculate_volume_and_pan ) # Import Speech class and functions from .speech import messagebox, speak, Speech # Import Scoreboard from .scoreboard import Scoreboard # Import input functions from .input import get_input, check_for_exit, pause_game # Import display functions from .display import display_text, initialize_gui # Import menu functions from .menu import game_menu, learn_sounds, instructions, credits, donate, exit_game # Update imports to reference Scoreboard methods high_scores = Scoreboard.display_high_scores has_high_scores = Scoreboard.has_high_scores # Import utility functions and Game class from .utils import ( Game, check_for_updates, get_version_tuple, check_compatibility, sanitize_filename, lerp, smooth_step, distance_2d, x_powerbar, y_powerbar, generate_tone ) __version__ = '2.0.0' # Make all symbols available at the package level __all__ = [ # Services 'ConfigService', 'VolumeService', 'PathService', # Sound 'Sound', 'play_bgm', 'play_sound', 'adjust_bgm_volume', 'adjust_sfx_volume', 'adjust_master_volume', 'play_ambiance', 'play_random', 'play_random_positional', 'play_directional_sound', 'obj_play', 'obj_update', 'obj_stop', 'cut_scene', 'play_random_falling', 'calculate_volume_and_pan', # Speech 'messagebox', 'speak', 'Speech', # Scoreboard 'Scoreboard', # Input 'get_input', 'check_for_exit', 'pause_game', # Display 'display_text', 'initialize_gui', # Menu 'game_menu', 'learn_sounds', 'instructions', 'credits', 'donate', 'exit_game', 'high_scores', 'has_high_scores', # Game class 'Game', # Utils 'check_for_updates', 'get_version_tuple', 'check_compatibility', 'sanitize_filename', 'lerp', 'smooth_step', 'distance_2d', 'x_powerbar', 'y_powerbar', 'generate_tone', # Re-exported functions from pygame, math, random 'get_ticks', 'delay', 'wait', 'sin', 'cos', 'sqrt', 'floor', 'ceil', 'randint', 'choice', 'uniform', 'seed' ] # Create global instances for backward compatibility configService = ConfigService.get_instance() volumeService = VolumeService.get_instance() pathService = PathService.get_instance() # Set up backward compatibility hooks for initialize_gui _originalInitializeGui = initialize_gui def initialize_gui_with_services(gameTitle): """Wrapper around initialize_gui that initializes services.""" # Initialize path service pathService.initialize(gameTitle) # Connect config service to path service configService.set_game_info(gameTitle, pathService) # Call original initialize_gui return _originalInitializeGui(gameTitle) # Replace initialize_gui with the wrapped version initialize_gui = initialize_gui_with_services # Initialize global scoreboard constructor _originalScoreboardInit = Scoreboard.__init__ def scoreboard_init_with_services(self, score=0, configService=None, speech=None): """Wrapper around Scoreboard.__init__ that ensures services are initialized.""" # Use global services if not specified if configService is None: configService = ConfigService.get_instance() # Ensure pathService is connected if using defaults if not hasattr(configService, 'pathService') and pathService.game_path is not None: configService.pathService = pathService # Call original init with services _originalScoreboardInit(self, score, configService, speech) # Replace Scoreboard.__init__ with the wrapped version Scoreboard.__init__ = scoreboard_init_with_services # Re-export pygame time functions for backward compatibility import pygame.time def get_ticks(): """Get the number of milliseconds since pygame.init() was called.""" return pygame.time.get_ticks() def delay(milliseconds): """Pause the program for a given number of milliseconds.""" return pygame.time.delay(milliseconds) def wait(milliseconds): """Pause the program for a given number of milliseconds.""" return pygame.time.wait(milliseconds) # Re-export math functions that might be used import math def sin(x): """Return the sine of x radians.""" return math.sin(x) def cos(x): """Return the cosine of x radians.""" return math.cos(x) def sqrt(x): """Return the square root of x.""" return math.sqrt(x) def floor(x): """Return the floor of x.""" return math.floor(x) def ceil(x): """Return the ceiling of x.""" return math.ceil(x) # Re-export random functions that might be used import random def randint(a, b): """Return a random integer N such that a <= N <= b.""" return random.randint(a, b) def choice(seq): """Return a random element from the non-empty sequence seq.""" return random.choice(seq) def uniform(a, b): """Return a random floating point number N such that a <= N <= b.""" return random.uniform(a, b) def seed(a=None): """Initialize the random number generator.""" return random.seed(a)