This commit is contained in:
2026-06-24 19:39:09 -04:00
parent 43539a3255
commit e4ad34faa1
5 changed files with 47 additions and 8 deletions

View File

@@ -1,9 +1,9 @@
from untitled import model, persistence from untitled import content, model, persistence
def test_save_load_roundtrip(tmp_path): def test_save_load_roundtrip(tmp_path):
original = model.Save( original = model.Save(
version=1, version=content.SAVE_VERSION,
cat=model.Cat( cat=model.Cat(
"Fry", "Fry",
{ {
@@ -23,7 +23,7 @@ def test_save_load_roundtrip(tmp_path):
"eyes": "blue", "eyes": "blue",
"personality": "judges you silently", "personality": "judges you silently",
} }
assert loaded.version == 1 assert loaded.version == content.SAVE_VERSION
def test_list_saves(tmp_path): def test_list_saves(tmp_path):

View File

@@ -1,7 +1,9 @@
STUDIO_NAME = "Untitled Randomness Studios" # Titled Randomness Studios STUDIO_NAME = "Untitled Randomness Studios" # Titled Randomness Studios
GAME_NAME = "Untitled Cat Game" # Titled Cat Game GAME_NAME = "Untitled Cat Game" # Titled Cat Game
SAVE_VERSION = 1 SAVE_VERSION = 2
HUNGER_DECAY_PER_HOUR = 5
CAT_COLORS = [ CAT_COLORS = [
"orange tabby", "orange tabby",

View File

@@ -1,5 +1,14 @@
import time
_MIGRATIONS = {} # TODO: ADD HUNGER AND LAST PLAYED MIGRATION
def _v1_to_v2(data):
data["cat"]["hunger"] = 100
data["cat"]["last_updated"] = time.time()
data["version"] = 2
return data
_MIGRATIONS = {1: _v1_to_v2} # TODO: ADD HUNGER AND LAST PLAYED MIGRATION
def migrate(data): def migrate(data):

View File

@@ -1,5 +1,7 @@
import string import string
from untitled import content
def validate_cat_name(name, auto_gen=False): def validate_cat_name(name, auto_gen=False):
ALLOWED = set(string.ascii_letters + string.digits) ALLOWED = set(string.ascii_letters + string.digits)
@@ -13,3 +15,19 @@ def validate_cat_name(name, auto_gen=False):
return "Your cat's name can only have letters and numbers." return "Your cat's name can only have letters and numbers."
if not any(c in string.ascii_letters for c in name): if not any(c in string.ascii_letters for c in name):
return "Your cat's name needs at least 1 letter." return "Your cat's name needs at least 1 letter."
def reconcile(cat, now):
elapsed_hours = (now - cat.last_updated) / 3600
if elapsed_hours <= 0:
return
cat.hunger -= content.HUNGER_DECAY_PER_HOUR * elapsed_hours
if cat.hunger < 0:
cat.hunger = 0
cat.last_updated = now
def feed(cat, amount=100):
cat.hunger += amount
if cat.hunger > 100:
cat.hunger = 100

View File

@@ -1,13 +1,23 @@
from untitled import model, persistence, ui import time
from untitled import generation, model, persistence, rules, ui
from untitled.screens.common import options from untitled.screens.common import options
def house(save: model.Save): def house(save: model.Save):
print("Welcome to your house!") print("Welcome to your house!")
while True: while True:
match ui.select("What do you want to do?", ["Check on your cat", "Menu"]): match ui.select(
"What do you want to do?", ["Check on your cat", "Feed your cat", "Menu"]
):
case "Check on your cat": case "Check on your cat":
print(save.cat.name) rules.reconcile(save.cat, time.time())
print(
f"{save.cat.name}, {generation.generate_trait_sentence(save.cat.traits).lower()}\nFullness: {round(save.cat.hunger,1)}"
)
case "Feed your cat":
rules.feed(save.cat)
print(f"You feed {save.cat.name}, {save.cat.name} is now full.")
case "Menu": case "Menu":
result = options() result = options()
match result: match result: