import pygame

class Text():
    def __init__(self,txt, font_size):
        pygame.font.init()
        self.color = pygame.Color("black")
        self.txt = txt
        self.font = pygame.font.Font(pygame.font.get_default_font(), font_size)
        self.text = self.font.render(self.txt, True, self.color)
        self.x = 0
        self.y = 0

    def setX(self, x):
        self.x = x
    def getX(self):
        return self.x

    def setY(self, y):
        self.y = y
    def getY(self):
        return self.y

    def get(self):
        return self.text

    def getSize(self):
        return self.text.get_size()

    def getWidth(self):
        return self.text.get_width()

    def setColor(self, color):
        try:
            self.color = pygame.Color(color)
        except:
            self.color = pygame.Color("black")
        self.text = self.font.render(self.txt, True, self.color)


class VariableText(Text):
    def __init__(self, txt, font_size):
        pygame.font.init()
        self.color = pygame.Color("black")
        self.txt = txt+"{}"
        self.font = pygame.font.Font(pygame.font.get_default_font(), font_size)
        self.text = self.font.render(self.txt.format(0), True, self.color)

    def setUnit(self, unit):
        self.txt = self.txt+unit
        self.unit = unit

    def update(self, value):
        self.text = self.font.render(self.txt.format(value), True, self.color)