From c23ae322408eea615a7a48f3b84a81000e6b418b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Tue, 25 Jan 2022 17:16:07 +0100 Subject: [PATCH] Add animated text??? --- .gitignore | 2 +- __main__.py | 4 ++-- assets/welcome.asc | Bin 0 -> 1699 bytes example.yml | 2 +- lib/ascii.py | 17 +++++++++++++++++ game.py => lib/game.py | 24 +++++++++++++++++++++--- 6 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 assets/welcome.asc create mode 100644 lib/ascii.py rename game.py => lib/game.py (71%) 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 0000000000000000000000000000000000000000..612c9678bc3377186a048f9ee955d41ade3a15f3 GIT binary patch literal 1699 zcmWIWW@Zs#U|`^2&}p^|k(Zk#kObseGBPmm0_pP9oaFr6)OZ8El8Tbr07tF{1D@U7 z{}j!?Ub$Z(b)@~vM>W|+8xk+;y!2Xld)FG_2l^IYPP&VBZqYn+Y3}*N4V()_G-eA; z^UXODIz6;s+jLFPX%?ay`#&brN7@{aeC@e_|EO__5SzMgnh(;hZs*ZkPi`x^Bt@3p&z zWi0gEcr;`KyY0)O>wkVPa#u%n*P36)lk$M>@<(%*5!78=2NZZ%-n0JSuzlO|Kg*Uo z{F-31?`E#!#-G+%gUtmM?U`%79^N8y%Pzyp|8u`V#1Yw(0=Cun zO1#oSWYvQrTUjUR#E9B&Dfryv+4=OA_W@z=2P;-Q)t__Q+G5R&YkPK^nmth{+iuRs z|G447w+9^i=Pb?244YSfzw9*&s@q!R)~132Eey?VCJ?t-^8o|R`McL0#pvUAmI(({ zO_15QO>lpggd|gCr_0V$j%Lb9^F+jy7v~-o4YD}WwI!rYnP+{8DFjnl~$P5a%yO{y<7>EMZM^YiyqCsod?%YDU+>ahP3YG<>t z1ez(tVHbH1C~&y^pS|O7?g6vEN{NDP?+cerm9i{me7dkO=CQ(-j)<8|A45|&D?jqL zTxzf?N_b_LChxgZymxwJMYH2nX0xbG^E|is%A8)+s^-(Hvg2;AIseGIOib<=>qM0& z|7MBCJFhx%dAqJHs;l@Jv=TtBibo4BGmxul`>?rcTWE6dxfq9v4C`C%2Chd=h;(e% zdM#|*9}&4+#4Xf%;;I>!9;~@@z}qxDVoT*l8R1zHYCBin3z(!{v8L_U?#aHZi+&d$ zOtcA@+;T^L^P_CfJN5rAvl8bjbGo~Vkx7IBcd-QwI0i-r1rP-UD1}&nH>y_jLI$J( zqO})EE4au(*NR>aAhfCiV-032xKu#bik?#uTK6Go1?O9It>_sEp*4yLVJkRWp=(7? z>Iki$k+gynKDt))^oY>f$&9cSoH~iuD$jz@3Qj@+-mGjOlR1F!1~4GD0u?YY006=2 BJ`Ml? literal 0 HcmV?d00001 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: '''