Skip to content

Commit c91f53b

Browse files
authored
Texture related docstring improvements (#2299)
* cache * texture related docstrings * Remove Self * close inline literal * uv_data * atlas docstrings * hitbox
1 parent f113b2e commit c91f53b

24 files changed

+844
-520
lines changed

arcade/cache/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ def crate_str_from_values(*args, sep: str = "_") -> str:
1616
>> crate_str_from_list("blue", 5)
1717
"blue_5"
1818
19-
:param params: List of parameters to create a string from.
20-
:param sep: Separator to use between parameters.
19+
Args:
20+
params: List of parameters to create a string from.
21+
sep: Separator to use between parameters.
2122
"""
2223
return sep.join([str(x) for x in args])
2324

@@ -32,8 +33,9 @@ def crate_str_from_list(entries: list[Any], sep: str = "_") -> str:
3233
>> crate_str_from_list(entries)
3334
"blue_5"
3435
35-
:param entries: List of parameters to create a string from.
36-
:param sep: Separator to use between parameters.
36+
Args:
37+
entries: List of parameters to create a string from.
38+
sep: Separator to use between parameters.
3739
"""
3840
return crate_str_from_values(*entries, sep=sep)
3941

arcade/cache/hit_box.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ def get(self, name_or_texture: str | Texture) -> Point2List | None:
5858
# Get a cache entry by string
5959
points = cache.get("hash|(0, 1, 2, 3)|simple|")
6060
61-
:param keys: List of keys to use for the cache entry
62-
:param hit_box_algorithm: The hit box algorithm used
61+
Args:
62+
keys:
63+
The texture or cache name to get the hit box for
64+
hit_box_algorithm:
65+
The hit box algorithm used
6366
"""
6467
from arcade import Texture
6568

@@ -81,8 +84,11 @@ def put(self, name_or_texture: str | Texture, points: Point2List) -> None:
8184
# Cache with custom string
8285
cache.put("my_custom_points", points)
8386
84-
:param keys: List of keys to use for the cache entry
85-
:param points: The hit box points
87+
Args:
88+
keys:
89+
The texture or cache name to store the hit box for
90+
points:
91+
The hit box points
8692
"""
8793
from arcade import Texture
8894

@@ -105,6 +111,9 @@ def load(self, path: str | Path) -> None:
105111
entries and can therefore be called multiple times to populate it.
106112
107113
if the file extension is ".gz" the file will be compressed.
114+
115+
Args:
116+
path: The path to the json file to load
108117
"""
109118
path = resolve(path)
110119
if path.suffix == ".gz":
@@ -126,8 +135,11 @@ def save(self, path: Path, indent: int = 0) -> None:
126135
127136
if the file extension is ".gz" the file will be compressed.
128137
129-
:param path: The path to save the cache to
130-
:param indent: The indentation level for the json file
138+
Args:
139+
path:
140+
The path to save the cache to
141+
indent:
142+
The indentation level for the json file
131143
"""
132144
if indent == 0:
133145
data_str = json.dumps(self._entries)
@@ -143,9 +155,7 @@ def save(self, path: Path, indent: int = 0) -> None:
143155
fd.write(data)
144156

145157
def flush(self) -> None:
146-
"""
147-
Clear the cache.
148-
"""
158+
"""Clear the cache."""
149159
self._entries.clear()
150160

151161
def __repr__(self) -> str:

arcade/cache/image_data.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def put(self, name: str, image: "ImageData"):
3232
An entry can only be cached as either strong or weak, not both.
3333
If and existing entry is found, it will be replaced.
3434
35-
:param name: Name of the image
36-
:param image: ImageData object
35+
Args:
36+
name: Name of the image
37+
image: ImageData object
3738
"""
3839
from arcade.texture import ImageData
3940

@@ -46,17 +47,22 @@ def get(self, name: str) -> ImageData | None:
4647
"""
4748
Attempts to retrieve an entry from the cache.
4849
49-
:param name: Name of the image
50-
:return: ImageData object or None if not found
50+
Args:
51+
name: Name of the image
52+
Returns:
53+
ImageData instance or ``None`` if not found
5154
"""
5255
return self._entries.get(name)
5356

5457
def delete(self, name: str, raise_if_not_exist: bool = False) -> None:
5558
"""
5659
Attempts to delete an entry from the cache.
5760
58-
:param name: Name of the image
59-
:param raise_if_not_exist: If True, raises KeyError if the entry does not exist
61+
Args:
62+
name:
63+
Name of the image
64+
raise_if_not_exist:
65+
If ``True``, raises ``KeyError`` if the entry does not exist
6066
"""
6167
try:
6268
del self._entries[name]

arcade/cache/texture.py

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,59 @@ def __init__(self):
1919
self._entries: dict[str, Texture] = {}
2020

2121
def put(self, name: str, texture: Texture) -> None:
22+
"""
23+
Add a texture to the cache.
24+
25+
Args:
26+
name:
27+
The cache name of the texture
28+
texture:
29+
The texture to add
30+
"""
2231
self._entries[name] = texture
2332

2433
def get(self, name: str) -> Texture | None:
34+
"""
35+
Get a texture from the cache by cache name.
36+
37+
Args:
38+
name:
39+
The cache name of the texture
40+
Returns:
41+
The texture if found, otherwise ``None``
42+
"""
2543
return self._entries.get(name)
2644

2745
def delete(self, name: str, raise_if_not_exist: bool = True) -> None:
46+
"""
47+
Delete a texture from the cache by cache name.
48+
49+
Args:
50+
name:
51+
The cache name of the texture
52+
raise_if_not_exist:
53+
If ``True``, raises ``KeyError`` if the entry does not exist
54+
"""
2855
try:
2956
del self._entries[name]
3057
except KeyError:
3158
if raise_if_not_exist:
3259
raise
3360

3461
def delete_by_value(self, texture: "Texture") -> None:
62+
"""
63+
Delete a texture from the cache by texture instance.
64+
65+
Args:
66+
texture: The texture instance to delete
67+
"""
3568
for name, value in self._entries.items():
3669
if value is texture:
3770
del self._entries[name]
3871
return
3972

4073
def flush(self) -> None:
74+
"""Clear the cache"""
4175
self._entries.clear()
4276

4377
def __len__(self) -> int:
@@ -72,7 +106,8 @@ def put(self, texture: "Texture") -> None:
72106
and file path are correctly set on the texture before adding it to
73107
the cache.
74108
75-
:param texture: The texture to add
109+
Args:
110+
texture: The texture to add
76111
"""
77112
self._entries.put(texture.cache_name, texture)
78113

@@ -87,18 +122,24 @@ def get(self, name: str) -> Texture | None:
87122
"""
88123
Get a texture from the cache by cache name
89124
90-
:param name: The cache name of the texture
91-
:return: The texture if found, otherwise None
125+
Args:
126+
name: The cache name of the texture
127+
Returns:
128+
The texture if found, otherwise ``None``
92129
"""
93130
return self._entries.get(name)
94131

95132
def get_with_config(self, hash: str, hit_box_algorithm: "HitBoxAlgorithm") -> Texture | None:
96133
"""
97134
Attempts to find a texture with a specific configuration.
98135
99-
:param hash: The image hash
100-
:param hit_box_algorithm: The hit box algorithm to search for
101-
:return: The texture if found, otherwise None
136+
Args:
137+
hash:
138+
The image hash
139+
hit_box_algorithm:
140+
The hit box algorithm to search for
141+
Returns:
142+
The texture if found, otherwise ``None``
102143
"""
103144
from arcade import Texture
104145

@@ -116,7 +157,9 @@ def get_texture_by_filepath(
116157
"""
117158
Get a texture from the cache by file path and crop values.
118159
119-
:param file_path: The path to the file the texture was loaded from
160+
Args:
161+
file_path: The path to the file the texture was loaded from
162+
crop: The crop values used when creating the texture
120163
"""
121164
from arcade import Texture
122165

@@ -127,8 +170,11 @@ def delete(self, texture_or_name: Texture | str, raise_if_not_exist: bool = Fals
127170
"""
128171
Delete a texture from the cache by cache name.
129172
130-
:param texture_or_name: The texture or cache name to delete
131-
:param ignore_error: If True, ignore errors when deleting
173+
Args:
174+
texture_or_name:
175+
The texture or cache name to delete
176+
raise_if_not_exist:
177+
If ``True``, ignore errors when deleting
132178
"""
133179
if isinstance(texture_or_name, Texture):
134180
texture = texture_or_name

arcade/hitbox/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ def calculate_hit_box_points_simple(image: Image, *args) -> Point2List:
2525
Given an RGBA image, this returns points that make up a hit box around it. Attempts
2626
to trim out transparent pixels.
2727
28-
:param image: Image get hit box from.
29-
30-
:Returns: List of points
28+
Args:
29+
image: Image get hit box from.
3130
"""
3231
return algo_simple.calculate(image)
3332

@@ -40,11 +39,12 @@ def calculate_hit_box_points_detailed(
4039
Given an RGBA image, this returns points that make up a hit box around it. Attempts
4140
to trim out transparent pixels.
4241
43-
:param image: Image get hit box from.
44-
:param hit_box_detail: How detailed to make the hit box. There's a
45-
trade-off in number of points vs. accuracy.
46-
47-
:Returns: List of points
42+
Args:
43+
image:
44+
Image get hit box from.
45+
hit_box_detail:
46+
How detailed to make the hit box. There's a
47+
trade-off in number of points vs. accuracy.
4848
"""
4949
return algo_detailed.calculate(image, detail=hit_box_detail)
5050

arcade/hitbox/base.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,25 @@ def calculate(self, image: Image, **kwargs) -> Point2List:
4949
when initialized, subclasses use them to alter how
5050
a specific instance handles image data by default.
5151
52-
:param image: The image to calculate hitbox points for
53-
:param kwargs: keyword arguments
54-
:return: A list of hit box points.
52+
Args:
53+
image:
54+
The image to calculate hitbox points for
55+
kwargs:
56+
keyword arguments
5557
"""
5658
raise NotImplementedError
5759

5860
def __call__(self, *args: Any, **kwds: Any) -> Self:
5961
"""
6062
Shorthand allowing any instance to be used identically to the base type.
6163
62-
:param args: The same positional arguments as `__init__`
63-
:param kwds: The same keyword arguments as `__init__`
64-
:return: A new HitBoxAlgorithm instance
64+
Args:
65+
args:
66+
The same positional arguments as `__init__`
67+
kwds:
68+
The same keyword arguments as `__init__`
69+
Returns:
70+
A new HitBoxAlgorithm instance
6571
"""
6672
return self.__class__(*args, **kwds) # type: ignore
6773

@@ -72,8 +78,8 @@ def create_bounding_box(self, image: Image) -> Point2List:
7278
doesn't manage to figure out any reasonable points for
7379
an image.
7480
75-
:param image: The image to create a bounding box for.
76-
:return: A tuple of hit box points.
81+
Args:
82+
image: The image to create a bounding box for.
7783
"""
7884
size = image.size
7985
return (
@@ -93,10 +99,13 @@ class HitBox:
9399
use :py:meth:`.create_rotatable` to create an instance of
94100
:py:class:`RotatableHitBox`.
95101
96-
:param points: The unmodified points bounding the hit box
97-
:param position: The center around which the points will be offset
98-
:param scale: The X and Y scaling factors to use when offsetting the
99-
points
102+
Args:
103+
points:
104+
The unmodified points bounding the hit box
105+
position:
106+
The center around which the points will be offset
107+
scale:
108+
The X and Y scaling factors to use when offsetting the points
100109
"""
101110

102111
def __init__(
@@ -128,7 +137,6 @@ def points(self) -> Point2List:
128137
def position(self) -> Point2:
129138
"""
130139
The center point used to offset the final adjusted positions.
131-
:return:
132140
"""
133141
return self._position
134142

@@ -199,11 +207,11 @@ def create_rotatable(
199207
Create a rotatable instance of this hit box.
200208
201209
The internal ``PointList`` is transferred directly instead of
202-
deepcopied, so care should be taken if using a mutable internal
210+
deep copied, so care should be taken if using a mutable internal
203211
representation.
204212
205-
:param angle: The angle to rotate points by (0 by default)
206-
:return:
213+
Args:
214+
angle: The angle to rotate points by (0 by default)
207215
"""
208216
return RotatableHitBox(
209217
self._points, position=self._position, scale=self._scale, angle=angle
@@ -241,6 +249,16 @@ class RotatableHitBox(HitBox):
241249
242250
Rotation is separated from the basic hitbox because it is much
243251
slower than offsetting and scaling.
252+
253+
Args:
254+
points:
255+
The unmodified points bounding the hit box
256+
position:
257+
The translation to apply to the points
258+
angle:
259+
The angle to rotate the points by
260+
scale:
261+
The X and Y scaling factors
244262
"""
245263

246264
def __init__(
@@ -272,7 +290,6 @@ def get_adjusted_points(self) -> Point2List:
272290
273291
As with :py:meth:`.HitBox.get_adjusted_points`, this method only
274292
recalculates the adjusted values when necessary.
275-
:return:
276293
"""
277294
if not self._adjusted_cache_dirty:
278295
return self._adjusted_points

0 commit comments

Comments
 (0)