new: intro videos
authorNiki Roo <niki@nikiroo.be>
Fri, 25 Apr 2025 12:24:46 +0000 (14:24 +0200)
committerNiki Roo <niki@nikiroo.be>
Fri, 25 Apr 2025 12:24:46 +0000 (14:24 +0200)
gamiki/game.py
gamiki/support/commands.py
gamiki/support/custom_commands.py
gamiki/support/support.py

index cd8b15f000484b12c2bb31f1abc8b46a79b90fdb..541d7a327b89bf9a3f2f15faf1b286a16eab6eae 100644 (file)
@@ -3,6 +3,7 @@ from typing   import Any
 from pathlib  import PurePath, Path
 from time     import time
 from datetime import datetime
+from random   import choice
 
 class Game(dict):
     """Game object generated from a directory."""
@@ -19,6 +20,7 @@ class Game(dict):
     sessions       : list     = None # list of (YYYY-MM-DD, HH:MM, time in sec)
     icon           : Path     = None # "main" icon
     icons          : dict     = None # all found icons
+    intro          : list     = None # all found intro videos
     support        : Any      = None # should be gamiki.Support
     library        : Any      = None # should be gamiki.Library
     
@@ -48,10 +50,14 @@ class Game(dict):
                 if (":" in opt):
                     self.opts[opt.split(":")[0]] = opt.split(":", maxsplit=1)[1]
     
+        self.intro = []
+        if (self.get("Intr")):
+            self.intro = self["Intr"].split(";")
+    
     def _init_icons(self):
         self.icon = self._read_icon()
         self.icons = { "main": self.icon }
-        for key in [ "square", "icon" ]:
+        for key in [ "square", "icon", "vertical", "banner", "logo" ]:
             icon = self._read_icon("-" + key)
             if (icon): self.icons[key] = icon
     
@@ -193,6 +199,13 @@ class Game(dict):
         begin = time()
         today = datetime.now()
         
+        if (self.intro):
+            intro = choice(self.intro)
+            print("Selected intro video:", intro)
+            rc = self.support._video(self.dir.joinpath(intro))
+            if (rc != 0):
+                print("Video player failed with RC", rc)
+        
         self.support._start(self, opt)
         
         elapsed = int(time() - begin)
index edf0f74816c7437aead5702cef34bc7a6f5833ed..ec0b07d460f2cb5c2a0408f5f827561b36e896c2 100644 (file)
@@ -5,6 +5,19 @@ from pathlib    import PurePath
 
 import gamiki.support.custom_commands as custom
 
+def video(file: PurePath) -> int:
+    cmd, env = custom.video(file)
+    if (not cmd):
+        prog = custom.program("mpv")
+        if (prog):
+            cmd = [ prog, "--fullscreen" ]
+        else:
+            raise RuntimeError("Video player not found")
+    
+    cmd.append(file.as_posix())
+    
+    return run(cmd, env=env).returncode
+
 def dosbox(dir: PurePath, link: PurePath, opt: str = None) -> int:
     
     cmd, env = custom.cmd("dosbox", link, None)    
index c4a9916929005b41e9e2f4b68e2050b9bec2aa23..2af010fd81148c82f30a9a02b789fc424f120fa6 100644 (file)
@@ -13,6 +13,14 @@ def program(program: str) -> str:
 
     return __programs__[program]
 
+def video(file: PurePath) -> (list, dict):
+    cmd = None
+    env = environ.copy()
+    if (program("local.sh")):
+            cmd = [ "local.sh", "mpv", "--fullscreen", file.as_posix() ]
+
+    return cmd, env
+
 def cmd(prog:str, t:PurePath, lnk:PurePath, pre:PurePath=None) -> (list, dict):
     
     cmd = None
index a437099bf1cae5cc8c8a1cc909718f01bb705ebc..20b8a0ee35a171c5a1a3b794f4f3e61f02128b0a 100644 (file)
@@ -1,8 +1,10 @@
 from typing     import Optional
 from subprocess import run
 from shutil     import which
+from pathlib    import PurePath
 
 from gamiki import Game
+from gamiki.support.commands import video
 
 class Support:    
     """Can detect and start games."""
@@ -22,4 +24,7 @@ class Support:
         
     def _error(self, game: Game, rc: int):
         print("\nError when running", game.name + ":", "RC", rc)
+    
+    def _video(self, file: PurePath) -> int:
+        return video(file)