added command line arguments support

This commit is contained in:
2024-01-28 13:52:45 +01:00
parent 946f4a3b5c
commit 9a032b1ebd
3 changed files with 44 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
from __future__ import annotations
import os
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from config import Config
@@ -14,10 +15,13 @@ class Renderer:
WIDTH = 1200
HEIGHT = 800
def __init__(self, config: Config) -> None:
def __init__(self, config: Config, display: bool = False) -> None:
self.config = config
self.display = display
pygame.init()
self.win = pygame.display.set_mode([Renderer.WIDTH, Renderer.HEIGHT])
if self.display:
self.win = pygame.display.set_mode([Renderer.WIDTH, Renderer.HEIGHT])
self.surf = pygame.Surface([Renderer.WIDTH, Renderer.HEIGHT], pygame.SRCALPHA)
self.font = pygame.font.SysFont(self.config.DEFAULT_FONT_FAMILY, self.config.DEFAULT_FONT_SIZE)
self.italicFont = pygame.font.SysFont(self.config.ITALIC_FONT_FAMILY, self.config.ITALIC_FONT_SIZE, italic=True)
@@ -25,14 +29,16 @@ class Renderer:
self.margins = self.config.MARGINS
def render(self, schema: InstructionSetSchema) -> None:
self.win.fill(self.config.BACKGROUND_COLOR)
self.surf.fill(self.config.BACKGROUND_COLOR)
self.drawStructure(schema.structures["main"], schema.structures, self.margins[3], self.margins[0])
self.win.blit(self.surf, [0, 0])
pygame.display.flip()
if self.display:
name = os.path.basename(schema.path)
pygame.display.set_caption(f"Rivet - {name}")
self.win.fill(self.config.BACKGROUND_COLOR)
self.win.blit(self.surf, [0, 0])
pygame.display.flip()
def save(self, path: str) -> None:
pygame.image.save(self.surf, path)