🔥 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 collections.abc import Iterable, Iterator
|
||||||
from enum import IntEnum, auto
|
from enum import IntEnum, auto
|
||||||
|
|
||||||
@@ -19,18 +20,18 @@ class SourceIterator(Iterator):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
raise NotImplementedError()
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Source(Iterable):
|
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
|
name: str
|
||||||
variant: str
|
variant: str
|
||||||
executable_format: str
|
|
||||||
|
|
||||||
def __init__(self, win) -> None:
|
def __init__(self, win) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -38,7 +39,7 @@ class Source(Iterable):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def full_name(self):
|
def full_name(self):
|
||||||
"""Get the source's full name"""
|
"""The source's full name"""
|
||||||
s = self.name
|
s = self.name
|
||||||
if self.variant is not None:
|
if self.variant is not None:
|
||||||
s += " (%s)" % self.variant
|
s += " (%s)" % self.variant
|
||||||
@@ -46,13 +47,20 @@ class Source(Iterable):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def game_id_format(self):
|
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()
|
_format = self.name.lower()
|
||||||
if self.variant is not None:
|
if self.variant is not None:
|
||||||
_format += "_" + self.variant.lower()
|
_format += "_" + self.variant.lower()
|
||||||
_format += "_{game_id}_{game_internal_id}"
|
_format += "_{game_id}_{game_internal_id}"
|
||||||
return _format
|
return _format
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def executable_format(self):
|
||||||
|
"""The executable format used to construct game executables"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""Get the source's iterator, to use in for loops"""
|
"""Get the source's iterator, to use in for loops"""
|
||||||
raise NotImplementedError()
|
pass
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from sqlite3 import connect
|
from sqlite3 import connect
|
||||||
|
|
||||||
from cartridges.game2 import Game
|
from src.game2 import Game
|
||||||
from cartridges.importer.source import Source, SourceIterator
|
from src.importer.source import Source, SourceIterator
|
||||||
from cartridges.importer.decorators import replaced_by_schema_key, replaced_by_path
|
from src.importer.decorators import replaced_by_schema_key, replaced_by_path
|
||||||
|
|
||||||
|
|
||||||
class LutrisSourceIterator(SourceIterator):
|
class LutrisSourceIterator(SourceIterator):
|
||||||
@@ -56,17 +56,17 @@ class LutrisSourceIterator(SourceIterator):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Build basic game
|
# Build basic game
|
||||||
game = Game(
|
values = {
|
||||||
name=row[1],
|
"name" : row[1],
|
||||||
hidden=row[4],
|
"hidden" : row[4],
|
||||||
source=self.source.full_name,
|
"source" : self.source.full_name,
|
||||||
game_id=self.source.game_id_format.format(game_id=row[2]),
|
"game_id" : self.source.game_id_format.format(game_id=row[2]),
|
||||||
executable=self.source.executable_format.format(game_id=row[2]),
|
"executable": self.source.executable_format.format(game_id=row[2]),
|
||||||
developer=None, # TODO get developer metadata on Lutris
|
"developer" : None, # TODO get developer metadata on Lutris
|
||||||
)
|
}
|
||||||
# TODO Add official image
|
# TODO Add official image
|
||||||
# TODO Add SGDB image
|
# TODO Add SGDB image
|
||||||
return game
|
return values
|
||||||
|
|
||||||
class LutrisSource(Source):
|
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