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
Bugfix with quitting game on desktop
Added credits
Major update!
Added saving to the web version!

View File

@@ -5,6 +5,8 @@ import sys
import hashlib
import systems.ui
import shutil
import base64
import systems.ui
def punish(cat):
@@ -55,10 +57,20 @@ class SaveData:
self.money = money
def save(cat, hide_web_message=False):
if os.path.exists("WEB_VERSION"):
if not hide_web_message:
print("Saving is disabled.")
def save(cat, dont_save=False):
if os.path.exists("WEB_VERSION") and not dont_save:
print(
"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
currentjson = {}
data_dir = get_data_dir()

39
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,10 +173,7 @@ 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)
if self.load_game():
self.game_loop()
elif choice == "Quit":
return True