Files
Whiskerbound/systems/debug.py

160 lines
7.2 KiB
Python

import os
import json
import data.save
import systems.ui # should cause circular import but doesn't, so not fixing it
import data.text
import data.cat
def fix_hash(current_cat):
data_dir = data.save.get_data_dir()
hash_path = os.path.join(data_dir, "dont hurt cats.json")
os.makedirs(data_dir, exist_ok=True)
if os.path.exists(hash_path):
with open(hash_path, "r") as f:
currentjson = json.load(f)
old_hash = currentjson[f"saves/{current_cat.name}.kitten"]
currentjson[f"saves/{current_cat.name}.kitten"] = data.save.hash_file(
f"saves/{current_cat.name}.kitten"
)
print(
f"Old hash: {old_hash}. New hash: {currentjson[f"saves/{current_cat.name}.kitten"]}"
)
with open(hash_path, "w") as f:
json.dump(currentjson, f)
def debug_menu(current_cat: data.cat.Cat):
print("hi")
while True:
match systems.ui.select(
"choose ur way of breaking the game",
[
"Breakpoint",
"Fix hash",
"Remove depression and sickness and max out both",
"FREE MONEY!!!",
"Instantly quit the game without saving",
"Debug settings",
"Back",
],
hide_debug=True,
):
case "Remove depression and sickness and max out both":
current_cat.depressed = False
current_cat.sick = False
current_cat.happiness = 100
current_cat.fullness = 100
print("Done")
case "FREE MONEY!!!":
print(f"You have ${current_cat.money} right now.")
try:
current_cat.money = (
int(
systems.ui.text(
"Enter the amount of money to SET the money to, not add, SET:"
)
)
or current_cat.money
)
except:
print("wat")
case "Instantly quit the game without saving":
exec(
"instantly quit the game without saving"
) # i mean, i quit it, what more do you want?
case "Breakpoint":
print(
"In this context, the cat is not cat or self.cat, use current_cat instead."
)
print("DON'T TYPE EXIT! Instead run 'c' as code.")
breakpoint()
case "Fix hash":
fix_hash(current_cat)
print(
"If you see this message and theres no errors above I think it worked."
)
case "Debug settings":
while True:
with open("debug.json", "r") as f:
config = json.load(f)
enabled = config.get("bypass_tamper_check_enable", False)
label = "Disable" if enabled else "Enable"
match systems.ui.select(
"choose a setting",
[
systems.ui.Choice(
title=f"{label} hash bypass",
value="Toggle tamper check",
),
"Configure auto savefile loading",
"Back",
],
hide_debug=True,
):
case "Toggle tamper check":
if (
config["bypass_tamper_check_message"]
!= data.text.BYPASS_TAMPER_CHECK_MESSAGE
):
print(
"If you already did this, you may have typed it wrong."
)
print(
"You need to set the message that you will not use this to cheat. Please type the following message EXACTLY."
)
print(data.text.BYPASS_TAMPER_CHECK_MESSAGE)
response = systems.ui.text("Type here:")
config["bypass_tamper_check_message"] = response
config["bypass_tamper_check_enable"] = not enabled
with open("debug.json", "w") as f:
json.dump(config, f)
case "Configure auto savefile loading":
while True:
print(
"Currently loads:",
config.get("auto_load_savefile", "Unset"),
)
match systems.ui.select(
"Please choose an option",
[
"Change file to load",
"Unset auto savefile loading",
"Back",
],
hide_debug=True,
):
case "Back":
break
case "Change file to load":
print("Press enter to cancel")
file = systems.ui.filepath(
'Please enter the path to your savefile (if it is in the normal "saves" folder, starts with saves/), eg: saves/example.kitten:',
default="",
)
if file:
if os.path.exists(file):
config["auto_load_savefile"] = file
with open("debug.json", "w") as f:
json.dump(config, f)
else:
print("This is an invalid path!")
else:
print("Cancelled.")
case "Unset auto savefile loading":
try:
del config["auto_load_savefile"]
except KeyError:
print(
"The autoload was already unset! Nothing was changed."
)
else:
with open("debug.json", "w") as f:
json.dump(config, f)
print("Done")
case "Back":
break
case "Back":
break