2024-01-09 20:54:34 +00:00
|
|
|
from typing import List
|
|
|
|
from starlette.routing import Route
|
2024-01-09 08:07:04 +00:00
|
|
|
from starlette.requests import Request
|
2024-01-09 20:54:34 +00:00
|
|
|
from starlette.responses import Response
|
2023-03-12 18:03:00 +00:00
|
|
|
from os import path
|
2024-01-09 20:54:34 +00:00
|
|
|
import yaml
|
|
|
|
import jinja2
|
2023-02-19 20:40:25 +00:00
|
|
|
|
2024-01-09 20:54:34 +00:00
|
|
|
from core.frontend import FE_Base, UserSession
|
2023-02-19 20:40:25 +00:00
|
|
|
from core.config import CoreConfig
|
|
|
|
from titles.wacca.database import WaccaData
|
|
|
|
from titles.wacca.config import WaccaConfig
|
2023-02-21 02:55:12 +00:00
|
|
|
from titles.wacca.const import WaccaConstants
|
2023-02-19 20:40:25 +00:00
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2023-02-19 20:40:25 +00:00
|
|
|
class WaccaFrontend(FE_Base):
|
2023-03-09 16:38:58 +00:00
|
|
|
def __init__(
|
|
|
|
self, cfg: CoreConfig, environment: jinja2.Environment, cfg_dir: str
|
|
|
|
) -> None:
|
2023-02-19 20:40:25 +00:00
|
|
|
super().__init__(cfg, environment)
|
|
|
|
self.data = WaccaData(cfg)
|
|
|
|
self.game_cfg = WaccaConfig()
|
2023-03-12 18:03:00 +00: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 02:55:12 +00:00
|
|
|
self.nav_name = "Wacca"
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2024-01-09 20:54:34 +00:00
|
|
|
def get_routes(self) -> List[Route]:
|
|
|
|
return [
|
|
|
|
Route("/", self.render_GET, methods=['GET'])
|
|
|
|
]
|
|
|
|
|
2024-01-09 19:42:17 +00:00
|
|
|
async def render_GET(self, request: Request) -> bytes:
|
2023-03-09 16:38:58 +00:00
|
|
|
template = self.environment.get_template(
|
2024-01-09 20:54:34 +00:00
|
|
|
"titles/wacca/templates/wacca_index.jinja"
|
2023-03-09 16:38:58 +00:00
|
|
|
)
|
2024-01-09 20:54:34 +00:00
|
|
|
usr_sesh = self.validate_session(request)
|
|
|
|
if not usr_sesh:
|
|
|
|
usr_sesh = UserSession()
|
2023-05-20 19:32:02 +00:00
|
|
|
|
2024-01-09 20:54:34 +00:00
|
|
|
return Response(template.render(
|
2023-02-21 02:55:12 +00:00
|
|
|
title=f"{self.core_config.server.name} | {self.nav_name}",
|
2023-03-09 16:38:58 +00:00
|
|
|
game_list=self.environment.globals["game_list"],
|
2023-05-20 19:32:02 +00:00
|
|
|
sesh=vars(usr_sesh)
|
2024-01-12 23:03:44 +00:00
|
|
|
), media_type="text/html; charset=utf-16")
|