diff --git a/.gitignore b/.gitignore index a3ca28d..eee4de9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ dist/ downloads/ eggs/ .eggs/ -lib/ +#lib/ lib64/ parts/ sdist/ diff --git a/__main__.py b/__main__.py index e820bf5..555c3ae 100644 --- a/__main__.py +++ b/__main__.py @@ -1,5 +1,5 @@ from sys import argv -from game import * +from lib.game import * from colorama import init def main(): @@ -11,7 +11,7 @@ def main(): game = load(argv[1]) if(game is None): exit(1) - game.printme() + game.print_text() if __name__ == "__main__": main() \ No newline at end of file diff --git a/assets/welcome.asc b/assets/welcome.asc new file mode 100644 index 0000000..612c967 Binary files /dev/null and b/assets/welcome.asc differ diff --git a/example.yml b/example.yml index d3163ef..b9b3612 100644 --- a/example.yml +++ b/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: "&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: "{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 actions: # here you add a list of actions that are inside of `game`, the user can select them - wave - sit diff --git a/lib/ascii.py b/lib/ascii.py new file mode 100644 index 0000000..9e5ef6a --- /dev/null +++ b/lib/ascii.py @@ -0,0 +1,17 @@ +from tempfile import TemporaryDirectory +from zipfile import ZipFile +from os import listdir + +def ascii_art(name): + """ + Returns ASCII by name + """ + a = [] + + with TemporaryDirectory() as tmpdir: + with ZipFile(f"./assets/{name}.asc","r") as z: + z.extractall(f"{tmpdir}/ascii/{name}") + for f in listdir(f"{tmpdir}/ascii/{name}"): + with open(f"{tmpdir}/ascii/{name}/{f}") as f: + a.append(f.read()) + return a diff --git a/game.py b/lib/game.py similarity index 71% rename from game.py rename to lib/game.py index 9902603..9fcede6 100644 --- a/game.py +++ b/lib/game.py @@ -1,6 +1,9 @@ import yaml from yaml.loader import SafeLoader from colorama import Fore, Back, Style +import re +from .ascii import ascii_art +from time import sleep class Game: def __init__(self,data:dict): @@ -18,12 +21,15 @@ class Game: else: self.current = self.nodes[self.current]["actions"][selection] return True - - def printme(self): + def print_text(self): ''' Used to print out the current prompt with the options ''' + animated = re.search(r"(?!{).+(?=})",self.nodes[self.current]["text"]) # find the animated text + if(animated != None): + self.print_animated(animated.group(0)) + self.nodes[self.current]["text"] = self.nodes[self.current]["text"].replace(animated.group(0),"") # remove the animated text from the text prompt print(self.nodes[self.current]["text"]) print("") ostring = "" @@ -36,7 +42,19 @@ class Game: while isWrong == False: sel = input("Make a selection (number): ") isWrong = self.make_selection(sel) - self.printme() + self.print_text() + + def print_animated(self,animid): + ''' + Used to print out animated text, + currently only prints out the first occurence of an animated text + (in curly braces) + ''' + animation = ascii_art(animid) + for frame in animation: + print(frame) + sleep(0.2) + def parse_colors(self,text:str) -> str: '''