wmwpy.utils package¶
Subpackages¶
Submodules¶
wmwpy.utils.XMLTools module¶
wmwpy.utils.color module¶
- wmwpy.utils.color.hls_to_rgb(hls_array: ndarray) ndarray [source]¶
Expects an array of shape (X, 3), each row being HLS colours. Returns an array of same size, each row being RGB colours. Like
colorsys
python module, all values are between 0 and 1. NOTE: likecolorsys
, this uses HLS rather than the more usual HSL
- wmwpy.utils.color.hsv_to_rgb(hsv_array: ndarray) ndarray [source]¶
Expects an array of shape (X, 3), each row being HSV colours. Returns an array of same size, each row being RGB colours. Like
colorsys
python module, all values are between 0 and 1.
- wmwpy.utils.color.rgb_to_hls(rgb_array: ndarray) ndarray [source]¶
Expects an array of shape (X, 3), each row being RGB colours. Returns an array of same size, each row being HLS colours. Like
colorsys
python module, all values are between 0 and 1. NOTE: likecolorsys
, this uses HLS rather than the more usual HSL
wmwpy.utils.filesystem module¶
- class wmwpy.utils.filesystem.File(parent, path: str, data: bytes | str | BytesIO)[source]¶
Bases:
FileBase
- add(path: str, file: bytes, replace=False)[source]¶
Add file to folder.
- Parameters:
path (str) – New file path.
content (bytes) – Content of file in bytes.
replace (bool, optional) – Whether to replace any conflicting file.. Defaults to False.
- Raises:
NotADirectoryError – Path to file contains file, not folder.
FileExistsError – File already exists.
- Returns:
Newly added File.
- Return type:
- exists(path: str)[source]¶
Tests whether path exists.
- Parameters:
path (str) – Path to check.
- Returns:
Does path exist?
- Return type:
bool
- property extension: str¶
The file extension
- Returns:
File extension
- Return type:
str
- listdir(recursive=False, search='*')[source]¶
Returns a list of files and subfolders in path.
- Parameters:
path (str, optional) – Path to folder to list. Defaults to ‘/’.
recursive (bool, optional) – Whether to include subfolders. Defaults to False.
- Returns:
List of files and subfolders.
- Return type:
list
- property rawdata: BytesIO¶
Returns the raw data of the file as a
BytesIO
object.- Returns:
Raw data of file.
- Return type:
io.BytesIO
- class wmwpy.utils.filesystem.FileBase(parent, path: str)[source]¶
Bases:
object
- property filesystem: Filesystem¶
Returns the Filesystem or root Folder for this File or Folder.
- Returns:
Root Filesystem or Folder
- Return type:
- name = ''¶
- property path: str¶
Path to this file or folder from the root.
- Returns:
Path this file or folder.
- Return type:
str
- class wmwpy.utils.filesystem.Filesystem(gamepath: str, assets: str, baseassets: str = '/')[source]¶
Bases:
object
- add(path: str, file: str | bytes, replace=False)[source]¶
Adds file with path to Folder.
- Parameters:
path (str) – Path to destenation of file. Must be str.
file (str | bytes) – File. This can be a path to the file to use, raw
bytes
of the file, or file-like object.replace (bool, optional) – Replace any conflicting files? Defaults to False.
- Raises:
TypeError – If file is not
str
,bytes
or file-like object.- Returns:
File object of the added file.
- Return type:
- dump(folder: str | None = None, callback: Callable[[int, str, int], Any] | None = None)[source]¶
Dump the contents of the filesystem to the specified directory
- Parameters:
folder (str, optional) – Path to output directory. Defaults to original path.
callback (Callable[[int, str, int], Any], optional) – A callback function to be ran while dumping the filesystem. Defaults to None.
- exists(fp: str) bool [source]¶
Test if file path exists.
- Parameters:
fp (str) – File path.
- Returns:
Whether the path exists.
- Return type:
bool
- getAssets(extract_zip=False, split_imagelist=False, load_callback: Callable[[int, str, int], Any] | None = None)[source]¶
Scans the assets directory and loads all files into the filesystem. This is so wmwpy can modify files without modifying the actual files.
- Parameters:
extract_zip (bool, optional) – Extrack zip files? Defaults to False.
split_imagelist (bool, optional) – Split imagelist files? Defaults to False.
hook (Callable[[int, str, int], Any], optional) – Hook for loading assets, useful for guis. The function gets called with the paramaters
(progress : int, current : str, max : int)
. Defaults to None.
- Raises:
FileNotFoundError – Assets folder does not exist.
- Returns:
Current Filesystem object.
- Return type:
this
- listdir(path='/', recursive=False, search='*') list [source]¶
Returns a list of files and subfolders in path.
- Parameters:
path (str, optional) – Path to folder to list. Defaults to ‘/’.
recursive (bool, optional) – Whether to include subfolders. Defaults to False.
- Returns:
List of files and subfolders.
- Return type:
list
- class wmwpy.utils.filesystem.Folder(parent=None, path: str | None = None)[source]¶
Bases:
FileBase
- add(path: str, content: bytes, replace=False) File [source]¶
Add file to folder.
- Parameters:
path (str) – New file path.
content (bytes) – Content of file in bytes.
replace (bool, optional) – Whether to replace any conflicting file.. Defaults to False.
- Raises:
NotADirectoryError – Path to file contains file, not folder.
FileExistsError – File already exists.
- Returns:
Newly added File.
- Return type:
- exists(path: str) bool [source]¶
Tests whether path exists.
- Parameters:
path (str) – Path to check.
- Returns:
Does path exist?
- Return type:
bool
- listdir(recursive=False, search='*')[source]¶
Returns a list of files and subfolders in path.
- Parameters:
path (str, optional) – Path to folder to list. Defaults to ‘/’.
recursive (bool, optional) – Whether to include subfolders. Defaults to False.
- Returns:
List of files and subfolders.
- Return type:
list
wmwpy.utils.gif module¶
- class wmwpy.utils.gif.TransparentAnimatedGifConverter(img_rgba: Image, alpha_threshold: int = 0)[source]¶
Bases:
object
- wmwpy.utils.gif.save_transparent_gif(images: List[Image], durations: int | List[int], save_file) Image [source]¶
Creates a transparent GIF, adjusting to avoid transparency issues that are present in the PIL library
Note that this does NOT work for partial alpha. The partial alpha gets discarded and replaced by solid colors.
- Parameters:
images – a list of PIL Image objects that compose the GIF frames
durations – an int or List[int] that describes the animation durations for the frames of this GIF
save_file – A filename (string), pathlib.Path object or file object. (This parameter corresponds
and is passed to the PIL.Image.save() method.)
- Returns:
Image - The PIL Image object (after first saving the image to the specified target)
wmwpy.utils.imageprocessing module¶
- wmwpy.utils.imageprocessing.recolor_image(image: Image, colorRGBA: tuple[int, int, int, int]) Image [source]¶
Replace color in image
- Parameters:
image (PIL.Image.Image) – Input image
color (tuple[int,int,int,int]) – The color to recolor the image with
- Returns:
resulting image
- Return type:
PIL.Image.Image
wmwpy.utils.logging_utils module¶
wmwpy.utils.path module¶
wmwpy.utils.rotate module¶
wmwpy.utils.textures module¶
- class wmwpy.utils.textures.HDFile(file: str | File, HD: bool = True, TabHD: bool = False, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/')[source]¶
Bases:
GameObject
- property filename: str¶
- wmwpy.utils.textures.getHDFile(file: str, HD=True, TabHD=False, filesystem: Filesystem | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/') str [source]¶
Get HD filename.
- Parameters:
file (str) – Filename. Must be a string.
HD (bool, optional) –
- Returns:
HD filename.
- Return type:
str
- wmwpy.utils.textures.getTexture(path: str, textureSettings: dict, size: tuple, cache=True) Image [source]¶
Get image.
- Parameters:
path (str) – Path to Image.
textureSettings (dict) – Texture settings.
size (tuple[width,height]) – Size of image.
cache (bool, optional) – Whether to cache waltex images. Defaults to True.
- Returns:
PIL Image.
- Return type:
Image.Image
wmwpy.utils.waltex module¶
- class wmwpy.utils.waltex.Waltex(file: str | bytes, byte_order: str = 'little')[source]¶
Bases:
object
- format = 'waltex'¶
- format_description = 'Walaber image file'¶
- read(byte_order: str | None = None) Image [source]¶
Read the waltex image.
- Parameters:
byte_order (str, optional) – The byte order. Can be ‘little’ or ‘big’. Defaults to None.
- Returns:
PIL Image object
- Return type:
PIL.Image.Image
- property size¶
Return size of image
- Returns:
tuple(width, height)
- Return type:
tuple[int,int]
- wmwpy.utils.waltex.WaltexImage(path: str | bytes | BytesIO, premultiplyAlpha: bool = False, dePremultiplyAlpha: bool = False, endian: str = 'little') Image [source]¶
Depracted¶
Use
Image.load()
instead.I am only keeping this just in case you need to load RGB565 (01) or RGBA5551 (02) waltex format.
Get image from
waltex
fileData on image can be found in coorisponding
imagelist
or inData/TextureSettings.xml
.- param path:
Path to
waltex
image- type path:
str
- param premultiplyAlpha:
Defaults to False.
- type premultiplyAlpha:
bool, optional
- param dePremultiplyAlpha:
Defaults to False.
- type dePremultiplyAlpha:
bool, optional
- param endian:
Endian mode. Set to ‘big’ to use big endian. Defaults to ‘little’.
- type endian:
str, optional
- returns:
Pillow image.
- rtype:
PIL.Image.Image
Thanks to @campbellsonic for the
WrapRawData()
function.