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

View File

@@ -1,3 +1,2 @@
Added release notes Major update!
Bugfix with quitting game on desktop Added saving to the web version!
Added credits

View File

@@ -5,6 +5,8 @@ import sys
import hashlib import hashlib
import systems.ui import systems.ui
import shutil import shutil
import base64
import systems.ui
def punish(cat): def punish(cat):
@@ -55,10 +57,20 @@ class SaveData:
self.money = money self.money = money
def save(cat, hide_web_message=False): def save(cat, dont_save=False):
if os.path.exists("WEB_VERSION"): if os.path.exists("WEB_VERSION") and not dont_save:
if not hide_web_message: print(
print("Saving is disabled.") "Under this message, in quotes, will be a long string of text, this is your savefile, please copy this somewhere safe (WITHOUT THE QUOTES) and make sure to copy the whole thing, you will paste it back to load your game. DO NOT use control+c to copy, instead, select it, and use the right click menu to copy, ctrl+c will crash this."
)
print('"' + base64.b64encode(json.dumps(cat.to_dict()).encode()).decode() + '"')
print(
"Your savefile has been printed above this, please save it somewhere safe."
)
print(
"Any progress done after this will not be saved in this string, please generate a new one to update your progress."
)
print("To get back to the main menu and quit, reload the page.")
systems.ui.press_any_key_to_continue("Press any key to continue.")
return return
currentjson = {} currentjson = {}
data_dir = get_data_dir() data_dir = get_data_dir()

39
game.py
View File

@@ -7,6 +7,7 @@ import data.text
import os import os
import json import json
import traceback import traceback
import base64
class Game: class Game:
@@ -45,9 +46,8 @@ class Game:
"Settings", "Settings",
] ]
else: else:
print( options[0:0] = ["Save"]
"This menu will have no options, all of them are about saving, which is not in the web version."
)
while True: while True:
match ui.select( match ui.select(
"Please choose an option", "Please choose an option",
@@ -95,11 +95,35 @@ class Game:
case _: case _:
return 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): def run(self):
title() title()
if os.path.exists("WEB_VERSION"): if os.path.exists("WEB_VERSION"):
print( 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( print(
"Just a recommendation, don't press any keys with CTRL, it will probably break something. If something weird happens, reload." "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 return
options = ["New Game", "Release Notes", "Credits"] 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") options.insert(0, "Load Game")
if not os.path.exists("WEB_VERSION"): if not os.path.exists("WEB_VERSION"):
options.append("Quit") options.append("Quit")
@@ -149,10 +173,7 @@ class Game:
if choice == "New Game": if choice == "New Game":
self.new_game() self.new_game()
elif choice == "Load Game": elif choice == "Load Game":
save = "saves/" + ui.select( if self.load_game():
"Please choose a savefile to load", os.listdir("saves")
)
self.cat = data.save.load(save)
self.game_loop() self.game_loop()
elif choice == "Quit": elif choice == "Quit":
return True return True