From 1e7b62498a6fc20696c545e26391caa21a351d6d Mon Sep 17 00:00:00 2001 From: yannis300307 Date: Sat, 6 Jan 2024 18:40:57 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20callback=20=C3=A0=20la=20fin=20d?= =?UTF-8?q?u=20dialogue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/engine/dialogs_manager.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/engine/dialogs_manager.py b/src/engine/dialogs_manager.py index bb0d252..cb6348e 100644 --- a/src/engine/dialogs_manager.py +++ b/src/engine/dialogs_manager.py @@ -1,4 +1,5 @@ import json +from types import FunctionType class DialogsManager: @@ -14,6 +15,8 @@ class DialogsManager: self.LETTER_WRITING_DELAY = 0.02 self.letter_timer = 0 + self.dialogue_finished_callback = None + def next_signal(self): """Fonction exécutée lorsque l'utilisateur demande de passer au prochain dialogue. Si un dialogue est en train d'être écrit, il écrit tout d'un coup.""" @@ -30,13 +33,15 @@ class DialogsManager: """Passe au dialogue suivant. Renvoie True si le dialogue est fini.""" self.current_dialog_id += 1 self.writing_dialog = True - if self.current_dialog_id >= len(self.current_dialogs): + if self.current_dialog_id >= len(self.current_dialogs): # Le dialogue est fini. self.current_dialogs = [] self.current_dialog_id = -1 self.writing_dialog = False self.reading_dialog = False + if self.dialogue_finished_callback is not None: + self.dialogue_finished_callback() - def start_dialog(self, name: str): + def start_dialog(self, name: str, dialogue_finished_callback: FunctionType | classmethod | staticmethod = None): """Lance le dialogue au nom donné.""" # Si un dialogue n'est pas déja lancé, on lance le dialogue au nom donné @@ -47,6 +52,8 @@ class DialogsManager: self.reading_dialog = True + self.dialogue_finished_callback = dialogue_finished_callback + def get_current_dialog_sentence(self, progressive=True) -> str: """Renvoie la phrase actuelle du dialogue.""" if progressive: