Source code for bacommon.workspace.assetsv1

# Released under the MIT License. See LICENSE for details.
#
"""Public types for assets-v1 workspaces.

These types may only be used server-side, but they are exposed here
for reference when setting workspace config data by hand or for use
in client-side workspace modification tools. There may be advanced
settings that are not accessible through the UI/etc.
"""

from __future__ import annotations

import datetime
from enum import Enum
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Annotated, override, assert_never

from efro.dataclassio import ioprepped, IOAttrs, IOMultiType
from bacommon.locale import Locale


if TYPE_CHECKING:
    pass


[docs] @ioprepped @dataclass class AssetsV1GlobalVals: """Global values for an assets_v1 workspace.""" base_assets: str | None = None base_assets_filter: str = ''
[docs] class AssetsV1StrInputTypeID(Enum): """Type ID for each of our subclasses.""" BASIC = 'b'
[docs] class AssetsV1StrInput(IOMultiType[AssetsV1StrInputTypeID]): """Top level class for our multitype."""
[docs] @override @classmethod def get_type_id(cls) -> AssetsV1StrInputTypeID: # Require child classes to supply this themselves. If we did a # full type registry/lookup here it would require us to import # everything and would prevent lazy loading. raise NotImplementedError()
[docs] @override @classmethod def get_type( cls, type_id: AssetsV1StrInputTypeID ) -> type[AssetsV1StrInput]: """Return the subclass for each of our type-ids.""" # pylint: disable=cyclic-import t = AssetsV1StrInputTypeID if type_id is t.BASIC: return BasicV1StrInput # Important to make sure we provide all types. assert_never(type_id)
[docs] @ioprepped @dataclass class BasicV1StrInput(AssetsV1StrInput): """Just a test."""
[docs] @override @classmethod def get_type_id(cls) -> AssetsV1StrInputTypeID: return AssetsV1StrInputTypeID.BASIC
[docs] @ioprepped @dataclass class AssetsV1StrData: """Data and output for a string asset."""
[docs] @dataclass class Output: """Represents a single instance of localized output."""
[docs] class Source(Enum): """Where localized output can come from.""" AI_V1 = 'ai_v1'
output_id: int created: datetime.datetime source: Source locale: Locale value_default: str | None = None
inputs: list[AssetsV1StrInput] = field( default_factory=list ) outputs: list[Output] = field(default_factory=list) next_output_id: int = 0
[docs] class AssetsV1PathValsTypeID(Enum): """Types of vals we can store for paths.""" TEX_V1 = 'tex_v1'
# STR_V1 = 'str_v1'
[docs] class AssetsV1PathVals(IOMultiType[AssetsV1PathValsTypeID]): """Top level class for path vals classes."""
[docs] @override @classmethod def get_type_id_storage_name(cls) -> str: return 'type'
[docs] @override @classmethod def get_type_id(cls) -> AssetsV1PathValsTypeID: # Require child classes to supply this themselves. If we # did a full type registry/lookup here it would require us # to import everything and would prevent lazy loading. raise NotImplementedError()
[docs] @override @classmethod def get_type( cls, type_id: AssetsV1PathValsTypeID ) -> type[AssetsV1PathVals]: # pylint: disable=cyclic-import t = AssetsV1PathValsTypeID if type_id is t.TEX_V1: return AssetsV1PathValsTexV1 # Important to make sure we provide all types. assert_never(type_id)
[docs] @ioprepped @dataclass class AssetsV1PathValsTexV1(AssetsV1PathVals): """Path-specific values for an assets_v1 workspace path."""
[docs] class TextureQuality(Enum): """Quality settings for our textures.""" LOW = 'low' MEDIUM = 'medium' HIGH = 'high'
# Just dummy testing values for now. texture_quality: TextureQuality = TextureQuality.MEDIUM
[docs] @override @classmethod def get_type_id(cls) -> AssetsV1PathValsTypeID: return AssetsV1PathValsTypeID.TEX_V1
# 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) import asyncio from concurrent.futures import Future from pathlib import Path from enum import Enum