diff --git a/source/gui/scene/GameLoad.py b/source/gui/scene/GameLoad.py index 328746d..c4167e3 100644 --- a/source/gui/scene/GameLoad.py +++ b/source/gui/scene/GameLoad.py @@ -1,15 +1,17 @@ +from pathlib import Path from typing import TYPE_CHECKING from source.gui import widget, texture from source.gui.scene.abc import Scene from source.network import Host +from source.utils import path_ctime_str if TYPE_CHECKING: from source.gui.window import Window class GameLoad(Scene): - def __init__(self, window: "Window", thread_host: Host, **kwargs): + def __init__(self, window: "Window", path: Path, thread_host: Host, **kwargs): super().__init__(window, **kwargs) self.thread_host = thread_host # thread de l'hôte @@ -21,7 +23,9 @@ class GameLoad(Scene): anchor_x="center", - text="Une ancienne partie contre cet adversaire a été sauvegardé.\nSouhaitez-vous la reprendre ?", + text=f"Une ancienne partie contre cet adversaire a été sauvegardé.\n" + f"Souhaitez-vous la reprendre ?\n" + f"({path_ctime_str(path)})", align="center", multiline=True, font_size=28, diff --git a/source/gui/scene/GameWaitLoad.py b/source/gui/scene/GameWaitLoad.py index 49f62e8..66dc41c 100644 --- a/source/gui/scene/GameWaitLoad.py +++ b/source/gui/scene/GameWaitLoad.py @@ -1,15 +1,16 @@ +from pathlib import Path from typing import TYPE_CHECKING -from source.gui import widget, texture +from source.gui import widget from source.gui.scene.abc import Scene -from source.network import Host +from source.utils import path_ctime_str if TYPE_CHECKING: from source.gui.window import Window class GameWaitLoad(Scene): - def __init__(self, window: "Window", **kwargs): + def __init__(self, window: "Window", path: Path, **kwargs): super().__init__(window, **kwargs) self.label = self.add_widget( @@ -19,7 +20,10 @@ class GameWaitLoad(Scene): anchor_x="center", - text="Une ancienne sauvegarde à été trouvé.\nL'hôte décide de son utilisation...", + text=f"Une ancienne sauvegarde à été trouvé.\n" + f"L'hôte décide de son utilisation...\n" + f"({path_ctime_str(path)})", + align="center", multiline=True, font_size=28, diff --git a/source/network/Client.py b/source/network/Client.py index 2884cbf..caf349c 100644 --- a/source/network/Client.py +++ b/source/network/Client.py @@ -63,7 +63,7 @@ class Client(StoppableThread): # si l'on possède la sauvegarde, attend que l'hôte confirme son utilisation from source.gui.scene import GameWaitLoad - in_pyglet_context(self.window.set_scene, GameWaitLoad) + in_pyglet_context(self.window.set_scene, GameWaitLoad, path=path_old_save) while True: # attend la décision de l'hôte diff --git a/source/network/Host.py b/source/network/Host.py index 21fb3e5..566b463 100644 --- a/source/network/Host.py +++ b/source/network/Host.py @@ -71,7 +71,7 @@ class Host(StoppableThread): if packet_save_found: from source.gui.scene import GameLoad - in_pyglet_context(self.window.set_scene, GameLoad, thread_host=self) + in_pyglet_context(self.window.set_scene, GameLoad, path=path_old_save, thread_host=self) with self.condition_load: self.condition_load.wait() # attend que l'utilisateur choisisse l'option diff --git a/source/utils/__init__.py b/source/utils/__init__.py index 2e6154f..27204c3 100644 --- a/source/utils/__init__.py +++ b/source/utils/__init__.py @@ -2,3 +2,4 @@ from .copy_array_offset import copy_array_offset from .in_bbox import in_bbox from .dict import dict_filter, dict_filter_prefix from .thread import StoppableThread +from .path import path_ctime_str diff --git a/source/utils/path.py b/source/utils/path.py new file mode 100644 index 0000000..94bb119 --- /dev/null +++ b/source/utils/path.py @@ -0,0 +1,6 @@ +from datetime import datetime +from pathlib import Path + + +def path_ctime_str(path: Path): + return datetime.fromtimestamp(path.lstat().st_ctime).strftime('%d/%m/%Y %H:%M:%S')