🎨 SourceIterator can yield addtitional data

SourceIterator-s can yield a game and a tuple of additional data.
This data will be passed to the Store, Pipeline and Managers.
This commit is contained in:
GeoffreyCoulaud
2023-06-07 14:01:06 +02:00
parent 7eef050a64
commit 98f02da36c
12 changed files with 68 additions and 37 deletions

View File

@@ -3,12 +3,15 @@ from abc import abstractmethod
from collections.abc import Iterable, Iterator
from functools import wraps
from pathlib import Path
from typing import Generator, Optional
from typing import Generator, Any
from src import shared
from src.game import Game
from src.utils.decorators import replaced_by_path
# Type of the data returned by iterating on a Source
SourceIterationResult = None | Game | tuple[Game, tuple[Any]]
class SourceIterator(Iterator):
"""Data producer for a source of games"""
@@ -24,11 +27,11 @@ class SourceIterator(Iterator):
def __iter__(self) -> "SourceIterator":
return self
def __next__(self) -> Optional[Game]:
def __next__(self) -> SourceIterationResult:
return next(self.generator)
@abstractmethod
def generator_builder(self) -> Generator[Optional[Game], None, None]:
def generator_builder(self) -> Generator[SourceIterationResult, None, None]:
"""
Method that returns a generator that produces games
* Should be implemented as a generator method
@@ -49,7 +52,6 @@ class Source(Iterable):
def __init__(self) -> None:
super().__init__()
self.available_on = set()
@property
def full_name(self) -> str: