🔥 Fo-cus.
This commit is contained in:
30
src/game2.py
30
src/game2.py
@@ -1,30 +0,0 @@
|
||||
from dataclasses import dataclass, field
|
||||
from time import time
|
||||
|
||||
|
||||
@dataclass
|
||||
class Game():
|
||||
"""Simple game class that contains the necessary fields.
|
||||
Saving, updating and removing is done by game manager classes."""
|
||||
|
||||
# State
|
||||
removed : bool = field(default=False, init=False)
|
||||
blacklisted: bool = field(default=False, init=False)
|
||||
added : int = field(default=-1, init=False)
|
||||
last_played: int = field(default=-1, init=False)
|
||||
|
||||
# Metadata
|
||||
source : str = None
|
||||
name : str = None
|
||||
game_id : str = None
|
||||
developer : str = None
|
||||
|
||||
# Launching
|
||||
executable : str = None
|
||||
|
||||
# Display
|
||||
game_cover : str = None
|
||||
hidden : bool = False
|
||||
|
||||
def __post_init__(self):
|
||||
self.added = int(time())
|
||||
@@ -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
|
||||
@@ -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):
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
class GameManager():
|
||||
"""Interface for systems that save, update and remove games"""
|
||||
|
||||
def add(self, game):
|
||||
"""Add a game to the manager"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def update(self, game):
|
||||
"""Update an existing game in the manager"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def remove(self, game):
|
||||
"""Remove an existing game from the manager"""
|
||||
raise NotImplementedError()
|
||||
Reference in New Issue
Block a user