2023-02-19 21:40:25 +01:00
|
|
|
import yaml
|
|
|
|
import jinja2
|
|
|
|
from twisted.web.http import Request
|
2023-03-12 19:03:00 +01:00
|
|
|
from os import path
|
2023-02-19 21:40:25 +01:00
|
|
|
|
|
|
|
from core.frontend import FE_Base
|
|
|
|
from core.config import CoreConfig
|
|
|
|
from titles.wacca.database import WaccaData
|
|
|
|
from titles.wacca.config import WaccaConfig
|
2023-02-21 03:55:12 +01:00
|
|
|
from titles.wacca.const import WaccaConstants
|
2023-02-19 21:40:25 +01:00
|
|
|
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2023-02-19 21:40:25 +01:00
|
|
|
class WaccaFrontend(FE_Base):
|
2023-03-09 17:38:58 +01:00
|
|
|
def __init__(
|
|
|
|
self, cfg: CoreConfig, environment: jinja2.Environment, cfg_dir: str
|
|
|
|
) -> None:
|
2023-02-19 21:40:25 +01:00
|
|
|
super().__init__(cfg, environment)
|
|
|
|
self.data = WaccaData(cfg)
|
|
|
|
self.game_cfg = WaccaConfig()
|
2023-03-12 19:03:00 +01:00
|
|
|
if path.exists(f"{cfg_dir}/{WaccaConstants.CONFIG_NAME}"):
|
|
|
|
self.game_cfg.update(
|
|
|
|
yaml.safe_load(open(f"{cfg_dir}/{WaccaConstants.CONFIG_NAME}"))
|
|
|
|
)
|
2023-02-21 03:55:12 +01:00
|
|
|
self.nav_name = "Wacca"
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2023-02-19 21:40:25 +01:00
|
|
|
def render_GET(self, request: Request) -> bytes:
|
2023-03-09 17:38:58 +01:00
|
|
|
template = self.environment.get_template(
|
|
|
|
"titles/wacca/frontend/wacca_index.jinja"
|
|
|
|
)
|
2023-02-21 03:55:12 +01:00
|
|
|
return template.render(
|
|
|
|
title=f"{self.core_config.server.name} | {self.nav_name}",
|
2023-03-09 17:38:58 +01:00
|
|
|
game_list=self.environment.globals["game_list"],
|
2023-02-21 03:55:12 +01:00
|
|
|
).encode("utf-16")
|