+from typing import Optional
from pathlib import PurePath
class Game(dict[str, str]):
"""Game object generated from a directory."""
- def __init__(self, library, dir: PurePath):
+ def __init__(self, parent, dir: PurePath):
self.dir = dir
self.name = dir.name
self.code = dir.name
self.tags = []
self.desc = ""
self.support = None
- self.library = library
+ self.parent = parent
self._read_info(self.dir.joinpath("gameinfo.txt"))
-
- if ("Name" in self):
- self.name = self["Name"]
- if ("Code" in self):
- self.code = self["Code"]
- if ("Tags" in self):
+ self._init()
+
+ def _init(self):
+ self.name = self.get("Name", self.dir.name)
+ self.code = self.get("Code", self.dir.name)
+ if (self.get("Tags").strip()):
self.tags = [ tag.strip() for tag in self["Tags"].split(";") ]
- if (self.tags):
- self.src = self.tags[0]
- if ("Desc" in self):
- self.desc = self["Desc"].replace("\\n", "\n").strip()
+ self.src = self.tags[0]
+ self.desc = self.get("Desc").replace("\\n", "\n").strip()
+
+ def get(self, key: str, default: Optional[str] = "") -> Optional[str]:
+ if (key in self):
+ return self[key]
+ return default
def _read_info(self, file: PurePath):
try:
with open(file, encoding="utf-8") as data:
for ln in data:
ln = ln.strip()
- tab = ln.split("=", maxsplit=1)
- if (len(ln) and ln[0] != '#' and len(tab) == 2):
- self[tab[0]] = tab[1]
+ if (ln and ln[0] != "#"):
+ tab = ln.split("=", maxsplit=1)
+ if (len(tab) == 2):
+ key = tab[0].strip()
+ val = tab[1].strip()
+ if (key and val):
+ self[key] = val
except FileNotFoundError:
pass
def set_support(self, support):
self.support = support
- def start(self, params: list[str] = []):
+ def start(self, params: Optional[list[str]] = None):
if (self.support == None):
raise RuntimeError("Unsupported game was called: " + game.name)
+from typing import Optional
from subprocess import run
from shutil import which
def supports(self, game: Game) -> bool:
return False
- def start(self, game: Game, params: list[str] = []):
+ def start(self, game: Game, params: Optional[list[str]] = None):
if (not self.supports(game)):
raise RuntimeError("Unsupported game was called: " + game.name)
+from typing import Optional
+
from gamiki import Game
from gamiki.support import Support
from gamiki.support.commands import dosbox
and not game.dir.joinpath("C", "WINDOWS").exists()
)
- def start(self, game: Game, params: list[str] = []):
+ def start(self, game: Game, params: Optional[list[str]] = None):
self.running(game)
rep = dosbox(game.dir.resolve(), game.dir.resolve())
if (rep != 0):
+from typing import Optional
+
from gamiki import Game
from gamiki.support import Support
from gamiki.support.commands import start_sh
def supports(self, game: Game):
return game.dir.joinpath("start.sh").exists()
- def start(self, game: Game, params: list[str] = []):
+ def start(self, game: Game, params: Optional[list[str]] = None):
start = game.dir.resolve().joinpath("start.sh")
self.running(game)
+from typing import Optional
+
from gamiki import Game
from gamiki.support import Support
from gamiki.support.commands import start_sh
def supports(self, game: Game):
return game.dir.joinpath("gameinfo").exists()
- def start(self, game: Game, params: list[str] = []):
+ def start(self, game: Game, params: Optional[list[str]] = None):
start = game.dir.resolve().joinpath("start.sh")
if (not start.exists()):
+from typing import Optional
+
from gamiki import Game
from gamiki.support import Support
from gamiki.support.commands import wine
def supports(self, game: Game):
return game.dir.joinpath("wine.bat").exists()
- def start(self, game: Game, params: list[str] = []):
+ def start(self, game: Game, params: Optional[list[str]] = None):
dir = game.dir.resolve()
if (not dir.joinpath("wine.prefix").exists()):
+from typing import Optional
+
from gamiki import Game
from gamiki.support import Support
from gamiki.support.commands import dosbox
and game.dir.joinpath("C", "WINDOWS").exists()
)
- def start(self, game: Game, params: list[str] = []):
+ def start(self, game: Game, params: Optional[list[str]] = None):
self.running(game)
rep = dosbox(game.dir.resolve(), game.library.dir.resolve())
if (rep != 0):