-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbean.py
More file actions
123 lines (95 loc) · 4.53 KB
/
bean.py
File metadata and controls
123 lines (95 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""
MIT License
Copyright (c) 2019-present Luc1412
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from __future__ import annotations
from collections.abc import Coroutine
from typing import TYPE_CHECKING, Any, overload
from ...enums import CustomGender, GameLanguage, try_enum
from ...http import HTTPClientT
from ...utils import get_with_fallback
from ..br import CosmeticBr
from ..common import Cosmetic, CosmeticImages
if TYPE_CHECKING:
from ...http import HTTPClient, SyncHTTPClient
__all__: tuple[str, ...] = ('VariantBean',)
class VariantBean(Cosmetic[dict[str, Any], HTTPClientT]):
"""
.. attributetable:: fortnite_api.VariantBean
This class represents the Bean variant of a cosmetic item. This stems from
the Fortnite x Fall Guys collaboration, where Fortnite cosmetics were
transformed into Fall Guys beans.
This class inherits from :class:`fortnite_api.Cosmetic`.
Attributes
----------
cosmetic_id: Optional[:class:`str`]
The ID of the cosmetic that this bean represents, if any.
name: :class:`str`
The name of this bean.
gender: Optional[:class:`fortnite_api.CustomGender`]
Denotes the gender of this bean. Can be ``None`` if no gender is assigned.
gameplay_tags: List[:class:`str`]
The gameplay tags associated with this bean.
.. opt-in:: INCLUDE_GAMEPLAY_TAGS
images: Optional[:class:`fortnite_api.CosmeticImages`]
Any display images of this bean in the game. Will be ``None``
if there are no images.
path: Optional[:class:`str`]
The game path of this bean. Will be ``None`` if there is no path
in the API response.
.. opt-in:: INCLUDE_PATHS
"""
def __init__(self, *, data: dict[str, Any], http: HTTPClientT) -> None:
super().__init__(data=data, http=http)
self.cosmetic_id: str | None = data.get('cosmetic_id')
self.name: str = data['name']
_gender = data.get("gender")
self.gender: CustomGender | None = _gender and try_enum(CustomGender, _gender)
self.gameplay_tags: list[str] = get_with_fallback(data, 'gameplay_tags', list)
_images = data.get('images')
self.images: CosmeticImages[HTTPClientT] | None = _images and CosmeticImages(data=_images, http=http)
self.path: str | None = data.get('path')
@overload
def fetch_cosmetic_br(
self: VariantBean[HTTPClient], *, language: GameLanguage | None = None
) -> Coroutine[Any, Any, CosmeticBr]: ...
@overload
def fetch_cosmetic_br(self: VariantBean[SyncHTTPClient], *, language: GameLanguage | None = None) -> CosmeticBr: ...
def fetch_cosmetic_br(
self, *, language: GameLanguage | None = None
) -> Coroutine[Any, Any, CosmeticBr] | CosmeticBr:
"""|coro|
Fetches the Battle Royale cosmetic that this bean variant is based on.
Parameters
----------
language: Optional[:class:`fortnite_api.GameLanguage`]
The language to fetch the cosmetic in.
Returns
-------
:class:`fortnite_api.CosmeticBr`
The Battle Royale cosmetic that this bean variant is based on.
Raises
------
ValueError
The bean variant does not have a corresponding Battle Royale cosmetic.
I.e. :attr`cosmetic_id` is ``None``.
"""
cosmetic_id = self.cosmetic_id
if cosmetic_id is None:
raise ValueError('This bean variant does not have a corresponding Battle Royale cosmetic.')
return self._http.get_cosmetic_br(cosmetic_id, language=language and language.value)