Utilities for working with paths, resources, and loading resources.
Module Contents
Functions
align_font_texture (sheet[, glyph_cell, new_left_padding])
|
Align a font sheet's character's sheet to what new_left_padding is. |
divide_resource_by_grid (resource, row_column_count)
|
Yield images of the sections of a divided resource. |
expand_path (path)
|
Expand path with any variables or shortcuts, such as ~ , $HOME , etc. |
expand_resource_location (file_path)
|
Take any path to a texture file and return the Minecraft file string for it. |
load_bitmap (file_name, base)
|
Companion function to load_resources() but specialized for bitmap provider resources. |
load_resources_legacy_unicode (template, sizes, base)
|
Companion function to load_resources() but specialized for legacy_unicode provider resources. |
load_resources_unihex (file_name, base)
|
Companion function to load_resources() but specialized for unihex provider resources. |
resolve_path (resource, base[, subpath])
|
Resolve the correct path to the resource indicated by path, using origin as the base path to follow from. |
traverse_to_assets (path)
|
Traverse up the path until the /assets/ directory is found, and then cut off the path there. |
-
mcfonts.utils.resources.align_font_texture(sheet, glyph_cell=
(8, 8)
, new_left_padding=0
)
Align a font sheet's character's sheet to what new_left_padding is.
This only shifts the character on the X axis (horizontally, left-right).
- Parameters:
- sheet : PIL.Image.Image
The font sheet, not the individual glyph.
- glyph_cell : tuple[int, int]
The dimensions of each individual character, their cell bounding box.
- new_left_padding : int
The distance away from the left edge the new character should be.
- Returns:
The new font sheet.
- Return type:
PIL.Image.Image
-
mcfonts.utils.resources.divide_resource_by_grid(resource, row_column_count)
Yield images of the sections of a divided resource.
Given a resource and number of characters in each row and column of that resource, yield every
PIL.Image.Image
in that resource.
If no data exists in a cell, yield None.
- Parameters:
- resource : PIL.Image.Image
A PIL.Image.Image
of the font resource.
- row_column_count : tuple[int, int]
A tuple of the number of characters in each row and column of resource.
- Returns:
A yield of PIL.Image.Image
glyphs, or None.
- Return type:
collections.abc.Iterable[PIL.Image.Image | None]
-
mcfonts.utils.resources.expand_path(path)
Expand path with any variables or shortcuts, such as ~
, $HOME
, etc.
>>> expand_path("~/Documents")
'/home/me/Documents'
- Parameters:
- path : os.PathLike[str] | str
The unexpanded path.
- Returns:
The expanded absolute path.
- Return type:
pathlib.Path
-
mcfonts.utils.resources.expand_resource_location(file_path)
Take any path to a texture file and return the Minecraft file string for it.
- Parameters:
- file_path : pathlib.Path
A real path to any file.
- Returns:
A string in the format of "<namespace>?:<dir/>?<file>".
- Return type:
str
-
mcfonts.utils.resources.load_bitmap(file_name, base)
Companion function to load_resources()
but specialized for bitmap provider resources.
- Parameters:
- file_name : str
The name of the file to search for.
- base : pathlib.Path
The path to the base "assets" directory.
- Returns:
A PIL.Image.Image
instance.
- Return type:
PIL.Image.Image
-
mcfonts.utils.resources.load_resources_legacy_unicode(template, sizes, base)
Companion function to load_resources()
but specialized for legacy_unicode provider resources.
- Parameters:
- template : str
The template string, which must include "%s".
- sizes : str
The name of the "sizes" file.
- base : pathlib.Path
The real path to the base /assets/
directory.
- Returns:
A yield of {filename: image}.
- Return type:
collections.abc.Iterable[tuple[str, PIL.Image.Image | bytes]]
-
mcfonts.utils.resources.load_resources_unihex(file_name, base)
Companion function to load_resources()
but specialized for unihex provider resources.
- Parameters:
- file_name : str
The path to the .zip file that contains the .hex files.
- base : pathlib.Path
The real path to the base /assets/
directory.
- Returns:
Yield of (filename, contents)
.
- Return type:
collections.abc.Iterable[tuple[str, str]]
-
mcfonts.utils.resources.resolve_path(resource, base, subpath=
None
)
Resolve the correct path to the resource indicated by path, using origin as the base path to follow from.
origin is where the original calling resource is;
path
is the requested resource path from the requesting resource.
Warning
This function doesn't return extensions.
You must add those later.
>>> resolve_path("mypath", pathlib.Path("~/mcfonts"), "textures")
'~/mcfonts/textures/mypath'
- Parameters:
- resource : str
An unresolved path to the resource.
- base : pathlib.Path
A real path to the central /assets/
directory.
- subpath : str | None
Under what subdirectory in base to start looking for a resource. Optional.
- Returns:
An absolute path of the requested resource.
- Return type:
pathlib.Path
-
mcfonts.utils.resources.traverse_to_assets(path)
Traverse up the path until the /assets/
directory is found, and then cut off the path there.
- Parameters:
- path : pathlib.Path
The path to the file.
- Returns:
The cut-off path up to the /assets/
directory if found.
- Raises:
FileNotFoundError -- If the /assets/
directory could not be found.
- Return type:
pathlib.Path
Last update:
2023 November 30