import initial

This commit is contained in:
Vincent Bourdon
2026-06-10 10:21:18 +02:00
commit 5a03f8a38d
59 changed files with 4777 additions and 0 deletions
@@ -0,0 +1,44 @@
from dataclasses import dataclass, field
from pathlib import Path
from logimage.domain.entities.puzzle import NonogramPuzzle
from logimage.domain.ports.image_source import ImageSource
from logimage.domain.ports.image_converter import ImageConverter
from logimage.domain.ports.pdf_exporter import PdfExporter
_DIFFICULTY_SIZES: dict[str, tuple[int, int]] = {
"easy": (10, 10),
"medium": (15, 15),
"hard": (20, 20),
}
@dataclass
class GeneratePuzzlesRequest:
count: int = 1
difficulty: str = "medium"
size: tuple[int, int] | None = None
theme: str | None = None
output_path: Path = field(default_factory=lambda: Path("puzzles.pdf"))
with_solution: bool = False
class GeneratePuzzlesUseCase:
def __init__(
self,
image_source: ImageSource,
image_converter: ImageConverter,
pdf_exporter: PdfExporter,
) -> None:
self._image_source = image_source
self._image_converter = image_converter
self._pdf_exporter = pdf_exporter
def execute(self, request: GeneratePuzzlesRequest) -> None:
width, height = request.size or _DIFFICULTY_SIZES.get(request.difficulty, (15, 15))
puzzles: list[NonogramPuzzle] = []
for _ in range(request.count):
image_data = self._image_source.fetch(request.theme)
grid = self._image_converter.to_grid(image_data.content, width, height)
puzzle = NonogramPuzzle.from_grid(grid, image_data.title, image_data.content)
puzzles.append(puzzle)
self._pdf_exporter.export(puzzles, request.output_path, request.with_solution)