From 6ee470aa1bc6fdbdafa9c79560117308265ec776 Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Wed, 8 Mar 2023 01:59:16 -0500 Subject: [PATCH] [+] AsciiArt data structure --- tngame/telnet.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tngame/telnet.py b/tngame/telnet.py index ad1a9ce..260ed02 100644 --- a/tngame/telnet.py +++ b/tngame/telnet.py @@ -3,25 +3,34 @@ import os import random import time from dataclasses import dataclass -from typing import NamedTuple import telnetlib3 from hyfetch.color_util import RGB from telnetlib3 import TelnetReaderUnicode, TelnetWriterUnicode -from .utils import setup_logger +from .utils import setup_logger, get_ascii_dimensions DEBUG = bool(os.environ.get("DEBUG", False)) log = setup_logger(DEBUG) -ASCII_CAT = r""" - /\_/\ - ( | | ) - > < """.strip('\n') +class AsciiArt: + """An ASCII art object.""" + art: str + h: int + w: int + credit: str + + def __init__(self, art: str, credit: str): + self.art = art.strip("\n") + self.h, self.w = get_ascii_dimensions(self.art) + + +ASC_CAT = AsciiArt(r""" + /\_/\ +( | | ) + > < """, "Azalea") -ASCII_HEIGHT = ASCII_CAT.count('\n') -ASCII_WIDTH = max(len(line.strip('\n')) for line in ASCII_CAT.splitlines()) SNOW_DENSITY = 0.05 # Snow particles per pixel on screen SNOW_SPEED = 8 # Snow fall speed in pixels per second