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    base_assets_filter: Annotated[
34        str, IOAttrs('base_assets_filter', store_default=False)
35    ] = ''
36
37
38class AssetsV1PathValsTypeID(Enum):
39    """Types of vals we can store for paths."""
40
41    TEX_V1 = 'tex_v1'
42
43
44class AssetsV1PathVals(IOMultiType[AssetsV1PathValsTypeID]):
45    """Top level class for path vals classes."""
46
47    @override
48    @classmethod
49    def get_type_id_storage_name(cls) -> str:
50        return 'type'
51
52    @override
53    @classmethod
54    def get_type_id(cls) -> AssetsV1PathValsTypeID:
55        # Require child classes to supply this themselves. If we
56        # did a full type registry/lookup here it would require us
57        # to import everything and would prevent lazy loading.
58        raise NotImplementedError()
59
60    @override
61    @classmethod
62    def get_type(
63        cls, type_id: AssetsV1PathValsTypeID
64    ) -> type[AssetsV1PathVals]:
65        # pylint: disable=cyclic-import
66        out: type[AssetsV1PathVals]
67        t = AssetsV1PathValsTypeID
68
69        if type_id is t.TEX_V1:
70            out = AssetsV1PathValsTexV1
71        else:
72            # Important to make sure we provide all types.
73            assert_never(type_id)
74        return out
75
76
77@ioprepped
78@dataclass
79class AssetsV1PathValsTexV1(AssetsV1PathVals):
80    """Path-specific values for an assets_v1 workspace path."""
81
82    class TextureQuality(Enum):
83        """Quality settings for our textures."""
84
85        LOW = 'low'
86        MEDIUM = 'medium'
87        HIGH = 'high'
88
89    # Just dummy testing values for now.
90    texture_quality: Annotated[
91        TextureQuality, IOAttrs('texture_quality', store_default=False)
92    ] = TextureQuality.MEDIUM
93
94    @override
95    @classmethod
96    def get_type_id(cls) -> AssetsV1PathValsTypeID:
97        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
33
34    base_assets_filter: Annotated[
35        str, IOAttrs('base_assets_filter', store_default=False)
36    ] = ''

Global values for an assets_v1 workspace.

AssetsV1GlobalVals( base_assets: Annotated[str | None, <efro.dataclassio.IOAttrs object>] = None, base_assets_filter: Annotated[str, <efro.dataclassio.IOAttrs object>] = '')
base_assets: Annotated[str | None, <efro.dataclassio.IOAttrs object at 0x104cda5a0>] = None
base_assets_filter: Annotated[str, <efro.dataclassio.IOAttrs object at 0x107462900>] = ''
class AssetsV1PathValsTypeID(enum.Enum):
39class AssetsV1PathValsTypeID(Enum):
40    """Types of vals we can store for paths."""
41
42    TEX_V1 = 'tex_v1'

Types of vals we can store for paths.

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

Top level class for path vals classes.

@override
@classmethod
def get_type_id_storage_name(cls) -> str:
48    @override
49    @classmethod
50    def get_type_id_storage_name(cls) -> str:
51        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:
53    @override
54    @classmethod
55    def get_type_id(cls) -> AssetsV1PathValsTypeID:
56        # Require child classes to supply this themselves. If we
57        # did a full type registry/lookup here it would require us
58        # to import everything and would prevent lazy loading.
59        raise NotImplementedError()

Return the type-id for this subclass.

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

Return a specific subclass given a type-id.

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

Path-specific values for an assets_v1 workspace path.

AssetsV1PathValsTexV1( texture_quality: Annotated[AssetsV1PathValsTexV1.TextureQuality, <efro.dataclassio.IOAttrs object>] = <TextureQuality.MEDIUM: 'medium'>)
texture_quality: Annotated[AssetsV1PathValsTexV1.TextureQuality, <efro.dataclassio.IOAttrs object at 0x1074b4f80>] = <TextureQuality.MEDIUM: 'medium'>
@override
@classmethod
def get_type_id(cls) -> AssetsV1PathValsTypeID:
95    @override
96    @classmethod
97    def get_type_id(cls) -> AssetsV1PathValsTypeID:
98        return AssetsV1PathValsTypeID.TEX_V1

Return the type-id for this subclass.

class AssetsV1PathValsTexV1.TextureQuality(enum.Enum):
83    class TextureQuality(Enum):
84        """Quality settings for our textures."""
85
86        LOW = 'low'
87        MEDIUM = 'medium'
88        HIGH = 'high'

Quality settings for our textures.

LOW = <TextureQuality.LOW: 'low'>
MEDIUM = <TextureQuality.MEDIUM: 'medium'>
HIGH = <TextureQuality.HIGH: 'high'>