From e4ad34faa1e12f4decf2e67dc5f6c8d3caff61a6 Mon Sep 17 00:00:00 2001 From: Toasterkitten Date: Wed, 24 Jun 2026 19:39:09 -0400 Subject: [PATCH] food --- tests/test_persistence.py | 6 +++--- untitled/content.py | 4 +++- untitled/migration.py | 11 ++++++++++- untitled/rules.py | 18 ++++++++++++++++++ untitled/screens/house.py | 16 +++++++++++++--- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 67a2c63..57fa8a5 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -1,9 +1,9 @@ -from untitled import model, persistence +from untitled import content, model, persistence def test_save_load_roundtrip(tmp_path): original = model.Save( - version=1, + version=content.SAVE_VERSION, cat=model.Cat( "Fry", { @@ -23,7 +23,7 @@ def test_save_load_roundtrip(tmp_path): "eyes": "blue", "personality": "judges you silently", } - assert loaded.version == 1 + assert loaded.version == content.SAVE_VERSION def test_list_saves(tmp_path): diff --git a/untitled/content.py b/untitled/content.py index 359a011..5a408b2 100644 --- a/untitled/content.py +++ b/untitled/content.py @@ -1,7 +1,9 @@ STUDIO_NAME = "Untitled Randomness Studios" # Titled Randomness Studios GAME_NAME = "Untitled Cat Game" # Titled Cat Game -SAVE_VERSION = 1 +SAVE_VERSION = 2 + +HUNGER_DECAY_PER_HOUR = 5 CAT_COLORS = [ "orange tabby", diff --git a/untitled/migration.py b/untitled/migration.py index c31b5c3..5fbec63 100644 --- a/untitled/migration.py +++ b/untitled/migration.py @@ -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): diff --git a/untitled/rules.py b/untitled/rules.py index 11cbc98..967dadf 100644 --- a/untitled/rules.py +++ b/untitled/rules.py @@ -1,5 +1,7 @@ import string +from untitled import content + def validate_cat_name(name, auto_gen=False): 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." if not any(c in string.ascii_letters for c in name): 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 diff --git a/untitled/screens/house.py b/untitled/screens/house.py index 2115604..f33e32f 100644 --- a/untitled/screens/house.py +++ b/untitled/screens/house.py @@ -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 def house(save: model.Save): print("Welcome to your house!") 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": - 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": result = options() match result: