multiple endings in template, fix a bug
This commit is contained in:
parent
a7ede1db3f
commit
8c816a4afb
2 changed files with 70 additions and 25 deletions
|
@ -9,8 +9,8 @@ from base64 import b64decode
|
|||
|
||||
__author__ = "Cheri Dawn"
|
||||
__copyright__ = "Copyright 2024, Cheri Dawn"
|
||||
__license__ = "GPLv3"
|
||||
__version__ = "0.2.0"
|
||||
__license__ = "GPL-3.0-only"
|
||||
__version__ = "0.3.0"
|
||||
__maintainer__ = "Cheri Dawn"
|
||||
__status__ = "Prototype"
|
||||
|
||||
|
@ -60,7 +60,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"]}")
|
||||
|
||||
|
@ -128,14 +128,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)
|
||||
|
@ -157,6 +165,9 @@ class SetageShell(Cmd):
|
|||
"""Interact with a <thing>"""
|
||||
global current_room_id, manifest
|
||||
cur_room = manifest["rooms"][current_room_id]
|
||||
if "interactables" not in cur_room:
|
||||
print("> Nothing to interact with here...")
|
||||
return
|
||||
inters = cur_room["interactables"]
|
||||
if arg in inters.keys():
|
||||
inter = inters[arg]
|
||||
|
@ -393,17 +404,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__":
|
||||
|
@ -420,19 +447,13 @@ if __name__ == "__main__":
|
|||
manifest = toml_loads(data)
|
||||
except (TOMLDecodeError) as e:
|
||||
ec = e.__class__
|
||||
fatal = "FATAL: embedded manifest"
|
||||
fatal = f"FATAL: embedded manifest"
|
||||
if ec == TOMLDecodeError:
|
||||
print(f"{fatal} isn't a valid toml file. "
|
||||
"Try running with `-b` flag.")
|
||||
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.")
|
||||
|
@ -454,17 +475,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"]
|
||||
|
|
|
@ -166,6 +166,9 @@ class SetageShell(Cmd):
|
|||
"""Interact with a <thing>"""
|
||||
global current_room_id, manifest
|
||||
cur_room = manifest["rooms"][current_room_id]
|
||||
if "interactables" not in cur_room:
|
||||
print("> Nothing to interact with here...")
|
||||
return
|
||||
inters = cur_room["interactables"]
|
||||
if arg in inters.keys():
|
||||
inter = inters[arg]
|
||||
|
|
Loading…
Reference in a new issue