Source code for bacommon.docui.routes.classiccharacterpreview

# Released under the MIT License. See LICENSE for details.
#
"""Routes for the classic character-preview doc-ui domain.

A character being tried out in a game (sent there from its builder
page; see the game's character-preview session): the profile editor
for it, as a player who picks the character will see it. Saving
changes nothing stored anywhere; it answers with the character as
edited for the preview session to carry on with.
"""

from __future__ import annotations  # Docs-generation hack.

from dataclasses import dataclass
from typing import Annotated, override

from efro.dataclassio import ioprepped, IOAttrs

import bacommon.docui.v2 as dui2
from bacommon.docui.routes import (
    DocUIRoute,
    DocUILocalActionBase,
    family_members,
)


[docs] class CharacterPreviewRoute(DocUIRoute): """Family class for classic character-preview routes."""
[docs] @override @classmethod def get_route_types(cls) -> tuple[type[DocUIRoute], ...]: return family_members(AnyCharacterPreviewRoute)
[docs] @override @classmethod def get_window_layout(cls) -> dui2.WindowLayout: # The profile editor's layout: controls in the column, the # character beside them. return dui2.WindowLayout.VIEWER
[docs] @ioprepped @dataclass class Edit(CharacterPreviewRoute, path='/'): """The profile editor for a previewed character. The draft being composed rides along as page state (the profile editor's own: :class:`~bacommon.docui.routes.classicstore.ProfileDraft`). """ #: The preview's id, as the game was given it with the character. preview_id: str
[docs] @ioprepped @dataclass class Save(CharacterPreviewRoute, path='/save', method=dui2.RequestMethod.POST): """Save the editor's draft; answered with :class:`Saved`.""" preview_id: str
# All character-preview routes. AnyCharacterPreviewRoute = Edit | Save
[docs] class CharacterPreviewLocalAction(DocUILocalActionBase): """Family class for classic character-preview local-actions."""
[docs] @override @classmethod def get_action_types(cls) -> tuple[type[DocUILocalActionBase], ...]: return family_members(AnyCharacterPreviewLocalAction)
[docs] @ioprepped @dataclass class Saved(CharacterPreviewLocalAction, name='saved'): """The previewed character was edited; here it is as it now stands.""" preview_id: str #: The character, in the form the game was first given it. character: str
# All character-preview local-actions. AnyCharacterPreviewLocalAction = Saved # Docs-generation hack; import some stuff that we likely only forward-declared # in our actual source code so that docs tools can find it. from typing import (Coroutine, Any, Literal, Callable, Generator, Awaitable, Sequence, Self, TypeIs) import asyncio from concurrent.futures import Future from pathlib import Path from enum import Enum