From 68e25b9c5eebcefb87f70c8ee6cbcec67596584a Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Tue, 11 Apr 2023 11:40:05 -0400 Subject: [PATCH] pokken: add frontend stub --- core/frontend.py | 7 ++--- titles/pokken/__init__.py | 8 +++--- titles/pokken/frontend.py | 33 +++++++++++++++++++++++ titles/pokken/frontend/pokken_index.jinja | 4 +++ 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 titles/pokken/frontend.py create mode 100644 titles/pokken/frontend/pokken_index.jinja diff --git a/core/frontend.py b/core/frontend.py index 127b174..0c96fdc 100644 --- a/core/frontend.py +++ b/core/frontend.py @@ -66,13 +66,14 @@ class FrontendServlet(resource.Resource): fe_game = FE_Game(cfg, self.environment) games = Utils.get_all_titles() for game_dir, game_mod in games.items(): - if hasattr(game_mod, "frontend"): + if hasattr(game_mod, "frontend"): try: game_fe = game_mod.frontend(cfg, self.environment, config_dir) self.game_list.append({"url": game_dir, "name": game_fe.nav_name}) fe_game.putChild(game_dir.encode(), game_fe) - except: - raise + + except Exception as e: + self.logger.error(f"Failed to import frontend from {game_dir} because {e}") self.environment.globals["game_list"] = self.game_list self.putChild(b"gate", FE_Gate(cfg, self.environment)) diff --git a/titles/pokken/__init__.py b/titles/pokken/__init__.py index ed2ee23..94237c4 100644 --- a/titles/pokken/__init__.py +++ b/titles/pokken/__init__.py @@ -1,8 +1,10 @@ -from titles.pokken.index import PokkenServlet -from titles.pokken.const import PokkenConstants -from titles.pokken.database import PokkenData +from .index import PokkenServlet +from .const import PokkenConstants +from .database import PokkenData +from .frontend import PokkenFrontend index = PokkenServlet database = PokkenData game_codes = [PokkenConstants.GAME_CODE] current_schema_version = 1 +frontend = PokkenFrontend diff --git a/titles/pokken/frontend.py b/titles/pokken/frontend.py new file mode 100644 index 0000000..e4e8947 --- /dev/null +++ b/titles/pokken/frontend.py @@ -0,0 +1,33 @@ +import yaml +import jinja2 +from twisted.web.http import Request +from os import path + +from core.frontend import FE_Base +from core.config import CoreConfig +from .database import PokkenData +from .config import PokkenConfig +from .const import PokkenConstants + + +class PokkenFrontend(FE_Base): + def __init__( + self, cfg: CoreConfig, environment: jinja2.Environment, cfg_dir: str + ) -> None: + super().__init__(cfg, environment) + self.data = PokkenData(cfg) + self.game_cfg = PokkenConfig() + if path.exists(f"{cfg_dir}/{PokkenConstants.CONFIG_NAME}"): + self.game_cfg.update( + yaml.safe_load(open(f"{cfg_dir}/{PokkenConstants.CONFIG_NAME}")) + ) + self.nav_name = "Pokken" + + def render_GET(self, request: Request) -> bytes: + template = self.environment.get_template( + "titles/pokken/frontend/pokken_index.jinja" + ) + return template.render( + title=f"{self.core_config.server.name} | {self.nav_name}", + game_list=self.environment.globals["game_list"], + ).encode("utf-16") diff --git a/titles/pokken/frontend/pokken_index.jinja b/titles/pokken/frontend/pokken_index.jinja new file mode 100644 index 0000000..446893a --- /dev/null +++ b/titles/pokken/frontend/pokken_index.jinja @@ -0,0 +1,4 @@ +{% extends "core/frontend/index.jinja" %} +{% block content %} +

Pokken

+{% endblock content %} \ No newline at end of file