Files
Whiskerbound/game.py
2026-04-17 18:23:05 -04:00

141 lines
5.0 KiB
Python

from data.cat import Cat
from systems.ui import clear, title
from systems.world import shelter, house, shop
import systems.ui as ui
import data.save
import data.text
import os
import json
class Game:
def __init__(self):
self.cat = None
def settings(self):
while True:
match ui.select(
"Please choose an option", ["Prepare for savefile transfer", "Back"]
):
case "Back":
return False
case "Prepare for savefile transfer":
print(
"This tool is for transfering your savefile to another device without causing the tamper detection."
)
print(
"If you confirm, the game will save and then exit, at this point you will copy your game files and saves folder over."
)
print(
"DO NOT RELAUNCH THE GAME before copying or it will undo this tool"
)
if ui.confirm():
data.save.save(self.cat)
return True
return False
def options_menu(self):
while True:
match ui.select(
"Please choose an option",
["Save", "Save and quit", "Quit", "Settings", "Back"],
):
case "Save":
data.save.save(self.cat)
print("Saved")
case "Save and quit":
print("Goodbye!")
data.save.save(self.cat)
return True
case "Quit":
if ui.confirm("Are you sure you want to quit without saving?"):
print("Goodbye!")
return True
case "Settings":
if self.settings():
return True
case "Back":
return False
def new_game(self):
self.cat = shelter()
if not os.path.exists("WEB_VERSION"):
print("Saving...")
data.save.save(self.cat)
print("Save complete.")
self.game_loop()
# TODO: Add shop, make food buyable and add money system
def game_loop(self):
ui.current_cat = self.cat
while True:
match ui.select(
"Please choose an option",
["Go to your house", "Go to the shop", "Options"],
):
case "Go to your house":
house(self.cat)
case "Go to the shop":
shop(self.cat)
case "Options":
if self.options_menu():
return
def run(self):
title()
if os.path.exists("WEB_VERSION"):
print(
"This is a web version of Whiskerbound, saving/loading is disabled. As soon as you quit this page, your savefile is gone."
)
if os.path.exists("debug.json"):
bypass_tamper_check = False
debug_config = None
with open("debug.json", "r") as f:
content = f.read()
if content.strip():
debug_config = json.loads(content)
if debug_config:
if debug_config.get("bypass_tamper_check_message", None):
if (
debug_config["bypass_tamper_check_message"]
== data.text.BYPASS_TAMPER_CHECK_MESSAGE
):
if debug_config.get("bypass_tamper_check_enable", False):
bypass_tamper_check = True
if debug_config.get("auto_load_savefile", None):
try:
self.cat = data.save.load(
debug_config["auto_load_savefile"],
bypass_tamper_check=bypass_tamper_check,
)
self.game_loop()
except:
print(
"There was an error loading the autoload savefile, please check your configuration."
)
else:
print(f"{self.cat.name} says bye")
return
options = ["New Game", "Quit"]
if os.path.exists("saves") and not os.path.exists("WEB_VERSION"):
options.insert(0, "Load Game")
print("Welcome to Whiskerbound!")
choice = ui.select("Please choose an option", choices=options)
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()
elif choice == "Quit":
quit()
if __name__ == "__main__":
game = Game()
game.run()