add more types of interactables
This commit is contained in:
parent
48abadce1d
commit
7ddef14360
4 changed files with 85 additions and 14 deletions
|
@ -1,3 +1,10 @@
|
|||
# v0.4.1
|
||||
## Added features
|
||||
* more interactable types:
|
||||
* `input` provides case insensitive input checking
|
||||
* `exact input` provides exact input checking
|
||||
* `item check`, `item take` provides item checking
|
||||
|
||||
# v0.4.0
|
||||
## Breaking changes
|
||||
* `title` moved to metadata table.
|
||||
|
|
|
@ -12,7 +12,7 @@ see docs.toml
|
|||
see test-game/manifest.setage
|
||||
|
||||
## Planned Features
|
||||
* more interactable types:
|
||||
* `input` provides case insensitive input checking
|
||||
* `exact input` provides exact input checking
|
||||
* `item` provides item checking
|
||||
* [x] more interactable types:
|
||||
* [x] `input` provides case insensitive input checking
|
||||
* [x] `exact input` provides exact input checking
|
||||
* [x] `item check`, `item take` provides item checking
|
||||
|
|
|
@ -40,8 +40,9 @@ item = "description" # item can be any valid id. description is a short descript
|
|||
|
||||
[rooms.id.interactables.id] # Optional. Any valid id.
|
||||
name = "name of the interactable" # appears in the room listing.
|
||||
type = "bare" # optional, default; options: "bare".
|
||||
times = "one" # optional, default; options: "one", "change", "remove", "many".
|
||||
type = "bare" # optional, default; options: "bare", "item check", "item take", "inputimes = "one" # optional, default; options: "one", "change", "remove", "many".
|
||||
check = "id" # Required if type is not "bare", id of the item or input to check for.
|
||||
prompt = "> " # Optional, for type `input` and `exact input`, prompt for the input.
|
||||
hidden = false # optional, default.
|
||||
action = "add exit" # any of "add exit", "add exits", "add item", "add items", "reveal interactable".
|
||||
target_room = "id" # any valid room id; changes will be made to that room.
|
||||
|
@ -58,6 +59,7 @@ target_items = [ # list of inline tables.
|
|||
]
|
||||
target_items.id = "description" # another way to do that.
|
||||
|
||||
message_failed = "> I don't seem to be able to do anything with that..." # Optional, default, message if the interaction fails
|
||||
message = "message after the interactable is activated" # Required.
|
||||
|
||||
[rooms.id.exits] # Technically optional.
|
||||
|
|
78
setage.py
78
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.4.0.3"
|
||||
__version__ = "0.4.1"
|
||||
__maintainer__ = "Cheri Dawn"
|
||||
__status__ = "Prototype"
|
||||
|
||||
|
@ -20,7 +20,7 @@ metadata = {}
|
|||
scenario = {}
|
||||
rooms = {}
|
||||
current_room_id = ""
|
||||
inventory = []
|
||||
inventory = {}
|
||||
|
||||
|
||||
def parse_version(ver):
|
||||
|
@ -134,9 +134,9 @@ class SetageShell(Cmd):
|
|||
elif arg in ("inv", "inventory"):
|
||||
if len(inventory) == 0:
|
||||
print("Your inventory is empty.")
|
||||
for k, v in inventory:
|
||||
for k, v in inventory.items():
|
||||
print(f"You have {v} [{k}].")
|
||||
elif arg in dict(inventory).keys():
|
||||
elif arg in inventory.keys():
|
||||
if "examine" in manifest["items"][arg]:
|
||||
print(manifest["items"][arg]["examine"])
|
||||
else:
|
||||
|
@ -171,7 +171,7 @@ class SetageShell(Cmd):
|
|||
all_items = manifest["items"]
|
||||
if "interactables" in rooms[current_room_id]:
|
||||
all_items.update(rooms[current_room_id]["interactables"])
|
||||
items = dict(inventory)
|
||||
items = inventory.copy()
|
||||
if "items" in rooms[current_room_id]:
|
||||
items.update(rooms[current_room_id]["items"])
|
||||
if "interactables" in rooms[current_room_id]:
|
||||
|
@ -212,6 +212,65 @@ class SetageShell(Cmd):
|
|||
can_activate = True
|
||||
else:
|
||||
can_activate = True
|
||||
elif inter["type"] == "item check":
|
||||
if "check" not in inter:
|
||||
print("FATAL: "
|
||||
"`check` id not in interactable with type `item` "
|
||||
f"in interactable '{arg}'")
|
||||
exit(2)
|
||||
if inter["check"] in inventory.keys():
|
||||
can_activate = True
|
||||
else:
|
||||
can_activate = False
|
||||
elif inter["type"] == "item take":
|
||||
if "check" not in inter:
|
||||
print("FATAL: "
|
||||
"`check` id not in interactable with type `item` "
|
||||
f"in interactable '{arg}'")
|
||||
exit(2)
|
||||
if inter["check"] in inventory.keys():
|
||||
can_activate = True
|
||||
inventory.pop(inter["check"])
|
||||
else:
|
||||
can_activate = False
|
||||
elif inter["type"] == "input":
|
||||
if "check" not in inter:
|
||||
print("FATAL: "
|
||||
"`check` string not in interactable "
|
||||
"with type `input` "
|
||||
f"in interactable '{arg}'")
|
||||
exit(2)
|
||||
if "prompt" not in inter:
|
||||
prompt = "> "
|
||||
else:
|
||||
prompt = inter["prompt"]
|
||||
try:
|
||||
i = input(prompt).strip().casefold()
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print()
|
||||
if i == inter["check"]:
|
||||
can_activate = True
|
||||
elif inter["type"] == "exact input":
|
||||
if "check" not in inter:
|
||||
print("FATAL: "
|
||||
"`check` string not in interactable "
|
||||
"with type `exact input` "
|
||||
f"in interactable '{arg}'")
|
||||
exit(2)
|
||||
if "prompt" not in inter:
|
||||
prompt = "> "
|
||||
else:
|
||||
prompt = inter["prompt"]
|
||||
try:
|
||||
i = input(prompt)
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print()
|
||||
if i == inter["check"]:
|
||||
can_activate = True
|
||||
else:
|
||||
print("FATAL: "
|
||||
f"invalid `type` '{inter["type"]}' "
|
||||
f"in interactable '{arg}'")
|
||||
if can_activate:
|
||||
if "target_room" not in inter:
|
||||
target_room = current_room_id
|
||||
|
@ -332,7 +391,10 @@ class SetageShell(Cmd):
|
|||
cur_room = manifest["rooms"][current_room_id]
|
||||
cur_room["interactables"].pop(arg)
|
||||
else:
|
||||
print("> I don't seem to be able to do anything with that...")
|
||||
if "message_failed" in inter:
|
||||
print(inter["message_failed"])
|
||||
else:
|
||||
print("> I don't seem to be able to do anything with that...")
|
||||
elif arg == "":
|
||||
print("> What should I interact with?")
|
||||
else:
|
||||
|
@ -395,7 +457,7 @@ class SetageShell(Cmd):
|
|||
print("> I don't see anything that I could take...")
|
||||
return
|
||||
if arg in cur_room["items"].keys():
|
||||
inventory.append((arg, cur_room["items"].pop(arg)))
|
||||
inventory.update({arg: cur_room["items"].pop(arg)})
|
||||
print(f"{arg} added to inventory.")
|
||||
else:
|
||||
print("> I don't see anything like that...")
|
||||
|
@ -452,7 +514,7 @@ class SetageShell(Cmd):
|
|||
for ending in endings:
|
||||
end = endings[ending]
|
||||
if end["trigger"] == "item":
|
||||
if end["target"] in dict(inventory).keys():
|
||||
if end["target"] in inventory.keys():
|
||||
if "message" not in end:
|
||||
print(f"WARNING: no message for ending '{ending}'")
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue