Layer fonctionellent
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
|
||||
|
||||
""" ANSI color codes """
|
||||
@@ -31,8 +32,8 @@ colors = {
|
||||
class Cli():
|
||||
"""Classe gérant l'interface graphique"""
|
||||
def __init__(self, **kwargs):
|
||||
self.width = os.get_terminal_size().columns
|
||||
self.height = os.get_terminal_size().lines -1
|
||||
self.width = shutil.get_terminal_size().columns
|
||||
self.height = shutil.get_terminal_size().lines -1
|
||||
for key, value in kwargs.items():
|
||||
if key == 'width':
|
||||
self.width = value
|
||||
@@ -59,26 +60,26 @@ class Cli():
|
||||
|
||||
def display(self):
|
||||
"""affiche le contenu de self.screen"""
|
||||
os.system('clear')
|
||||
self.__clear()
|
||||
for line in self.screen:
|
||||
print(''.join(line))
|
||||
self.screen = [[' ' for i in range(self.width)] for j in range(self.height)]
|
||||
|
||||
|
||||
def draw(self, content, x, y, **kwargs):
|
||||
"""dessine aux coordonées"""
|
||||
for key, value in kwargs.items():
|
||||
if key == 'color':
|
||||
try:
|
||||
self.screen[y][x-1] = colors[value]
|
||||
self.screen[y][x+len(str(content))] = colors['END']
|
||||
except:
|
||||
pass
|
||||
for i in range(len(str(content))):
|
||||
try:
|
||||
if content[i] != ' ':
|
||||
self.screen[y][x+i] = content[i]
|
||||
except(IndexError):
|
||||
break
|
||||
for key, value in kwargs.items():
|
||||
if key == 'color':
|
||||
try:
|
||||
self.screen[y][x] = colors[value] + self.screen[y][x]
|
||||
self.screen[y][x+len(str(content))-1] += colors['END']
|
||||
except:
|
||||
pass
|
||||
|
||||
def draw_life(self, percent, x, y):
|
||||
"""dessine la barre de vie"""
|
||||
@@ -87,22 +88,30 @@ class Cli():
|
||||
if percent > 25:
|
||||
self.draw('|{}{}|'.format(''.join(['█' for i in range(part_to_draw)]), ''.join([' ' for i in range(length - part_to_draw)])), x, y)
|
||||
else:
|
||||
self.draw('{}|{}{}|{}'.format(colors['RED'], ''.join(['█' for i in range(part_to_draw)]), ''.join([' ' for i in range(length - part_to_draw)]), colors['END']), x, y)
|
||||
self.draw('|{}{}|'.format(''.join(['█' for i in range(part_to_draw)]), ''.join([' ' for i in range(length - part_to_draw)])), x, y, color='RED')
|
||||
|
||||
def wipe(self):
|
||||
"""vide le contenu de self.screen"""
|
||||
self.screen = [[' ' for i in range(self.width)] for j in range(self.height)]
|
||||
|
||||
|
||||
class Layer(Cli):
|
||||
|
||||
class Layer():
|
||||
"""defini une zone indépendante dans l'écran pour ne pas tout recharger"""
|
||||
def __init__(self, x, y, shape):
|
||||
def __init__(self, cli, x, y, shape):
|
||||
"""shape doit être fournis sous forme de tableau"""
|
||||
super().__init__()
|
||||
|
||||
self.cli = cli
|
||||
self.shape = shape
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.width = max(map(len, shape))
|
||||
self.height = len(shape)
|
||||
self.shape_width = max(map(len, self.shape))
|
||||
self.shape_height = len(self.shape)
|
||||
|
||||
def refresh(self):
|
||||
pass
|
||||
|
||||
|
||||
print(platform.system())
|
||||
"""efface seulement le contenu du calque"""
|
||||
for i in range(self.shape_height):
|
||||
for j in range(self.shape_width):
|
||||
try:
|
||||
self.cli.screen[self.y+i][self.x+j] = ' '
|
||||
except:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user