Working on inventory
This commit is contained in:
parent
b1573d8b4a
commit
5cf11374f4
3 changed files with 38 additions and 17 deletions
12
example.yml
12
example.yml
|
@ -4,7 +4,7 @@ meta: # make sure every key is in lowercase
|
|||
|
||||
game: # here goes all the game logic
|
||||
start: # the starting point always HAS to be named "start" (lowercase), the order and name of the rest does not matter
|
||||
text: "{welcome}&bYou arrive to a small tavern in the middle of nowhere.\nYou are greeted with a non-welcoming look on the faces of all the customers." # here is the text, which gets printed
|
||||
text: "&bYou arrive to a small tavern in the middle of nowhere.\nYou are greeted with a non-welcoming look on the faces of all the customers." # here is the text, which gets printed
|
||||
actions: # here you add a list of actions that are inside of `game`, the user can select them
|
||||
- wave
|
||||
- sit
|
||||
|
@ -14,4 +14,14 @@ game: # here goes all the game logic
|
|||
sit: # if no `actions` are supplied, the game exits
|
||||
description: "Sit down"
|
||||
text: "You quietly sit down and check the menu."
|
||||
actions:
|
||||
- beer
|
||||
- nothing
|
||||
beer:
|
||||
description: "Order beer"
|
||||
text: "You order some &ebeer"
|
||||
add_inventory: "Beer" # add something to inventory
|
||||
nothing:
|
||||
description: "Do nothing"
|
||||
text: "You sit and wait..."
|
||||
|
||||
|
|
11
lib/ascii.py
11
lib/ascii.py
|
@ -1,7 +1,7 @@
|
|||
from tempfile import TemporaryDirectory
|
||||
from zipfile import ZipFile
|
||||
from os import listdir
|
||||
|
||||
import yaml
|
||||
class AsciiAnimation:
|
||||
def __init__(self) -> None:
|
||||
self.frames = []
|
||||
|
@ -16,8 +16,11 @@ class AsciiAnimation:
|
|||
with ZipFile(f"./assets/{name}.asc","r") as z: # extract the asc file
|
||||
z.extractall(f"{tmpdir}/ascii/{name}")
|
||||
for f in listdir(f"{tmpdir}/ascii/{name}"): # read all the files
|
||||
if f.endswith("yaml"):
|
||||
# TODO: load asc config file
|
||||
if f == "config.yml":
|
||||
with open(f"{tmpdir}/ascii/{name}/{f}",encoding="utf-8") as c:
|
||||
data = yaml.load(c,Loader=yaml.SafeLoader)
|
||||
if(data["speed"] != None):
|
||||
self.speed = data["speed"]
|
||||
pass
|
||||
with open(f"{tmpdir}/ascii/{name}/{f}") as f: # add all frames into list
|
||||
with open(f"{tmpdir}/ascii/{name}/{f}",encoding="utf-8") as f: # add all frames into list
|
||||
self.frames.append(f.read())
|
28
lib/game.py
28
lib/game.py
|
@ -12,16 +12,24 @@ class Game:
|
|||
self.author = data["meta"]["creator"]
|
||||
self.current = "start"
|
||||
self.nodes = {}
|
||||
self.inventory = []
|
||||
for k in data["game"]:
|
||||
self.nodes.update({k:data["game"][k]})
|
||||
|
||||
def make_selection(self,selection:int) -> bool:
|
||||
if(type(selection) != int or selection >= len(self.nodes[self.current]["actions"]) or selection < 0):
|
||||
def make_selection(self) -> int:
|
||||
y = False
|
||||
selection = 0
|
||||
# TODO: Check for "has_item"
|
||||
while y == False:
|
||||
try:
|
||||
selection = int(input("Make a selection (number): "))
|
||||
except ValueError:
|
||||
print("Not a number selection")
|
||||
if(selection >= len(self.nodes[self.current]["actions"]) or selection < 0):
|
||||
print("Invalid selection")
|
||||
return False
|
||||
else:
|
||||
self.current = self.nodes[self.current]["actions"][selection]
|
||||
return True
|
||||
y = True
|
||||
return selection
|
||||
|
||||
def print_text(self):
|
||||
'''
|
||||
|
@ -38,11 +46,11 @@ class Game:
|
|||
for i,option in enumerate(self.nodes[self.current]["actions"]):
|
||||
ostring+=f"{i} - {self.nodes[option]['description']}\n"
|
||||
print(ostring)
|
||||
sel = input("Make a selection (number): ")
|
||||
isWrong = self.make_selection(int(sel))
|
||||
while isWrong == False:
|
||||
sel = input("Make a selection (number): ")
|
||||
isWrong = self.make_selection(sel)
|
||||
sel = self.make_selection()
|
||||
if(self.nodes[self.current]["add_inventory"] is not None):
|
||||
# add item to inventory
|
||||
self.inventory.append(self.nodes[self.current]["add_inventory"])
|
||||
self.current = self.nodes[self.current]["actions"][sel]
|
||||
self.print_text()
|
||||
|
||||
def print_animated(self,animid):
|
||||
|
|
Reference in a new issue