Add animated text???

This commit is contained in:
Matyáš Caras 2022-01-25 17:16:07 +01:00
parent d0cc24c193
commit c23ae32240
6 changed files with 42 additions and 7 deletions

2
.gitignore vendored
View file

@ -14,7 +14,7 @@ dist/
downloads/ downloads/
eggs/ eggs/
.eggs/ .eggs/
lib/ #lib/
lib64/ lib64/
parts/ parts/
sdist/ sdist/

View file

@ -1,5 +1,5 @@
from sys import argv from sys import argv
from game import * from lib.game import *
from colorama import init from colorama import init
def main(): def main():
@ -11,7 +11,7 @@ def main():
game = load(argv[1]) game = load(argv[1])
if(game is None): if(game is None):
exit(1) exit(1)
game.printme() game.print_text()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

BIN
assets/welcome.asc Normal file

Binary file not shown.

View file

@ -4,7 +4,7 @@ meta: # make sure every key is in lowercase
game: # here goes all the game logic 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 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 actions: # here you add a list of actions that are inside of `game`, the user can select them
- wave - wave
- sit - sit

17
lib/ascii.py Normal file
View file

@ -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

View file

@ -1,6 +1,9 @@
import yaml import yaml
from yaml.loader import SafeLoader from yaml.loader import SafeLoader
from colorama import Fore, Back, Style from colorama import Fore, Back, Style
import re
from .ascii import ascii_art
from time import sleep
class Game: class Game:
def __init__(self,data:dict): def __init__(self,data:dict):
@ -18,12 +21,15 @@ class Game:
else: else:
self.current = self.nodes[self.current]["actions"][selection] self.current = self.nodes[self.current]["actions"][selection]
return True return True
def printme(self): def print_text(self):
''' '''
Used to print out the current prompt with the options 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(self.nodes[self.current]["text"])
print("") print("")
ostring = "" ostring = ""
@ -36,7 +42,19 @@ class Game:
while isWrong == False: while isWrong == False:
sel = input("Make a selection (number): ") sel = input("Make a selection (number): ")
isWrong = self.make_selection(sel) 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: def parse_colors(self,text:str) -> str:
''' '''