bacommon.workspace.assetsv1

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.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""Public types for assets-v1 workspaces.
 4
 5These types may only be used server-side, but they are exposed here
 6for reference when setting workspace config data by hand or for use
 7in client-side workspace modification tools. There may be advanced
 8settings that are not accessible through the UI/etc.
 9"""
10
11from __future__ import annotations
12
13from enum import Enum
14from dataclasses import dataclass
15from typing import TYPE_CHECKING, Annotated, override, assert_never
16
17from efro.dataclassio import ioprepped, IOAttrs, IOMultiType
18
19
20if TYPE_CHECKING:
21    pass
22
23
24@ioprepped
25@dataclass
26class AssetsV1GlobalVals:
27    """Global values for an assets_v1 workspace."""
28
29    base_assets: Annotated[
30        str | None, IOAttrs('base_assets', store_default=False)
31    ] = None
32
33
34class AssetsV1PathValsTypeID(Enum):
35    """Types of vals we can store for paths."""
36
37    TEX_V1 = 'tex_v1'
38
39
40class AssetsV1PathVals(IOMultiType[AssetsV1PathValsTypeID]):
41    """Top level class for path vals classes."""
42
43    @override
44    @classmethod
45    def get_type_id_storage_name(cls) -> str:
46        return 'type'
47
48    @override
49    @classmethod
50    def get_type_id(cls) -> AssetsV1PathValsTypeID:
51        # Require child classes to supply this themselves. If we
52        # did a full type registry/lookup here it would require us
53        # to import everything and would prevent lazy loading.
54        raise NotImplementedError()
55
56    @override
57    @classmethod
58    def get_type(
59        cls, type_id: AssetsV1PathValsTypeID
60    ) -> type[AssetsV1PathVals]:
61        # pylint: disable=cyclic-import
62        out: type[AssetsV1PathVals]
63        t = AssetsV1PathValsTypeID
64
65        if type_id is t.TEX_V1:
66            out = AssetsV1PathValsTexV1
67        else:
68            # Important to make sure we provide all types.
69            assert_never(type_id)
70        return out
71
72
73@ioprepped
74@dataclass
75class AssetsV1PathValsTexV1(AssetsV1PathVals):
76    """Path-specific values for an assets_v1 workspace path."""
77
78    class TextureQuality(Enum):
79        """Quality settings for our textures."""
80
81        LOW = 'low'
82        MEDIUM = 'medium'
83        HIGH = 'high'
84
85    # Just dummy testing values for now.
86    texture_quality: Annotated[
87        TextureQuality, IOAttrs('texture_quality', store_default=False)
88    ] = TextureQuality.MEDIUM
89
90    @override
91    @classmethod
92    def get_type_id(cls) -> AssetsV1PathValsTypeID:
93        return AssetsV1PathValsTypeID.TEX_V1
@ioprepped
@dataclass
class AssetsV1GlobalVals:
25@ioprepped
26@dataclass
27class AssetsV1GlobalVals:
28    """Global values for an assets_v1 workspace."""
29
30    base_assets: Annotated[
31        str | None, IOAttrs('base_assets', store_default=False)
32    ] = None

Global values for an assets_v1 workspace.

AssetsV1GlobalVals( base_assets: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>] = None)
base_assets: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x108877920>] = None
class AssetsV1PathValsTypeID(enum.Enum):
35class AssetsV1PathValsTypeID(Enum):
36    """Types of vals we can store for paths."""
37
38    TEX_V1 = 'tex_v1'

Types of vals we can store for paths.

TEX_V1 = <AssetsV1PathValsTypeID.TEX_V1: 'tex_v1'>
Inherited Members
enum.Enum
name
value
class AssetsV1PathVals(efro.dataclassio._base.IOMultiType[bacommon.workspace.assetsv1.AssetsV1PathValsTypeID]):
41class AssetsV1PathVals(IOMultiType[AssetsV1PathValsTypeID]):
42    """Top level class for path vals classes."""
43
44    @override
45    @classmethod
46    def get_type_id_storage_name(cls) -> str:
47        return 'type'
48
49    @override
50    @classmethod
51    def get_type_id(cls) -> AssetsV1PathValsTypeID:
52        # Require child classes to supply this themselves. If we
53        # did a full type registry/lookup here it would require us
54        # to import everything and would prevent lazy loading.
55        raise NotImplementedError()
56
57    @override
58    @classmethod
59    def get_type(
60        cls, type_id: AssetsV1PathValsTypeID
61    ) -> type[AssetsV1PathVals]:
62        # pylint: disable=cyclic-import
63        out: type[AssetsV1PathVals]
64        t = AssetsV1PathValsTypeID
65
66        if type_id is t.TEX_V1:
67            out = AssetsV1PathValsTexV1
68        else:
69            # Important to make sure we provide all types.
70            assert_never(type_id)
71        return out

Top level class for path vals classes.

@override
@classmethod
def get_type_id_storage_name(cls) -> str:
44    @override
45    @classmethod
46    def get_type_id_storage_name(cls) -> str:
47        return 'type'

Return the key used to store type id in serialized data.

The default is an obscure value so that it does not conflict with members of individual type attrs, but in some cases one might prefer to serialize it to something simpler like 'type' by overriding this call. One just needs to make sure that no encompassed types serialize anything to 'type' themself.

@override
@classmethod
def get_type_id(cls) -> AssetsV1PathValsTypeID:
49    @override
50    @classmethod
51    def get_type_id(cls) -> AssetsV1PathValsTypeID:
52        # Require child classes to supply this themselves. If we
53        # did a full type registry/lookup here it would require us
54        # to import everything and would prevent lazy loading.
55        raise NotImplementedError()

Return the type-id for this subclass.

@override
@classmethod
def get_type( cls, type_id: AssetsV1PathValsTypeID) -> type[AssetsV1PathVals]:
57    @override
58    @classmethod
59    def get_type(
60        cls, type_id: AssetsV1PathValsTypeID
61    ) -> type[AssetsV1PathVals]:
62        # pylint: disable=cyclic-import
63        out: type[AssetsV1PathVals]
64        t = AssetsV1PathValsTypeID
65
66        if type_id is t.TEX_V1:
67            out = AssetsV1PathValsTexV1
68        else:
69            # Important to make sure we provide all types.
70            assert_never(type_id)
71        return out

Return a specific subclass given a type-id.

Inherited Members
efro.dataclassio._base.IOMultiType
get_type_id_type
@ioprepped
@dataclass
class AssetsV1PathValsTexV1(efro.dataclassio._base.IOMultiType[bacommon.workspace.assetsv1.AssetsV1PathValsTypeID]):
74@ioprepped
75@dataclass
76class AssetsV1PathValsTexV1(AssetsV1PathVals):
77    """Path-specific values for an assets_v1 workspace path."""
78
79    class TextureQuality(Enum):
80        """Quality settings for our textures."""
81
82        LOW = 'low'
83        MEDIUM = 'medium'
84        HIGH = 'high'
85
86    # Just dummy testing values for now.
87    texture_quality: Annotated[
88        TextureQuality, IOAttrs('texture_quality', store_default=False)
89    ] = TextureQuality.MEDIUM
90
91    @override
92    @classmethod
93    def get_type_id(cls) -> AssetsV1PathValsTypeID:
94        return AssetsV1PathValsTypeID.TEX_V1

Path-specific values for an assets_v1 workspace path.

AssetsV1PathValsTexV1( texture_quality: Annotated[AssetsV1PathValsTexV1.TextureQuality, <efro.dataclassio._base.IOAttrs object>] = <TextureQuality.MEDIUM: 'medium'>)
texture_quality: Annotated[AssetsV1PathValsTexV1.TextureQuality, <efro.dataclassio._base.IOAttrs object at 0x10889b230>] = <TextureQuality.MEDIUM: 'medium'>
@override
@classmethod
def get_type_id(cls) -> AssetsV1PathValsTypeID:
91    @override
92    @classmethod
93    def get_type_id(cls) -> AssetsV1PathValsTypeID:
94        return AssetsV1PathValsTypeID.TEX_V1

Return the type-id for this subclass.

Inherited Members
AssetsV1PathVals
get_type_id_storage_name
get_type
efro.dataclassio._base.IOMultiType
get_type_id_type
class AssetsV1PathValsTexV1.TextureQuality(enum.Enum):
79    class TextureQuality(Enum):
80        """Quality settings for our textures."""
81
82        LOW = 'low'
83        MEDIUM = 'medium'
84        HIGH = 'high'

Quality settings for our textures.

LOW = <TextureQuality.LOW: 'low'>
MEDIUM = <TextureQuality.MEDIUM: 'medium'>
HIGH = <TextureQuality.HIGH: 'high'>
Inherited Members
enum.Enum
name
value