This repository has been archived on 2022-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
texty/loader.py
Matyáš Caras 4055c92353 Base
2021-11-02 17:40:54 +01:00

37 lines
1.2 KiB
Python

import yaml
from yaml.loader import SafeLoader
class Game:
def __init__(self,name:str,author:str,game:dict):
self.name = name
self.author = author
self.current = "start"
self.nodes = {}
for k in game:
self.nodes.update({k:game[k]})
def make_selection(self,selection):
if(selection >= len(self.nodes[self.current][selection]) or selection < 0):
print("Invalid selection")
else:
self.current = self.nodes[self.current][selection]
def printme(self):
'''
Used to print out the current prompt with the options
'''
print(self.nodes[self.current]["text"])
print("")
ostring = ""
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): ")
def load(file_path):
'''Loads the game from a YAML file to a Game class'''
with open(file_path) as f:
data = yaml.load(f,Loader=SafeLoader)
g = Game(data["meta"]["name"],data["meta"]["creator"],data["game"])
return g