Add web version savegame

This commit is contained in:
2026-04-20 16:24:47 -04:00
parent 0f9730645a
commit 1580ad9e6e
3 changed files with 49 additions and 17 deletions

41
game.py
View File

@@ -7,6 +7,7 @@ import data.text
import os
import json
import traceback
import base64
class Game:
@@ -45,9 +46,8 @@ class Game:
"Settings",
]
else:
print(
"This menu will have no options, all of them are about saving, which is not in the web version."
)
options[0:0] = ["Save"]
while True:
match ui.select(
"Please choose an option",
@@ -95,11 +95,35 @@ class Game:
case _:
return
def load_game(self):
if os.path.exists("WEB_VERSION"):
print(
"Please paste your savefile on the next line, DO NOT USE CTRL+V, instead, right click and click paste. Make sure to not paste the quotes surrounding it if you copied those. Press enter to cancel."
)
savetext = ui.text("Enter here:")
if savetext:
try:
self.cat = Cat(**json.loads(base64.b64decode(savetext).decode()))
except:
print(
"The savefile you gave was unable to load, please make sure you pasted correctly. Otherwise, it may have broken."
)
else:
print(
f"Savefile loaded successfully! Continuing save with {self.cat.name}."
)
return True
return False
save = "saves/" + ui.select(
"Please choose a savefile to load", os.listdir("saves")
)
self.cat = data.save.load(save)
def run(self):
title()
if os.path.exists("WEB_VERSION"):
print(
f"This is a web version of {data.text.GAME_NAME}, saving/loading is disabled. As soon as you quit this page, your savefile is gone.\nAlso, to anyone outside of Germany, this game is running on a cheap VPS I got, the company didn't have any US locations available, so I had to get a Germany one, sorry for the high ping (I also have to deal with it, I'm in the US)\nPls don't hack this"
f"This is a web version of {data.text.GAME_NAME}, here is some important info. To anyone outside of Germany, this game is running on a cheap VPS I got, the company didn't have any US locations available, so I had to get a Germany one, sorry for the high ping (I also have to deal with it, I'm in the US)\nPls don't hack this"
)
print(
"Just a recommendation, don't press any keys with CTRL, it will probably break something. If something weird happens, reload."
@@ -138,7 +162,7 @@ class Game:
return
options = ["New Game", "Release Notes", "Credits"]
if os.path.exists("saves") and not os.path.exists("WEB_VERSION"):
if os.path.exists("saves") or os.path.exists("WEB_VERSION"):
options.insert(0, "Load Game")
if not os.path.exists("WEB_VERSION"):
options.append("Quit")
@@ -149,11 +173,8 @@ class Game:
if choice == "New Game":
self.new_game()
elif choice == "Load Game":
save = "saves/" + ui.select(
"Please choose a savefile to load", os.listdir("saves")
)
self.cat = data.save.load(save)
self.game_loop()
if self.load_game():
self.game_loop()
elif choice == "Quit":
return True
elif choice == "Release Notes":