Dialogues (fais pas chier j'ai trop mal a la tête pour faire une bonne PR) #62

Merged
raphael merged 7 commits from dialogues into main 2023-11-05 12:02:51 +00:00
3 changed files with 2 additions and 11 deletions
Showing only changes of commit cb14acf58e - Show all commits

View file

@ -5,7 +5,6 @@ Un plugin permettant de gérer l'affichage et l'audio des dialogues.
import json
import random
import threading
import pygame
from engine.ecs import World
@ -15,27 +14,19 @@ from plugins import render
# from plugins.assets import Assets
from plugins.sound import Sound
from plugins.text import Text
import pyttsx3
engine = pyttsx3.init()
def spawn_dialog(world: World, name: str, index: int = -1, height: float = 100):
"""
Fait apparaitre un dialogue dans le monde.
"""
global engine
texts: list[str] = json.load(
open(f"assets/dialogs/{name}.json", "r", encoding="utf-8")
open(f"assets/dialogs/{name}/info.json", "r", encoding="utf-8")
)
text = random.choice(texts) if index == -1 else texts[index]
# engine.say(text)
engine.save_to_file(text, "voice.mp3")
engine.runAndWait()
world.new_entity().set(
Sound(
pygame.mixer.Sound("voice.mp3"),
pygame.mixer.Sound(f"assets/dialogs/{name}/{index}.mp3"),
callback=lambda world, entity: entity.destroy(),
),
Text(text, position=Vec2(render.WIDTH / 2, height), origin=Vec2(0.5)),