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."""
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
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
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)
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)
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
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."""
def _error(self, game: Game, rc: int):
print("\nError when running", game.name + ":", "RC", rc)
+
+ def _video(self, file: PurePath) -> int:
+ return video(file)