🔥 Fo-cus.

This commit is contained in:
GeoffreyCoulaud
2023-05-03 11:37:32 +02:00
parent 451fde8a91
commit f432c41843
5 changed files with 27 additions and 63 deletions

View File

@@ -1,3 +1,4 @@
from abc import abstractmethod
from collections.abc import Iterable, Iterator
from enum import IntEnum, auto
@@ -19,18 +20,18 @@ class SourceIterator(Iterator):
def __iter__(self):
return self
@abstractmethod
def __next__(self):
raise NotImplementedError()
pass
class Source(Iterable):
"""Source of games. Can be a program location on disk with a config file that points to game for example"""
"""Source of games. E.g an installed app with a config file that lists game directories"""
win = None
win = None # TODO maybe not depend on that ?
name: str
variant: str
executable_format: str
def __init__(self, win) -> None:
super().__init__()
@@ -38,7 +39,7 @@ class Source(Iterable):
@property
def full_name(self):
"""Get the source's full name"""
"""The source's full name"""
s = self.name
if self.variant is not None:
s += " (%s)" % self.variant
@@ -46,13 +47,20 @@ class Source(Iterable):
@property
def game_id_format(self):
"""Get the string format used to construct game IDs"""
"""The string format used to construct game IDs"""
_format = self.name.lower()
if self.variant is not None:
_format += "_" + self.variant.lower()
_format += "_{game_id}_{game_internal_id}"
return _format
@property
@abstractmethod
def executable_format(self):
"""The executable format used to construct game executables"""
pass
@abstractmethod
def __iter__(self):
"""Get the source's iterator, to use in for loops"""
raise NotImplementedError()
pass

View File

@@ -1,9 +1,9 @@
from functools import cached_property
from sqlite3 import connect
from cartridges.game2 import Game
from cartridges.importer.source import Source, SourceIterator
from cartridges.importer.decorators import replaced_by_schema_key, replaced_by_path
from src.game2 import Game
from src.importer.source import Source, SourceIterator
from src.importer.decorators import replaced_by_schema_key, replaced_by_path
class LutrisSourceIterator(SourceIterator):
@@ -56,17 +56,17 @@ class LutrisSourceIterator(SourceIterator):
continue
# Build basic game
game = Game(
name=row[1],
hidden=row[4],
source=self.source.full_name,
game_id=self.source.game_id_format.format(game_id=row[2]),
executable=self.source.executable_format.format(game_id=row[2]),
developer=None, # TODO get developer metadata on Lutris
)
values = {
"name" : row[1],
"hidden" : row[4],
"source" : self.source.full_name,
"game_id" : self.source.game_id_format.format(game_id=row[2]),
"executable": self.source.executable_format.format(game_id=row[2]),
"developer" : None, # TODO get developer metadata on Lutris
}
# TODO Add official image
# TODO Add SGDB image
return game
return values
class LutrisSource(Source):