@@ -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
0 commit comments