mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-22 15:53:01 +00:00
config rework & bigger images
This commit is contained in:
parent
c35fe495dc
commit
5e0f797a2f
6 changed files with 44 additions and 39 deletions
|
@ -39,7 +39,7 @@ class AdventImage:
|
|||
# skalieren
|
||||
return cls(
|
||||
img.resize(
|
||||
size=(500, 500),
|
||||
size=(1000, 1000),
|
||||
resample=Image.LANCZOS,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -36,7 +36,7 @@ class CalendarConfig(BaseModel):
|
|||
"""
|
||||
|
||||
await WebDAV.write_str(
|
||||
path=f"files/{cfg.puzzle.calendar}",
|
||||
path=f"files/{cfg.calendar}",
|
||||
content=tomli_w.dumps(self.model_dump()),
|
||||
)
|
||||
|
||||
|
@ -48,5 +48,5 @@ async def get_calendar_config(
|
|||
Kalender Konfiguration lesen
|
||||
"""
|
||||
|
||||
txt = await WebDAV.read_str(path=f"files/{cfg.puzzle.calendar}")
|
||||
txt = await WebDAV.read_str(path=f"files/{cfg.calendar}")
|
||||
return CalendarConfig.model_validate(tomllib.loads(txt))
|
||||
|
|
|
@ -11,9 +11,13 @@ class User(BaseModel):
|
|||
password: str
|
||||
|
||||
|
||||
class Server(BaseModel):
|
||||
# Dateiname Schriftart
|
||||
font: str
|
||||
class Puzzle(BaseModel):
|
||||
# Titel
|
||||
# TODO
|
||||
title: str
|
||||
|
||||
# Lösungswort
|
||||
solution: str
|
||||
|
||||
# Tag, an dem der Kalender startet
|
||||
# TODO penner
|
||||
|
@ -28,12 +32,32 @@ class Server(BaseModel):
|
|||
close_after: int = 90
|
||||
|
||||
|
||||
class Puzzle(BaseModel):
|
||||
# Titel
|
||||
title: str
|
||||
class TTFont(BaseModel):
|
||||
# Dateiname (in "/files")
|
||||
file: str
|
||||
|
||||
# Lösungswort
|
||||
solution: str
|
||||
# Schriftgröße für den Font
|
||||
size: int = 50
|
||||
|
||||
|
||||
class Image(BaseModel):
|
||||
# Quadrat, Seitenlänge in px
|
||||
# TODO penner
|
||||
size: int = 1000
|
||||
|
||||
# Rand in px, wo keine Buchstaben untergebracht werden
|
||||
# TODO penner
|
||||
border: int = 60
|
||||
|
||||
# Schriftarten
|
||||
# TODO
|
||||
fonts: list[TTFont]
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
admin: User
|
||||
puzzle: Puzzle
|
||||
image: Image
|
||||
|
||||
# Kalenderdefinition
|
||||
calendar: str = "default.toml"
|
||||
|
@ -42,12 +66,6 @@ class Puzzle(BaseModel):
|
|||
random_seed: str = ""
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
admin: User
|
||||
server: Server
|
||||
puzzle: Puzzle
|
||||
|
||||
|
||||
async def get_config() -> Config:
|
||||
"""
|
||||
Globale Konfiguration lesen
|
||||
|
|
|
@ -113,14 +113,14 @@ async def gen_day_auto_image(
|
|||
rnd = await Random.get(day)
|
||||
|
||||
font = ImageFont.truetype(
|
||||
font=BytesIO(await WebDAV.read_bytes(f"files/{cfg.server.font}")),
|
||||
size=50,
|
||||
font=BytesIO(await WebDAV.read_bytes("files/Lena.ttf")), # TODO
|
||||
size=100,
|
||||
)
|
||||
|
||||
# Buchstaben verstecken
|
||||
for letter in day_parts[day]:
|
||||
await image.hide_text(
|
||||
xy=cast(_XY, tuple(rnd.choices(range(30, 470), k=2))),
|
||||
xy=cast(_XY, tuple(rnd.choices(range(60, 940), k=2))),
|
||||
text=letter,
|
||||
font=font,
|
||||
)
|
||||
|
|
|
@ -18,7 +18,7 @@ class Random(random.Random):
|
|||
@classmethod
|
||||
async def get(cls, bonus_salt: Any = "") -> Self:
|
||||
cfg = await get_config()
|
||||
return cls(f"{cfg.puzzle.solution}{cfg.puzzle.random_seed}{bonus_salt}")
|
||||
return cls(f"{cfg.puzzle.solution}{cfg.random_seed}{bonus_salt}")
|
||||
|
||||
def shuffled(self, population: Sequence[T]) -> Sequence[T]:
|
||||
return self.sample(population, k=len(population))
|
||||
|
|
|
@ -6,7 +6,7 @@ from pydantic import BaseModel
|
|||
from advent22_api.core.helpers import EventDates
|
||||
|
||||
from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config
|
||||
from ..core.config import Config, get_config
|
||||
from ..core.config import Config, Image, get_config
|
||||
from ..core.depends import get_all_event_dates, get_all_image_names, get_all_parts
|
||||
from ..core.settings import SETTINGS
|
||||
from ._security import require_admin, user_is_admin
|
||||
|
@ -34,15 +34,6 @@ class ConfigModel(BaseModel):
|
|||
config_file: str
|
||||
background: str
|
||||
|
||||
class __Image(BaseModel):
|
||||
class __Font(BaseModel):
|
||||
file: str
|
||||
size: int
|
||||
|
||||
size: int
|
||||
border: int
|
||||
fonts: list[__Font]
|
||||
|
||||
class __WebDAV(BaseModel):
|
||||
url: str
|
||||
cache_ttl: int
|
||||
|
@ -50,7 +41,7 @@ class ConfigModel(BaseModel):
|
|||
|
||||
puzzle: __Puzzle
|
||||
calendar: __Calendar
|
||||
image: __Image
|
||||
image: Image
|
||||
webdav: __WebDAV
|
||||
|
||||
|
||||
|
@ -73,17 +64,13 @@ async def get_config_model(
|
|||
"next": event_dates.next,
|
||||
"last": event_dates.last,
|
||||
"end": event_dates.end,
|
||||
"seed": cfg.puzzle.random_seed,
|
||||
"seed": cfg.random_seed,
|
||||
},
|
||||
"calendar": {
|
||||
"config_file": cfg.puzzle.calendar,
|
||||
"config_file": cfg.calendar,
|
||||
"background": cal_cfg.background,
|
||||
},
|
||||
"image": {
|
||||
"size": 500, # TODO
|
||||
"border": 30, # TODO
|
||||
"fonts": [{"file": cfg.server.font, "size": 50}], # TODO
|
||||
},
|
||||
"image": cfg.image,
|
||||
"webdav": {
|
||||
"url": SETTINGS.webdav.url,
|
||||
"cache_ttl": SETTINGS.webdav.cache_ttl,
|
||||
|
|
Loading…
Reference in a new issue