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 colorama import init
def main():
def main(): # TODO: Maybe a menu for available text games?
init()
if len(argv)<2:
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 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
"""
a = []
with TemporaryDirectory() as tmpdir:
with ZipFile(f"./assets/{name}.asc","r") as z:
with TemporaryDirectory() as tmpdir: # we enter a temporary directory
with ZipFile(f"./assets/{name}.asc","r") as z: # extract the asc file
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
for f in listdir(f"{tmpdir}/ascii/{name}"): # read all the files
if f.endswith("yaml"):
# TODO: load asc config file
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 colorama import Fore, Back, Style
import re
from .ascii import ascii_art
from .ascii import AsciiAnimation
from time import sleep
from os import system
@ -51,7 +51,8 @@ class Game:
currently only prints out the first occurence of an animated text
(in curly braces)
'''
animation = ascii_art(animid)
animation = AsciiAnimation()
animation.load_ascii(animid)
for frame in animation:
system("cls||clear")
print(frame)