From: Niki Roo Date: Tue, 15 Apr 2025 19:27:01 +0000 (+0200) Subject: new: option mode for DosBox X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=d746096f3a70ca5c2c2190d665750ed0ed630949;p=gamiki.git new: option mode for DosBox --- diff --git a/gamiki/game.py b/gamiki/game.py index 0684e24..cd8b15f 100644 --- a/gamiki/game.py +++ b/gamiki/game.py @@ -12,6 +12,7 @@ class Game(dict): code : str = None src : str = "" tags : list = None + opts : dict = None # option name -> description desc : str = "" total_time : int = 0 total_sessions : int = 0 @@ -40,6 +41,12 @@ class Game(dict): self.tags = [ tag.strip() for tag in self["Tags"].split(";") ] self.src = self.tags[0] self.desc = self.get("Desc", "").replace("\\n", "\n").strip() + + self.opts = { } + if (self.get("Opts")): + for opt in self["Opts"].split(";"): + if (":" in opt): + self.opts[opt.split(":")[0]] = opt.split(":", maxsplit=1)[1] def _init_icons(self): self.icon = self._read_icon() @@ -179,14 +186,14 @@ class Game(dict): except: print("Cannot save total time", file=stderr) - def run(self, params: list = None): + def run(self, opt: str = None): if (not self.support): raise RuntimeError("Unsupported game was called: " + game.name) begin = time() today = datetime.now() - self.support._start(self, params) + self.support._start(self, opt) elapsed = int(time() - begin) if (elapsed >= 60): # Ignore very short sessions diff --git a/gamiki/support/commands.py b/gamiki/support/commands.py index 60c653b..a3eb696 100644 --- a/gamiki/support/commands.py +++ b/gamiki/support/commands.py @@ -5,7 +5,7 @@ from pathlib import PurePath import gamiki.support.custom_commands as custom -def dosbox(dir: PurePath, link: PurePath) -> int: +def dosbox(dir: PurePath, link: PurePath, opt: str = None) -> int: cmd, env = custom.cmd("dosbox", link, None) if (not cmd): @@ -24,7 +24,16 @@ def dosbox(dir: PurePath, link: PurePath) -> int: cmd.append("-conf") cmd.append(cpu.as_posix()) cmd.append("-conf") - cmd.append(dir.joinpath("start.conf").as_posix()) + + if (opt): + start = dir.joinpath(f"start-{opt}.conf") + else: + start = dir.joinpath("start.conf") + + if (not start.exists()): + return 404; + + cmd.append(start.as_posix()) return run(cmd, cwd=dir, env=env).returncode diff --git a/gamiki/support/support.py b/gamiki/support/support.py index 553ea69..a437099 100644 --- a/gamiki/support/support.py +++ b/gamiki/support/support.py @@ -10,12 +10,15 @@ class Support: def supports(self, game: Game) -> bool: return False - def _start(self, game: Game, params: list = None): + def _start(self, game: Game, opt: str = None): if (not self.supports(game)): raise RuntimeError("Unsupported game was called: " + game.name) - def _running(self, game: Game): - print("Running", game.name) + def _running(self, game: Game, opt: str = None): + if (opt): + print("Running", game.name, "(option: " + opt + ")") + else: + print("Running", game.name) def _error(self, game: Game, rc: int): print("\nError when running", game.name + ":", "RC", rc) diff --git a/gamiki/support/support_dos.py b/gamiki/support/support_dos.py index c323b93..7bf6c12 100644 --- a/gamiki/support/support_dos.py +++ b/gamiki/support/support_dos.py @@ -11,9 +11,9 @@ class SupportDos(Support): and not game.dir.joinpath("C", "WINDOWS").exists() ) - def _start(self, game: Game, params: list = None): - self._running(game) - rep = dosbox(game.dir.resolve(), game.dir.resolve()) + def _start(self, game: Game, opt: str = None): + self._running(game, opt) + rep = dosbox(game.dir.resolve(), game.dir.resolve(), opt) if (rep != 0): self._error(game, rep) diff --git a/gamiki/support/support_ext.py b/gamiki/support/support_ext.py index a07900d..c7399c2 100644 --- a/gamiki/support/support_ext.py +++ b/gamiki/support/support_ext.py @@ -8,7 +8,7 @@ class SupportExt(Support): def supports(self, game: Game): return game.dir.joinpath("start.sh").exists() - def _start(self, game: Game, params: list = None): + def _start(self, game: Game, opt: str = None): start = game.dir.resolve().joinpath("start.sh") self._running(game) diff --git a/gamiki/support/support_gog.py b/gamiki/support/support_gog.py index c3f1bbc..1720775 100644 --- a/gamiki/support/support_gog.py +++ b/gamiki/support/support_gog.py @@ -8,7 +8,7 @@ class SupportGog(Support): def supports(self, game: Game): return game.dir.joinpath("gameinfo").exists() - def _start(self, game: Game, params: list = None): + def _start(self, game: Game, opt: str = None): start = game.dir.resolve().joinpath("start.sh") if (not start.exists()): diff --git a/gamiki/support/support_win.py b/gamiki/support/support_win.py index 44b2d17..151ddfb 100644 --- a/gamiki/support/support_win.py +++ b/gamiki/support/support_win.py @@ -8,7 +8,7 @@ class SupportWin(Support): def supports(self, game: Game): return game.dir.joinpath("wine.bat").exists() - def _start(self, game: Game, params: list = None): + def _start(self, game: Game, opt: str = None): dir = game.dir.resolve() if (not dir.joinpath("wine.prefix").exists()): diff --git a/gamiki/support/support_win31.py b/gamiki/support/support_win31.py index c45dd6a..8b6e4ee 100644 --- a/gamiki/support/support_win31.py +++ b/gamiki/support/support_win31.py @@ -11,7 +11,7 @@ class SupportWin31(Support): and game.dir.joinpath("C", "WINDOWS").exists() ) - def _start(self, game: Game, params: list = None): + def _start(self, game: Game, opt: str = None): self._running(game) rep = dosbox(game.dir.resolve(), game.library.dir.resolve()) if (rep != 0):