new: option mode for DosBox
authorNiki Roo <niki@nikiroo.be>
Tue, 15 Apr 2025 19:27:01 +0000 (21:27 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 15 Apr 2025 19:27:01 +0000 (21:27 +0200)
gamiki/game.py
gamiki/support/commands.py
gamiki/support/support.py
gamiki/support/support_dos.py
gamiki/support/support_ext.py
gamiki/support/support_gog.py
gamiki/support/support_win.py
gamiki/support/support_win31.py

index 0684e247c2a7d7a14b31e5e4091be7dcc84db3a5..cd8b15f000484b12c2bb31f1abc8b46a79b90fdb 100644 (file)
@@ -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
index 60c653b2ac5e3bd0a4628db733d88c9282ca3825..a3eb6960e00dd103f1efd7eab9405ce96ccad157 100644 (file)
@@ -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
 
index 553ea69dc8fe73c5fd8f3be1e052b9680546483d..a437099bf1cae5cc8c8a1cc909718f01bb705ebc 100644 (file)
@@ -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)
index c323b93b2065b8f00bc50aa6168f3087a0cf6d86..7bf6c1241fd008bfd1478973d24a76b9b96af316 100644 (file)
@@ -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)
 
index a07900d6839a1c6b7f6c788e87111faf06d2164d..c7399c2750ff967c4cdcacf3aa4086adb30b312f 100644 (file)
@@ -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)
index c3f1bbce5439bba7360a58c8334ff439c65d4216..172077551b0a1d1c6e0992daa1becbeda4525b70 100644 (file)
@@ -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()):
index 44b2d179d0c39519c48178578a0095caa2f939a6..151ddfb5137e92045196ca20f057ed5f6edeb4b0 100644 (file)
@@ -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()):
index c45dd6a04cf2110b042534437be0be82a03786bd..8b6e4ee6620869002f513fe68c2f91922bfce853 100644 (file)
@@ -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):