add multiple endings support, fix up some things
This commit is contained in:
parent
0c307ade86
commit
a7ede1db3f
3 changed files with 68 additions and 27 deletions
|
@ -1,5 +1,6 @@
|
|||
[credits] # Optional but highly recommended.
|
||||
author = "who made the manifest for the game"
|
||||
contributors = [] # optional list of strings.
|
||||
year = "when it was made"
|
||||
license = "license for this manifest"
|
||||
|
||||
|
@ -11,11 +12,12 @@ intro = "intro to the game"
|
|||
prompt = "> " # optional, default shown.
|
||||
playtested = false # optional, default. displays a warning if this is set to false.
|
||||
|
||||
[scenario.win] # Required.
|
||||
[scenario.endings.1] # Required.
|
||||
trigger = "item" # one of "item", "room" ("interactable" in future releases).
|
||||
target = "id of the trigger" # which item, room (or interactable) should trigger the win.
|
||||
message = "message when the win is triggered"
|
||||
end = false # optional, default; exit the game after triggering?
|
||||
title = "title of the ending" # optional.
|
||||
message = "message when this ending is triggered"
|
||||
exit = false # optional, default; exit the game after triggering?
|
||||
|
||||
|
||||
[items] # Required.
|
||||
|
|
85
setage.py
85
setage.py
|
@ -11,7 +11,7 @@ from base64 import b64decode
|
|||
__author__ = "Cheri Dawn"
|
||||
__copyright__ = "Copyright 2024, Cheri Dawn"
|
||||
__license__ = "GPL-3.0-only"
|
||||
__version__ = "0.2.0"
|
||||
__version__ = "0.3.0"
|
||||
__maintainer__ = "Cheri Dawn"
|
||||
__status__ = "Prototype"
|
||||
|
||||
|
@ -61,7 +61,7 @@ def print_exits(cur_room):
|
|||
exit(2)
|
||||
if "description" not in rooms[v]:
|
||||
print("WARNING: "
|
||||
f"room '{v}' does not have a `description`.")
|
||||
f"room '{v}' ({k}) does not have a `description`.")
|
||||
continue
|
||||
print(f"Looking [{k}] you see {rooms[v]["description"]}")
|
||||
|
||||
|
@ -129,14 +129,22 @@ class SetageShell(Cmd):
|
|||
print(manifest["items"][arg]["examine"])
|
||||
else:
|
||||
print("It doesn't seem to be all that interesting...")
|
||||
elif arg in cur_room["interactables"].keys():
|
||||
cur_room["interactables"][arg]["hidden"] = False
|
||||
if "examine" in cur_room["interactables"][arg]:
|
||||
print(cur_room["interactables"][arg]["examine"])
|
||||
else:
|
||||
print("It doesn't seem to be all that interesting...")
|
||||
else:
|
||||
print("> I don't see anything like that...")
|
||||
|
||||
def complete_examine(self, text, line, bidx, eidx):
|
||||
global current_room_id
|
||||
all_items = manifest["items"]
|
||||
all_items.update(rooms[current_room_id]["interactables"])
|
||||
items = dict(inventory)
|
||||
items.update(rooms[current_room_id]["items"])
|
||||
items.update(rooms[current_room_id]["interactables"])
|
||||
items = [x for x in items if (not all_items[x]["hidden"])]
|
||||
if not text:
|
||||
return list(items)
|
||||
|
@ -394,17 +402,33 @@ class SetageShell(Cmd):
|
|||
|
||||
def check_win(self, arg=""):
|
||||
"""Check if you have won."""
|
||||
win = scenario["win"]
|
||||
if win["trigger"] == "item":
|
||||
if win["target"] in dict(inventory).keys():
|
||||
print(win["message"])
|
||||
if win["end"]:
|
||||
return True
|
||||
if win["trigger"] == "room":
|
||||
if current_room_id == win["target"]:
|
||||
print(win["message"])
|
||||
if win["end"]:
|
||||
return True
|
||||
endings = scenario["endings"]
|
||||
for ending in endings:
|
||||
end = endings[ending]
|
||||
if end["trigger"] == "item":
|
||||
if end["target"] in dict(inventory).keys():
|
||||
if "title" in end:
|
||||
print(end["title"])
|
||||
if "message" not in end:
|
||||
print(f"WARNING: no message for ending '{ending}'")
|
||||
else:
|
||||
print(end["message"])
|
||||
if "exit" not in end:
|
||||
continue
|
||||
if end["exit"]:
|
||||
return True
|
||||
if end["trigger"] == "room":
|
||||
if current_room_id == end["target"]:
|
||||
if "title" in end:
|
||||
print(end["title"])
|
||||
if "message" not in end:
|
||||
print(f"WARNING: no message for ending '{ending}'")
|
||||
else:
|
||||
print(end["message"])
|
||||
if "exit" not in end:
|
||||
continue
|
||||
if end["exit"]:
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -439,12 +463,6 @@ if __name__ == "__main__":
|
|||
print(f"FATAL: the following error occured: {e}")
|
||||
exit(1)
|
||||
|
||||
if "items" in manifest:
|
||||
for k, v in manifest["items"].items():
|
||||
if "hidden" not in v:
|
||||
v.update({"hidden": False})
|
||||
manifest["items"][k] = v
|
||||
|
||||
if "scenario" not in manifest:
|
||||
print("FATAL: "
|
||||
"table `scenario` does not exist in manifest.")
|
||||
|
@ -466,17 +484,38 @@ if __name__ == "__main__":
|
|||
print("FATAL: "
|
||||
"room id `start` does not exist in scenario.")
|
||||
exit(2)
|
||||
if "win" not in manifest["scenario"]:
|
||||
if "endings" not in manifest["scenario"]:
|
||||
print("FATAL: "
|
||||
"table `win` does not exist in scenario.")
|
||||
"table `endings` does not exist in scenario.")
|
||||
exit(2)
|
||||
|
||||
if "end" not in manifest["scenario"]["win"]:
|
||||
manifest["scenario"]["win"]["end"] = False
|
||||
if not isinstance(manifest["rooms"], dict):
|
||||
print("FATAL: "
|
||||
"`rooms` is not a table in scenario.")
|
||||
exit(2)
|
||||
if not isinstance(manifest["items"], dict):
|
||||
print("FATAL: "
|
||||
"`items` is not a table in scenario.")
|
||||
exit(2)
|
||||
if not isinstance(manifest["scenario"]["endings"], dict):
|
||||
print("FATAL: "
|
||||
"`endings` is not a table in scenario.")
|
||||
exit(2)
|
||||
|
||||
if "items" in manifest:
|
||||
for k, v in manifest["items"].items():
|
||||
if "hidden" not in v:
|
||||
v.update({"hidden": False})
|
||||
manifest["items"][k] = v
|
||||
|
||||
for k, v in manifest["rooms"].items():
|
||||
if "exits" not in v:
|
||||
v.update({"exits": dict()})
|
||||
for room in manifest["rooms"]:
|
||||
if "interactables" in manifest["rooms"][room]:
|
||||
for k, v in manifest["rooms"][room]["interactables"].items():
|
||||
if "hidden" not in v:
|
||||
v.update({"hidden": False})
|
||||
|
||||
scenario = manifest["scenario"]
|
||||
rooms = manifest["rooms"]
|
||||
|
|
|
@ -10,7 +10,7 @@ title = "Dust Bunnies"
|
|||
intro = "You wake up in a very dusty and old-looking room.\nYou think you can get out of here if you find something that could help you remember..."
|
||||
prompt = ": "
|
||||
|
||||
[scenario.win]
|
||||
[scenario.endings.1]
|
||||
trigger = "item"
|
||||
target = "shiny"
|
||||
message = "Congrats! You have found the old locket of your grandma."
|
||||
|
|
Loading…
Reference in a new issue