@@ -19,25 +19,59 @@ def __init__(self):
19
19
self ._entries : dict [str , Texture ] = {}
20
20
21
21
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
+ """
22
31
self ._entries [name ] = texture
23
32
24
33
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
+ """
25
43
return self ._entries .get (name )
26
44
27
45
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
+ """
28
55
try :
29
56
del self ._entries [name ]
30
57
except KeyError :
31
58
if raise_if_not_exist :
32
59
raise
33
60
34
61
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
+ """
35
68
for name , value in self ._entries .items ():
36
69
if value is texture :
37
70
del self ._entries [name ]
38
71
return
39
72
40
73
def flush (self ) -> None :
74
+ """Clear the cache"""
41
75
self ._entries .clear ()
42
76
43
77
def __len__ (self ) -> int :
@@ -72,7 +106,8 @@ def put(self, texture: "Texture") -> None:
72
106
and file path are correctly set on the texture before adding it to
73
107
the cache.
74
108
75
- :param texture: The texture to add
109
+ Args:
110
+ texture: The texture to add
76
111
"""
77
112
self ._entries .put (texture .cache_name , texture )
78
113
@@ -87,18 +122,24 @@ def get(self, name: str) -> Texture | None:
87
122
"""
88
123
Get a texture from the cache by cache name
89
124
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``
92
129
"""
93
130
return self ._entries .get (name )
94
131
95
132
def get_with_config (self , hash : str , hit_box_algorithm : "HitBoxAlgorithm" ) -> Texture | None :
96
133
"""
97
134
Attempts to find a texture with a specific configuration.
98
135
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``
102
143
"""
103
144
from arcade import Texture
104
145
@@ -116,7 +157,9 @@ def get_texture_by_filepath(
116
157
"""
117
158
Get a texture from the cache by file path and crop values.
118
159
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
120
163
"""
121
164
from arcade import Texture
122
165
@@ -127,8 +170,11 @@ def delete(self, texture_or_name: Texture | str, raise_if_not_exist: bool = Fals
127
170
"""
128
171
Delete a texture from the cache by cache name.
129
172
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
132
178
"""
133
179
if isinstance (texture_or_name , Texture ):
134
180
texture = texture_or_name
0 commit comments