🎨 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:
@@ -48,12 +48,9 @@ class ItchSourceIterator(SourceIterator):
|
||||
"game_id": self.source.game_id_format.format(game_id=row[0]),
|
||||
"executable": self.source.executable_format.format(cave_id=row[4]),
|
||||
}
|
||||
yield Game(values, allow_side_effects=False)
|
||||
|
||||
# TODO pass image URIs to the pipeline somehow
|
||||
# - Add a reserved field to the Game object
|
||||
# - Reconstruct those from the pipeline (we already have them)
|
||||
# - Pass game and additional data to the pipeline separately (requires deep changes)
|
||||
additional_data = (row[3], row[2])
|
||||
game = Game(values, allow_side_effects=False)
|
||||
yield (game, additional_data)
|
||||
|
||||
|
||||
class ItchSource(Source):
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user