DMI — Icon Parsing¶
- class avulto.DMI¶
A DMI file.
The DMI class provides the ability to create, parse, and modify
*.dmifiles.Instances are created with the following methods:
- static from_file(filename: os.PathLike[str] | str) DMI¶
Creates a DMI from the given filename.
- static new(dims: tuple[int, int]) DMI¶
Creates an empty DMI file with the given icon width-height tuple dims.
Once instantiated, the following methods and properties are available:
- property filepath: pathlib.Path | None¶
The original filename of the DMI.
- class avulto.IconState¶
A single icon state in a DMI file.
- static from_data(data: Mapping[Dir, Sequence[bytes]], width: int = 32, height: int = 32, name: str = '', delays: Sequence[float] | None = None, loops: int = 0, rewind: bool = False, movement: bool = False) IconState¶
Construct an
IconStatewith the given data and other arguments.data must be a dict mapping
Dirvalues to lists ofbytescontaining RGBA image data. The number of images in each list must be the same, and if there is more than one frame in the icon state, delays must contain the same number of delay intervals as there are images in the state.
- data_rgba8(frame: int, dir: Any) bytes¶
Return the byte data of the spritesheet in 8-bit RGBA.
Using Pillow, the image data for a given icon can quickly be turned into a
PIL.Imageobject and easily manipulated.from avulto import DMI, Dir from PIL import Image dmi = DMI.from_file("/SS13/icons/objects/weapons.dmi") pistol = dmi.state("pistol") data = pistol.data_rgba8(frame=1, dir=Dir.SOUTH) image = Image.frombytes("RGBA", size=dmi.icon_dims, data=data)