Ascii now a class

This commit is contained in:
Matyáš Caras 2022-01-26 09:23:30 +01:00
parent 0b6d9b287c
commit 2a7581336b
3 changed files with 23 additions and 16 deletions

View file

@ -2,7 +2,7 @@ from sys import argv
from lib.game import * from lib.game import *
from colorama import init from colorama import init
def main(): def main(): # TODO: Maybe a menu for available text games?
init() init()
if len(argv)<2: if len(argv)<2:
print("You need to specify a path to a YAML file") print("You need to specify a path to a YAML file")

View file

@ -2,16 +2,22 @@ from tempfile import TemporaryDirectory
from zipfile import ZipFile from zipfile import ZipFile
from os import listdir from os import listdir
def ascii_art(name): class AsciiAnimation:
def __init__(self) -> None:
self.frames = []
self.speed = 0.2
def load_ascii(self,name:str):
""" """
Returns ASCII by name Returns ASCII by name
""" """
a = []
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir: # we enter a temporary directory
with ZipFile(f"./assets/{name}.asc","r") as z: with ZipFile(f"./assets/{name}.asc","r") as z: # extract the asc file
z.extractall(f"{tmpdir}/ascii/{name}") z.extractall(f"{tmpdir}/ascii/{name}")
for f in listdir(f"{tmpdir}/ascii/{name}"): for f in listdir(f"{tmpdir}/ascii/{name}"): # read all the files
with open(f"{tmpdir}/ascii/{name}/{f}") as f: if f.endswith("yaml"):
a.append(f.read()) # TODO: load asc config file
return a pass
with open(f"{tmpdir}/ascii/{name}/{f}") as f: # add all frames into list
self.frames.append(f.read())

View file

@ -2,7 +2,7 @@ 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 import re
from .ascii import ascii_art from .ascii import AsciiAnimation
from time import sleep from time import sleep
from os import system from os import system
@ -51,7 +51,8 @@ class Game:
currently only prints out the first occurence of an animated text currently only prints out the first occurence of an animated text
(in curly braces) (in curly braces)
''' '''
animation = ascii_art(animid) animation = AsciiAnimation()
animation.load_ascii(animid)
for frame in animation: for frame in animation:
system("cls||clear") system("cls||clear")
print(frame) print(frame)