Dialogues (fais pas chier j'ai trop mal a la tête pour faire une bonne PR) #62
|
@ -5,7 +5,6 @@ Un plugin permettant de gérer l'affichage et l'audio des dialogues.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import threading
|
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
from engine.ecs import World
|
from engine.ecs import World
|
||||||
|
@ -15,27 +14,19 @@ from plugins import render
|
||||||
# from plugins.assets import Assets
|
# from plugins.assets import Assets
|
||||||
from plugins.sound import Sound
|
from plugins.sound import Sound
|
||||||
from plugins.text import Text
|
from plugins.text import Text
|
||||||
import pyttsx3
|
|
||||||
|
|
||||||
|
|
||||||
engine = pyttsx3.init()
|
|
||||||
|
|
||||||
|
|
||||||
def spawn_dialog(world: World, name: str, index: int = -1, height: float = 100):
|
def spawn_dialog(world: World, name: str, index: int = -1, height: float = 100):
|
||||||
"""
|
"""
|
||||||
Fait apparaitre un dialogue dans le monde.
|
Fait apparaitre un dialogue dans le monde.
|
||||||
"""
|
"""
|
||||||
global engine
|
|
||||||
texts: list[str] = json.load(
|
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]
|
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(
|
world.new_entity().set(
|
||||||
Sound(
|
Sound(
|
||||||
pygame.mixer.Sound("voice.mp3"),
|
pygame.mixer.Sound(f"assets/dialogs/{name}/{index}.mp3"),
|
||||||
callback=lambda world, entity: entity.destroy(),
|
callback=lambda world, entity: entity.destroy(),
|
||||||
),
|
),
|
||||||
Text(text, position=Vec2(render.WIDTH / 2, height), origin=Vec2(0.5)),
|
Text(text, position=Vec2(render.WIDTH / 2, height), origin=Vec2(0.5)),
|
||||||
|
|
Loading…
Reference in a new issue