modify styling
This commit is contained in:
@@ -2,3 +2,4 @@ __pycache__
|
||||
.env
|
||||
logos
|
||||
old
|
||||
*.png
|
||||
+11981
File diff suppressed because it is too large
Load Diff
+5
-7
@@ -2,7 +2,7 @@ import requests
|
||||
from PIL import Image
|
||||
from time import time
|
||||
from rgbmatrix import graphics
|
||||
from vars import PANEL_HEIGHT, PANEL_WIDTH, GAME_WIDTH, DIVIDER_COLOR, Colors, font, font_small
|
||||
from vars import PANEL_HEIGHT, PANEL_WIDTH, GAME_WIDTH, DIVIDER_COLOR, Colors, font, font_small, font_super_small
|
||||
|
||||
players = {
|
||||
"team1": [],
|
||||
@@ -31,7 +31,6 @@ def fetch_data():
|
||||
|
||||
new_players = {"team1": [], "team2": []}
|
||||
for player in data["team1"]["players"]:
|
||||
print(player)
|
||||
new_players['team1'].append({
|
||||
"first_name": player['first_name'],
|
||||
"last_name": player['last_name'],
|
||||
@@ -42,7 +41,6 @@ def fetch_data():
|
||||
"injury_body_part": player.get('injury_body_part')
|
||||
})
|
||||
for player in data["team2"]["players"]:
|
||||
print(player)
|
||||
new_players['team2'].append({
|
||||
"first_name": player['first_name'],
|
||||
"last_name": player['last_name'],
|
||||
@@ -72,15 +70,15 @@ def draw_text_overlay(canvas, players, scroll_x):
|
||||
if x + GAME_WIDTH < 0 or x >= PANEL_WIDTH:
|
||||
continue
|
||||
|
||||
graphics.DrawText(canvas, font_small, x + 35, 11,
|
||||
graphics.DrawText(canvas, font, x + 35, 11,
|
||||
rbg(Colors.WHITE.value), player['abbr_name'])
|
||||
graphics.DrawText(canvas, font_small, x + 35, 27,
|
||||
graphics.DrawText(canvas, font_small, x + 72, 11,
|
||||
rbg(Colors.WHITE.value), player['position'])
|
||||
|
||||
if player['injury_status'] and player['injury_body_part']:
|
||||
graphics.DrawText(canvas, font, x + 40, 13,
|
||||
graphics.DrawText(canvas, font_small, x + 35, 20,
|
||||
rbg(Colors.RED.value), str(player['injury_status']))
|
||||
graphics.DrawText(canvas, font, x + 40, 29,
|
||||
graphics.DrawText(canvas, font_super_small, x + 35, 25,
|
||||
rbg(Colors.RED.value), str(player["injury_body_part"]))
|
||||
|
||||
# # if the time is shown it should be split between lines
|
||||
|
||||
+27
-17
@@ -1,12 +1,3 @@
|
||||
"""
|
||||
Dev-only preview tool: renders the fantasy card for two synthetic players
|
||||
(one healthy, one injured) to PNG files, without needing the actual
|
||||
LED matrix hardware or the `rgbmatrix` library.
|
||||
|
||||
Run: python preview_fantasy_card.py
|
||||
Output: preview_healthy.png, preview_injured.png, preview_comparison.png
|
||||
(preview_comparison.png opens automatically)
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import types
|
||||
@@ -16,21 +7,42 @@ REPO_ROOT = Path(__file__).resolve().parent
|
||||
sys.path.insert(0, str(REPO_ROOT))
|
||||
|
||||
# --- stub out rgbmatrix so vars.py / modes/fantasy.py import cleanly on a dev machine ---
|
||||
from PIL import ImageFont
|
||||
|
||||
_FONT_PATH_SIZES = {"4x6.bdf": 6, "5x7.bdf": 7, "7x13.bdf": 12, "9x18.bdf": 16}
|
||||
|
||||
|
||||
def _load_pil_font(px_size):
|
||||
for candidate in (r"C:\Windows\Fonts\consola.ttf", r"C:\Windows\Fonts\cour.ttf"):
|
||||
if os.path.exists(candidate):
|
||||
try:
|
||||
return ImageFont.truetype(candidate, px_size)
|
||||
except Exception:
|
||||
pass
|
||||
return ImageFont.load_default()
|
||||
|
||||
|
||||
class _FakeFont:
|
||||
def __init__(self):
|
||||
self.size = 10
|
||||
self.pil_font = _load_pil_font(self.size)
|
||||
|
||||
def LoadFont(self, path):
|
||||
pass
|
||||
# real BDF files are named e.g. "5x7.bdf" / "7x13.bdf" / "9x18.bdf" -
|
||||
# use that to pick a comparably-sized stand-in TTF for the preview
|
||||
self.size = _FONT_PATH_SIZES.get(os.path.basename(path), 10)
|
||||
self.pil_font = _load_pil_font(self.size)
|
||||
|
||||
|
||||
def _fake_draw_text(canvas, font, x, y, color, text):
|
||||
r, g, b = color
|
||||
canvas.draw.text((x, y - 8), text, fill=(r, g, b))
|
||||
return len(text) * 6
|
||||
|
||||
offset = getattr(font, "size", 10)
|
||||
canvas.draw.text((x, y - offset), text, fill=(r, g, b), font=getattr(font, "pil_font", None))
|
||||
return len(text) * (offset // 2 + 1)
|
||||
|
||||
def _fake_color(r, g, b):
|
||||
return (r, g, b)
|
||||
|
||||
|
||||
_graphics_mod = types.ModuleType("rgbmatrix.graphics")
|
||||
_graphics_mod.Font = _FakeFont
|
||||
_graphics_mod.DrawText = _fake_draw_text
|
||||
@@ -47,7 +59,6 @@ from PIL import Image, ImageDraw
|
||||
import vars
|
||||
from modes import fantasy
|
||||
|
||||
|
||||
class FakeCanvas:
|
||||
def __init__(self, width, height):
|
||||
self.img = Image.new("RGB", (width, height), (0, 0, 0))
|
||||
@@ -60,7 +71,6 @@ class FakeCanvas:
|
||||
if 0 <= x < self.img.width and 0 <= y < self.img.height:
|
||||
self.img.putpixel((x, y), (r, g, b))
|
||||
|
||||
|
||||
class FakeMatrix:
|
||||
def __init__(self):
|
||||
self.canvas = FakeCanvas(vars.PANEL_WIDTH, vars.PANEL_HEIGHT)
|
||||
@@ -134,4 +144,4 @@ if __name__ == "__main__":
|
||||
combined_path = REPO_ROOT / "preview_comparison.png"
|
||||
combined.save(combined_path)
|
||||
print(f"Saved: {combined_path}")
|
||||
combined.show()
|
||||
# combined.show()
|
||||
|
||||
@@ -23,7 +23,9 @@ DIVIDER_COLOR = (40, 40, 40)
|
||||
|
||||
font = graphics.Font()
|
||||
font_small = graphics.Font()
|
||||
font_super_small = graphics.Font()
|
||||
font_big = graphics.Font()
|
||||
font.LoadFont(os.path.join(ASSET_DIR, "fonts/7x13.bdf"))
|
||||
font_small.LoadFont(os.path.join(ASSET_DIR, "fonts/5x7.bdf"))
|
||||
font_super_small.LoadFont(os.path.join(ASSET_DIR, "fonts/4x6.bdf"))
|
||||
font_big.LoadFont(os.path.join(ASSET_DIR, "fonts/9x18.bdf"))
|
||||
Reference in New Issue
Block a user