Sauvegarde automatique du nom d'utilisateur (#32)

Reviewed-on: #32
Reviewed-by: Corentin <solois.corentin@gmail.com>
Co-authored-by: Tipragot <contact@tipragot.fr>
Co-committed-by: Tipragot <contact@tipragot.fr>
This commit is contained in:
Tipragot 2024-01-07 12:58:29 +00:00 committed by Corentin
parent 5c0073809f
commit c9376ac431

View file

@ -1,3 +1,4 @@
import os
from plugins import writing
from engine import CurrentScene, Plugin
from engine.ecs import Entity, World
@ -21,6 +22,8 @@ def new_score(world: World, e: Entity):
try:
post = {"name": name[Text], "score": world[game.Player1Score]}
rq.post(f"https://{IP}/new_score", post)
with open("username.txt", "w") as f:
f.write(name[Text])
world.set(CurrentScene(thanks.THANKS))
except Exception as error:
print("Error with the serveur:", error)
@ -38,6 +41,14 @@ def __spawn_elements(world: World):
Ajoute les éléments du menu dans le monde.
"""
if os.path.exists("username.txt"):
with open("username.txt", "r") as f:
name = f.read()
post = {"name": name, "score": world[game.Player1Score]}
rq.post(f"https://{IP}/new_score", post)
world.set(CurrentScene(thanks.THANKS))
return
world.new_entity().set(SpriteBundle("background.png", -5))
world.new_entity().set(
TextBundle(