1
0
forked from Hay1tsme/artemis

pokken: add frontend stub

This commit is contained in:
Hay1tsme 2023-04-11 11:40:05 -04:00
parent bf6c7d39f5
commit 68e25b9c5e
4 changed files with 46 additions and 6 deletions

View File

@ -71,8 +71,9 @@ class FrontendServlet(resource.Resource):
game_fe = game_mod.frontend(cfg, self.environment, config_dir) game_fe = game_mod.frontend(cfg, self.environment, config_dir)
self.game_list.append({"url": game_dir, "name": game_fe.nav_name}) self.game_list.append({"url": game_dir, "name": game_fe.nav_name})
fe_game.putChild(game_dir.encode(), game_fe) 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.environment.globals["game_list"] = self.game_list
self.putChild(b"gate", FE_Gate(cfg, self.environment)) self.putChild(b"gate", FE_Gate(cfg, self.environment))

View File

@ -1,8 +1,10 @@
from titles.pokken.index import PokkenServlet from .index import PokkenServlet
from titles.pokken.const import PokkenConstants from .const import PokkenConstants
from titles.pokken.database import PokkenData from .database import PokkenData
from .frontend import PokkenFrontend
index = PokkenServlet index = PokkenServlet
database = PokkenData database = PokkenData
game_codes = [PokkenConstants.GAME_CODE] game_codes = [PokkenConstants.GAME_CODE]
current_schema_version = 1 current_schema_version = 1
frontend = PokkenFrontend

33
titles/pokken/frontend.py Normal file
View File

@ -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")

View File

@ -0,0 +1,4 @@
{% extends "core/frontend/index.jinja" %}
{% block content %}
<h1>Pokken</h1>
{% endblock content %}