the load menus now show the time of the save

This commit is contained in:
Faraphel 2023-03-05 21:47:51 +01:00
parent 49546ff4a8
commit 808b309c40
6 changed files with 23 additions and 8 deletions

View file

@ -1,15 +1,17 @@
from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from source.gui import widget, texture from source.gui import widget, texture
from source.gui.scene.abc import Scene from source.gui.scene.abc import Scene
from source.network import Host from source.network import Host
from source.utils import path_ctime_str
if TYPE_CHECKING: if TYPE_CHECKING:
from source.gui.window import Window from source.gui.window import Window
class GameLoad(Scene): 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) super().__init__(window, **kwargs)
self.thread_host = thread_host # thread de l'hôte self.thread_host = thread_host # thread de l'hôte
@ -21,7 +23,9 @@ class GameLoad(Scene):
anchor_x="center", 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", align="center",
multiline=True, multiline=True,
font_size=28, font_size=28,

View file

@ -1,15 +1,16 @@
from pathlib import Path
from typing import TYPE_CHECKING 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.gui.scene.abc import Scene
from source.network import Host from source.utils import path_ctime_str
if TYPE_CHECKING: if TYPE_CHECKING:
from source.gui.window import Window from source.gui.window import Window
class GameWaitLoad(Scene): class GameWaitLoad(Scene):
def __init__(self, window: "Window", **kwargs): def __init__(self, window: "Window", path: Path, **kwargs):
super().__init__(window, **kwargs) super().__init__(window, **kwargs)
self.label = self.add_widget( self.label = self.add_widget(
@ -19,7 +20,10 @@ class GameWaitLoad(Scene):
anchor_x="center", 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", align="center",
multiline=True, multiline=True,
font_size=28, font_size=28,

View file

@ -63,7 +63,7 @@ class Client(StoppableThread):
# si l'on possède la sauvegarde, attend que l'hôte confirme son utilisation # si l'on possède la sauvegarde, attend que l'hôte confirme son utilisation
from source.gui.scene import GameWaitLoad 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: while True:
# attend la décision de l'hôte # attend la décision de l'hôte

View file

@ -71,7 +71,7 @@ class Host(StoppableThread):
if packet_save_found: if packet_save_found:
from source.gui.scene import GameLoad 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 with self.condition_load: self.condition_load.wait() # attend que l'utilisateur choisisse l'option

View file

@ -2,3 +2,4 @@ from .copy_array_offset import copy_array_offset
from .in_bbox import in_bbox from .in_bbox import in_bbox
from .dict import dict_filter, dict_filter_prefix from .dict import dict_filter, dict_filter_prefix
from .thread import StoppableThread from .thread import StoppableThread
from .path import path_ctime_str

6
source/utils/path.py Normal file
View file

@ -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')