From 639198e8de8bf8921dc5177cbc9ec45ad4be371d Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sun, 27 Mar 2022 00:59:07 -0400 Subject: [PATCH] Somewhat of a start on switching over to pyglet. It's in a very broken state with some remaining calls to pygame. --- __init__.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/__init__.py b/__init__.py index 901d315..b40224c 100755 --- a/__init__.py +++ b/__init__.py @@ -10,7 +10,7 @@ from os.path import isfile, join from inspect import isfunction from xdg import BaseDirectory from setproctitle import setproctitle -import pygame +import pyglet import pyperclip import random import re @@ -125,9 +125,8 @@ def speak(text, interupt = True): def exit_game(): if speechProvider == "speechd": spd.close() - pygame.mixer.music.stop() - pygame.quit() - exit() + # Close the pyglet window + pyglet.app.exit() def initialize_gui(gameTitle): # Check for, and possibly create, storm-games path @@ -142,24 +141,16 @@ def initialize_gui(gameTitle): global gameName gameName = gameTitle setproctitle(str.lower(str.replace(gameTitle, " ", ""))) - # start pygame - pygame.init() - # start the display (required by the event loop) - pygame.display.set_mode((320, 200)) - pygame.display.set_caption(gameTitle) - # Set 32 channels for sound by default - pygame.mixer.init() - pygame.mixer.set_num_channels(32) - # Reserve the cut scene channel - pygame.mixer.set_reserved(0) - # Load sounds from the sound directory and creates a list like that {'bottle': 'bottle.ogg'} + # init pyglet window + window = pyglet.window.Window(500, 300, gameTitle) + # Load sounds from the sound directory and creates a list like {'bottle': 'bottle.ogg'} soundFiles = [f for f in listdir("sounds/") if isfile(join("sounds/", f)) and (f.split('.')[1].lower() in ["ogg","wav"])] - #lets make a dict with pygame.mixer.Sound() objects {'bottle':} + # make a dict with pyglet media {'bottle':} soundData = {} for f in soundFiles: - soundData[f.split('.')[0]] = pygame.mixer.Sound("sounds/" + f) + soundData[f.split('.')[0]] = pyglet.media.load("sounds/" + f, streaming = False) soundData['game-intro'].play() - time.sleep(soundData['game-intro'].get_length()) + time.sleep(soundData['game-intro'].duration) return soundData def cut_scene(sounds, soundName):