wmwpy.classes package

Subpackages

Submodules

wmwpy.classes.level module

class wmwpy.classes.level.Level(xml: str | bytes | File | None = None, image: str | bytes | File | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', load_callback: Callable[[int, str, int], Any] | None = None, ignore_errors: bool = False, HD: bool = False, TabHD: bool = False, object_pack: ObjectPack | None = None)[source]

Bases: GameObject

The Level object.

HD

Using HD graphics

Type:

bool

TabHD

Using TabHD graphics.

Type:

bool

object_pack

The ObjectPack that is being used for all the objects.

Type:

ObjectPack

objects

List of Objects currently in this level.

Type:

list[Object]

properties (dict[str,str]

) All the Level properties.

challenges

List of WMW2 challenges in this level.

Type:

list[Level.Challenge]

room

The room element in WMW levels. I have no idea what this does, but it still should be kept, even though it doesn’t actually do anything.

Type:

tuple[float,float]

class Challenge(xml: ElementBase | None = None, id: str = '', requirements: dict[str, dict[str, str]] = {})[source]

Bases: object

getXML()[source]

Get the XML for the challenge.

Returns:

lxml etree Element.

Return type:

lxml.etree.Element

readXML()[source]

Read the XML of the challenge. If the XML wasn’t set, it’ll just return None

IMAGE_FORMAT = 'PNG'
IMAGE_TEMPLATE = <PIL.Image.Image image mode=P size=90x127>
property PhotoImage: PhotoImage

Tkinter PhotoImage of the Level image

Returns:

Tkinter PhotoImage

Return type:

ImageTk.PhotoImage

XML_TEMPLATE = b'<?xml version="1.0"?>\n    <Objects>\n    </Objects>\n    '
addObject(filename: str | Object, properties: dict = {}, pos: tuple[float, float] = (0, 0), name: str = 'Obj')[source]

Add object to level.

Parameters:
  • filename (str | Object) – Filename for object. If it’s a wmwpy.classes.Object class, then it will use that instead.

  • properties (dict, optional) – Object properties. Defaults to {}.

  • pos (tuple[x,y], optional) – Position of object in level. Defaults to (0,0).

  • name (str, optional) – Name of object. May get renamed if object with name already exists. Defaults to ‘Obj’.

Returns:

wmwpy Object.

Return type:

Object

export(filename: str | None = None, exportObjects: bool = False, saveImage: bool = True) bytes[source]

Export level

Parameters:
  • filename (str, optional) – Path to level. Defaults to Level.filename.

  • exportObjects (bool, optional) – Whether to export objects. Defaults to False.

Raises:

TypeError – Path is not a file.

Returns:

XML file.

Return type:

bytes

getObject(name: str)[source]

Get object by name

Parameters:

name (str) – Object name.

getObjectById(id: int) Object[source]

Get an Object by it’s id

Parameters:

id (int) – Object id to find

Returns:

wmwpy Object

Return type:

Object

property image: Image

Scaled up Level image

Returns:

PIL Image

Return type:

PIL.Image.Image

read(load_callback: Callable[[int, str, int], Any] | None = None, ignore_errors: bool = False)[source]

Read level XML

property scale: int

Level size scale

property size: tuple[int, int]

Level image size

Returns:

(width,height)

Return type:

tuple[int,int]

wmwpy.classes.object module

class wmwpy.classes.object.Object(file: str | bytes | File, filesystem: Filesystem | Folder = None, gamepath: str = None, assets: str = '/assets', baseassets: str = '/', properties: dict = {}, pos: tuple | str = (0, 0), name: str = 'Obj', scale: int = 50, HD: bool = False, TabHD: bool = False, object_pack: ObjectPack = None)[source]

Bases: GameObject

wmwpy Object.

HD

Using HD images.

Type:

bool

TabHD

Using TabHD images.

Type:

bool

sprites

List of sprites.

Type:

list[Sprite]

shapes

List of Shapes.

Type:

list[Shape]

UVs

List of UVs (on the balloon object).

Type:

list[tuple[int,int]]

VertIndices

List of VertIndices (on the balloon object).

Type:

list[int]

defaultProperties

Dictionary of the object default properties (the ones in the object .hs files).

Type:

dict[str,str]

properties

Dictionary of the object properties (the ones in the level xml).

Type:

dict[str,str]

name

The object name.

Type:

str

id

The object id.

Type:

int

frame

The current animation frame.

Type:

int

object_pack

The game Object Pack.

Type:

ObjectPack

scale

The image scale.

Type:

float

property PhotoImage: PhotoImage

Tkinter PhotoImage of the Object image

Returns:

Tkinter PhotoImage

Return type:

ImageTk.PhotoImage

property SAFE_MODE: bool

Safe mode allows the properties to be modified without carrying onto the level xml.

Returns:

The current state.

Return type:

bool

property Type
property background: Image

The background image of this Object

Returns:

PIL Image

Return type:

PIL.Image.Image

property background_PhotoImage: PhotoImage

Tkinter PhotoImage of this Object

Returns:

Tkinter PhotoImage

Return type:

ImageTk.PhotoImage

copy() Object[source]

Creates a copy of this object (aka, get the object again).

Returns:

New Object.

Return type:

Object

export(path: str | None = None) bytes[source]

Export object XML

Parameters:

path (str, optional) – Filename for object. Defaults to Object.filename.

Raises:

TypeError – Path is not a file

Returns:

XML file.

Return type:

bytes

property filename: str | None

Object filename based on the Filename property

property foreground: Image

The foreground of the Object image

Returns:

PIL Image

Return type:

PIL.Image.Image

property foreground_PhotoImage: PhotoImage

Foreground Tkinter PhotoImage

Returns:

Tkinter PhotoImage

Return type:

ImageTk.PhotoImage

property frame: int

The current animation frame.

Returns:

Current frame.

Return type:

int

getAnimation(duration: int = 0, fps: float = 0) dict[Literal['fps', 'frame_duration', 'frames'], float | int | list[PIL.Image.Image]][source]

Get the animation of this object

Parameters:
  • duration (int, optional) – Duration of animation in seconds. If 0, it will try to create a perfect loop. Defaults to 0.

  • fps (float, optional) – The fps of the animation. If 0, it will try to detect the fps that works for all the sprites. Defaults to 0.

Raises:

TypeError – ‘fps must be an int or float’

getLevelXML(filename: str | None = None) ElementBase[source]

Gets XML to be used in levels.

Parameters:

filename (str, optional) – Object filename. Defaults to Object.filename.

Returns:

lxml Element

Return type:

etree.Element

getOffset() tuple[float, float][source]

Get the center offset for the Object image

Returns:

(x,y)

Return type:

tuple[float,float]

getProperties()[source]

Get the object properties.

Returns:

The properties dictionary.

Return type:

dict[str,str]

property image: Image

Full Object image, with both the background and foreground.

Returns:

PIL Image

Return type:

PIL.Image.Image

property offset: tuple[float, float]

The center offset of the Object image

Returns:

(x,y)

Return type:

tuple[float,float]

readXML()[source]

Read object XML

rotateImage(image: Image) Image[source]

Rotate an image the amount of degrees as the Object Angle property

Parameters:

image (PIL.Image.Image) – Image to rotate

Returns:

Rotated PIL Image

Return type:

PIL.Image.Image

rotatePoint(point: tuple = (0, 0), angle: float | None = None) tuple[float, float][source]

Rotate a point around (0,0)

Parameters:
  • point (tuple, optional) – Point to rotate. Defaults to (0,0).

  • angle (float, optional) – Angle to rotate. Defaults to Object Angle property.

Returns:

(x,y)

Return type:

tuple[float,float]

saveGIF(filename=None, duration: int = 0, fps: float = 0)[source]

Save object as a gif.

Parameters:
  • filename (str, optional) – The filename to save this object gif as. Defaults to None.

  • duration (int, optional) – The duration of the gif in seconds. If it’s 0, it automatically finds a perfect loop. Defaults to 0.

  • fps (float, optional) – The frames per second of the animation. If it’s 0, it is automatically calculated. Defaults to 0.

Returns:

The resulting PIL Image object.

Return type:

PIL.Image.Image

property scale: int

Object image scale

setProperty(property: str | dict, value: str = '')[source]

Set object property.

Parameters:
  • property (str | dict) – Property name to set. If value is dict, it will combine the properties in the dict with the current properties.

  • value (str, optional) – Property value. Defaults to ‘’.

property type: str | None

The Object type, based off the Type property.

updateProperties()[source]

Update properties. Deletes any properties that are the same as defaultProperties, unless specified by the object type in the ObjectPack.

class wmwpy.classes.object.Shape(xml: ElementBase | None = None)[source]

Bases: GameObject

Shape object for wmwpy Object.

points

List of shape points.

Type:

list[tuple[float,float]]

getXML() ElementBase[source]

Gets Shape XML for Object.

Returns:

lxml Element.

Return type:

etree.Element

property image: Image

Get the Shape image

Returns:

PIL Image

Return type:

PIL.Image.Image

readXML()[source]

Read XML if any.

wmwpy.classes.sprite module

class wmwpy.classes.sprite.Sprite(file: str | bytes | File | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', properties: dict = {}, scale: float = 50, HD: bool = False, TabHD: bool = False)[source]

Bases: GameObject

wmwpy Sprite.

HD

Using HD images.

Type:

bool

TabHD

Using TabHD images.

Type:

bool

properties

Sprite properties.

Type:

dict[str,str]

animations

List of animations.

Type:

list[Sprite.Animation]

scale

The image scale.

Type:

float

class Animation(xml: str | ElementBase | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', HD: bool = False, TabHD: bool = False)[source]

Bases: GameObject

Animation object for wmwpy Sprite.

HD

Using HD images.

Type:

bool

TabHD

Using TabHD images.

Type:

bool

properties

The animation properties.

Type:

dict[str,str]

frames

List of frames.

Type:

list[Sprite.Animation.Frame]

frame

The current animation frame.

Type:

int

class Frame(properties: dict = {}, atlas: Imagelist | None = None, textureBasePath: str | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/')[source]

Bases: GameObject

The Frame for Animations.

atlas

The atlas for this Frame.

Type:

Imagelist

textureBasePath

The textureBasePath for this Frame.

Type:

str

properties

The frame properties.

Type:

dict[str,str]

property SAFE_MODE: bool

A “safe mode” where you can modify the properties without them being added to the output xml.

Returns:

The current state.

Return type:

bool

property angleDeg: float

The frame rotation angle.

Returns:

Angle in degrees.

Return type:

float

getImage()[source]

Get the image. The image is stored in Frame._image.

getXML() ElementBase[source]

Get the XML for the Frame

Returns:

XML of this Frame

Return type:

etree.Element

property image: Image

Image of this Image

Returns:

PIL Image

Return type:

PIL.Image.Image

property name: str

The name of this frame.

Returns:

The name of this frame.

Return type:

str

property offset: tuple[float, float]

The frame offset.

Returns:

(x,y)

Return type:

tuple[float,float]

property repeat: int

The amount of times to repeat this frame in the animation.

Returns:

The amount of times to repeat.

Return type:

int

property scale: tuple[float, float]

The frame scale.

Returns:

(x,y)

Return type:

tuple[float, float]

show(*args, **kwargs)[source]

Calls the PIL.Image.Image.show() method.

Description copied from the PIL library

Displays this image. This method is mainly intended for debugging purposes.

This method calls PIL.ImageShow.show internally. You can use PIL.ImageShow.register to override its default behavior.

The image is first saved to a temporary file. By default, it will be in PNG format.

On Unix, the image is then opened using the display, eog or xv utility, depending on which one can be found.

On macOS, the image is opened with the native Preview application.

On Windows, the image is opened with the standard PNG display utility.

param title:

Optional title to use for the image window, where possible.. Defaults to None.

type title:

str | None, optional

property texture: Texture

The frame Texture instead of atlas.

Returns:

The Texture object.

Return type:

Texture

updateProperties()[source]

Update Image properties

property PhotoImage: PhotoImage

Tkinter PhotoImage for the Animation

property SAFE_MODE: bool

A “safe mode” where you can modify the properties without them being added to the output xml.

Returns:

The current state.

Return type:

bool

TEMPLATE = '<Animation>\n</Animation>\n'
property atlas: Imagelist
property atlasPath: str

The path to the atlas.

Returns:

The path to the atlas file.

Return type:

str

property fps: float

The Animation fps.

Returns:

The Animation fps.

Return type:

float

property frame: int

Current animation frame.

Returns:

Current animation frame index.

Return type:

int

getAnimation(duration: int = 0, fps: float = 0) dict[Literal['fps', 'frame_duration', 'frames'], float | int | list[PIL.Image.Image]][source]

Get the animation of this object

Parameters:
  • duration (int, optional) – Duration of animation in seconds. If 0, it will try to create a perfect loop. Defaults to 0.

  • fps (float, optional) – The fps of the animation. If 0, it will try to detect the fps that works for all the sprites. Defaults to 0.

Raises:

TypeError – ‘fps must be an int or float’

getAttributes()[source]

Get all the attributes of this Animation

getFrames() list['Sprite.Animation.Frame'][source]

Get a list of all the Animation ``Frame``s

Returns:

List of all the Frames in this Animation.

Return type:

list[Sprite.Animation.Frame]

getXML()[source]

Get the XML of this Animation

Returns:

etree Element

Return type:

etree.Element

property image: Image

Current Animation image

Returns:

PIL Image

Return type:

PIL.Image.Image

property loopCount: int

The loopCount for this Animation.

Returns:

The loopCount.

Return type:

int

property name: str

Name of this animation.

Returns:

The name of this animation.

Return type:

str

property playbackMode: str

The playback mode.

Returns:

The current playback mode.

Return type:

str

readXML()[source]

Read the xml for this Animation

saveGIF(filename=None, duration: int = 0, fps: float = 0) Image[source]

Save animation as a gif.

Parameters:
  • filename (str, optional) – The filename to save this animation gif as. Defaults to None.

  • duration (int, optional) – The duration of the gif in seconds. If it’s 0, it automatically finds a perfect loop. Defaults to 0.

  • fps (float, optional) – The frames per second of the animation. If it’s 0, it is automatically calculated. Defaults to 0.

Returns:

The resulting PIL Image object.

Return type:

PIL.Image.Image

property texture: Texture

The texture for this animation. Sometimes used instead of an atlas.

Returns:

The Texture.

Return type:

Texture

property textureBasePath: str

The textureBasePath where all textures are stored.

Returns:

textureBasePath.

Return type:

str

updateProperties()[source]

Update the Sprite properties

property SAFE_MODE: bool

A “safe mode” where you can modify the properties without them being added to the output xml.

Returns:

The current state.

Return type:

bool

TEMPLATE = b'<?xml version="1.0"?>\n<Sprite>\n</Sprite>\n'
property angle: float

Sprite rotation angle

Returns:

Angle as degrees

Return type:

float

property animation: Animation

Returns the current animation

Returns:

A Sprite.Animation class

Return type:

Sprite.Animation

export(path: str | None = None) bytes[source]

Export the Sprite XML file

Parameters:

path (str, optional) – Path to export into the filesystem. Defaults to the original filename.

Raises:

TypeError – Path is not a file.

Returns:

Contents of saved file.

Return type:

bytes

property filename: str

Sprite filename

property fps: float
property frame: int

The current animation frame.

Returns:

Current animation frame index.

Return type:

int

property frames: list['Sprite.Animation.Frame']

Returns the current animation frames.

Returns:

A list of frames.

Return type:

list[Sprite.Animation.Frame]

getAnimation(duration: int = 0, fps: float = 0) dict[Literal['fps', 'frame_duration', 'frames'], float | int | list[PIL.Image.Image]][source]

Get the animation of this object

Parameters:
  • duration (int, optional) – Duration of animation in seconds. If 0, it will try to create a perfect loop. Defaults to 0.

  • fps (float, optional) – The fps of the animation. If 0, it will try to detect the fps that works for all the sprites. Defaults to 0.

Raises:

TypeError – ‘fps must be an int or float’

property gridSize: tuple[float, float]

The gridSize (size) of this Sprite

Returns:

(width,height)

Return type:

tuple[float,float]

property image: Image

Image of sprite

Returns:

PIL Image

Return type:

PIL.Image.Image

property isBackground

Whether this Sprite is a background

property pos: tuple[float, float]

Position of Sprite relative to the center of the Object

Returns:

(x,y)

Return type:

tuple[float,float]

readXML()[source]

Read Sprite XML

saveGIF(filename: str | None = None, duration: int = 0, fps: float = 0)[source]

Save current animation as a gif.

Parameters:
  • filename (str, optional) – The filename to save this animation gif as. Defaults to None.

  • duration (int, optional) – The duration of the gif in seconds. If it’s 0, it automatically finds a perfect loop. Defaults to 0.

  • fps (float, optional) – The frames per second of the animation. If it’s 0, it is automatically calculated. Defaults to 0.

Returns:

The resulting PIL Image object.

Return type:

PIL.Image.Image

setAnimation(animation: str | int)[source]

Set the current animation for the Sprite

Parameters:

animation (str | int) – Animation name or index.

property visible: bool

Whether this Sprite is visible or not

wmwpy.classes.imagelist module

class wmwpy.classes.imagelist.Imagelist(file: str | bytes | File | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', HD: bool = False, TabHD: bool = False, save_images: bool = False)[source]

Bases: GameObject

class Format[source]

Bases: object

IMAGELIST = 0
PAGES = 1
class Page(element: ElementBase, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', HD: bool = False, TabHD: bool = False, save_images: bool = False)[source]

Bases: GameObject

class Image(atlas: Image, properties: dict, textureBasePath='/Textures', filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', save_image: bool = False)[source]

Bases: GameObject

property filename: str

Image filepath in the Filesystem

Returns:

Full filepath in the Filesystem

Return type:

str

getImage() Image[source]

Get image from atlas.

Returns:

PIL Image.

Return type:

PIL.Image.Image

getXML(tag='Image')[source]

Get xml for image.

Returns:

lxml element

Return type:

lxml.etree.Element

property image

The resulting PIL Image.

Returns:

PIL Image.

Return type:

PIL.Image.Image

property name: str

The name of the image

Returns:

image name

Return type:

str

property offset: tuple[int, int]

The image offset

Returns:

(x,y)

Return type:

tuple[int,int]

(I have no idea what this is for)

property rect: tuple[int, int, int, int]

The rectangle of this image inside the atlas

Returns:

(x,y,width,height)

Return type:

tuple[int,int,int,int]

removeFile()[source]

Remove file from filesystem.

saveFile(replace: bool = False)[source]

Save image to filesystem.

Parameters:

replace (bool, optional) – Whether to replace any existing file. Defaults to False.

show(*args, **kwargs)[source]

Calls the PIL.Image.Image.show() method.

Description copied from the PIL library

Displays this image. This method is mainly intended for debugging purposes.

This method calls PIL.ImageShow.show internally. You can use PIL.ImageShow.register to override its default behavior.

The image is first saved to a temporary file. By default, it will be in PNG format.

On Unix, the image is then opened using the display, eog or xv utility, depending on which one can be found.

On macOS, the image is opened with the native Preview application.

On Windows, the image is opened with the standard PNG display utility.

param title:

Optional title to use for the image window, where possible.. Defaults to None.

type title:

str | None, optional

property size: tuple[int, int]

The size of the image.

Returns:

(width,height)

Return type:

tuple[int,int]

add(name: str, image: Image, properties: dict = {}, replace=False) Image[source]

Add image to imagelist.

Parameters:
  • name (str) – Name of image file used in-game.

  • image (PIL.Image.Image) – Image to use.

  • properties (dict, optional) – Additional properties for image. Defaults to {}.

  • replace (bool, optional) – Whether to replace existing image if there is a conflict. Defaults to False.

Raises:

NameError – Image already exists.

Returns:

Resulting imagelist image.

Return type:

Imagelist.Page.Image

exportAtlas(filename=None, gap: tuple = (1, 1), auto_fit=False, format: str = 'webp')[source]

Export the atlas image into the Filesystem. This function recreates the imagelist, so you need to also export the xml using getXML().

Parameters:
  • gap (tuple, optional) – Gap between each image. Defaults to (1,1).

  • filename (str, optional) – Filename of image. Defaults to file property.

  • auto_fit (bool, optional) – Auto minimize the atlas image size while keeping all the sprites in the image. Defaults to False.

  • format (str, optional) – Format to save image as. Defaults to ‘webp’.

Returns:

PIL Image.

Return type:

PIL.Image.Image

property file: str

The path to the atlas file to use in this ImageList

Returns:

Path to atlas file.

Return type:

str

get(name: str) Image[source]

Get an image from the imagelist

Parameters:

name (str) – Name of image.

Returns:

Imagelist Image.

Return type:

Imagelist.Page.Image

getAtlas()[source]

Get atlas image.

getImages(save_images=False)[source]

Get images from xml. :param save_images: Save images in filesystem. Note: this may take more time to load the imagelist. Defaults to False. :type save_images: bool, optional

getXML(filename=None, format: int = 1)[source]

Generates the xml for the page / imagelist.

Parameters:
  • filename (str, optional) – Name of image. Defaults to file property.

  • format (int, optional) – Format of file. 0 for Imagelist, 1 for Page. Defaults to 1.

Returns:

lxml Element.

Return type:

lxml.etree.Element

property id

Page id

Returns:

The id

Return type:

str

property imgSize: tuple[int, int]

The size of the image in the properties. Does not have to reflect the size of the atlas.

Returns:

(width,height)

Return type:

tuple[int,int]

read(save_images: bool = False)[source]

Read xml.

Parameters:

save_images (bool, optional) – Save images in filesystem. Note: this may take more time to load the imagelist. Defaults to False.

removeImageFiles()[source]

Remove all image files from filesystem.

property textureBasePath: str

The base Textures path, or the place where the files are extracted to.

Returns:

The textureBasePath

Return type:

str

update(gap: tuple[int, int] = (1, 1), auto_fit=False)[source]

Update the atlas image.

Parameters:
  • gap (tuple[int,int], optional) – The gap between images. Defaults to (1,1).

  • auto_fit (bool, optional) – Auto minimize the atlas image size while keeping all the sprites in the image. Defaults to False.

TEMPLATE = b'<?xml version="1.0"?>\n    <ImageList imgSize="512 512" file="" textureBasePath="/Textures/">\n    </ImageList>\n    '
add(name: str, image: Image, properties: dict = {}, page: int | str = 0, replace=False)[source]

Add image to imagelist.

Parameters:
  • name (str) – Name of image file used in-game.

  • image (PIL.Image.Image) – Image to use.

  • properties (dict, optional) – Additional properties for image. Defaults to {}.

  • replace (bool, optional) – Whether to replace existing image if there is a conflict. Defaults to False.

Raises:

NameError – Image already exists.

Returns:

Resulting imagelist image.

Return type:

Imagelist.Page.Image

combinePages()[source]

Combine all the pages in this Imagelist into 1 Page

export(path: str | None = None, exportImage: bool = True, format: str = 'webp', removeImageFiles: bool = True)[source]

Export the xml of the imagelist.

Parameters:
  • path (str, optional) – Path to the file in the filesystem to write to. If None, it will not save to a file, only report the output. Defaults to None.

  • exportImage (bool, optional) – Whether to also export the atlas image(s). If there are multiple pages, it’ll append _split_# to the end of the filenames. Defaults to False.

  • imageFormat (str, optional) – What format to export the images as. Defaults to ‘webp’.

  • removeImageFiles (bool, optional) – Remove image files from filesystem. Defaults to False.

Raises:

TypeError – Path is an existing folder.

Returns:

The xml output as bytes.

Return type:

bytes

get(name: str)[source]

Get image from imagelist.

Parameters:

name (str) – Name of image.

Returns:

Imagelist Image.

Return type:

Imagelist.Page.Image

getPage(id: int | str = 0) Page[source]

Get the page with this id / index.

Parameters:

id (int | str, optional) – The id or index of the page. Defaults to 0.

Raises:

TypeError – id must be int or str

Returns:

The page that has the id or index.

Return type:

Imagelist.Page

read(save_images: bool = False)[source]

Read the imagelist xml.

Parameters:

save_images (bool, optional) – Save images in filesystem. Note: this may take more time to load the imagelist. Defaults to False.

removeImageFiles()[source]

Remove all image files in imagelist from filesystem.

update(gap: tuple[int, int] = (1, 1), auto_fit=False)[source]

Update the atlas image.

Parameters:
  • gap (tuple[int,int], optional) – The gap between images. Defaults to (1,1).

  • auto_fit (bool, optional) – Auto minimize the atlas image size while keeping all the sprites in the image. Defaults to False.

wmwpy.classes.location module

class wmwpy.classes.location.Location(file: File | str | bytes, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/')[source]

Bases: GameObject

Location object for location xml files in WMW2.

backgrounds

List of backgrounds.

Type:

list[dict[str,str]]

levels

List of levels.

Type:

list[dict[str,str]]

widgets

List of widgets.

Type:

list[dict[str,str]]

sprites

List of sprites (if any).

Type:

list[dict[str,str]]

armatures

List of Armatures.

Type:

list[dict[str,str]]

waterPaths

List of WaterPaths.

Type:

list[dict[str,str]]

atlases

List of Atlases.

Type:

list[dict[str,str]]

expertAtlases

List of ExpertAtlases.

Type:

list[dict[str,str]]

transitionPiece

List of TransitionPieces.

Type:

list[dict[str,str]]

expertModeAssets

List of ExpertModeAssets.

Type:

list[dict[str,str]]

audios

List of Audios.

Type:

list[dict[str,str]]

read()[source]

Read the XML file.

wmwpy.classes.database module

class wmwpy.classes.database.Database(database: str | bytes | File, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/')[source]

Bases: GameObject

property connection: Connection

The sqlite3 python database object.

Returns:

sqlite3 database connection

Return type:

sqlite3.Connection

execute(*args)[source]

Execute sql on the database. See sqlite3.Cursor.execute for parameters.

Parameters:

sqlite3.Cursor.execute() (The arguments for) –

Returns:

The sqlite3 Cursor object.

Return type:

sqlite3.Cursor

export(filename: str | None = None) bytes[source]

Export the database into the filesystem.

Parameters:

filename (str, optional) – The filename of the database. Defaults to None.

Returns:

Output file in bytes.

Return type:

bytes

Module contents

class wmwpy.classes.Database(database: str | bytes | File, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/')[source]

Bases: GameObject

property connection: Connection

The sqlite3 python database object.

Returns:

sqlite3 database connection

Return type:

sqlite3.Connection

execute(*args)[source]

Execute sql on the database. See sqlite3.Cursor.execute for parameters.

Parameters:

sqlite3.Cursor.execute() (The arguments for) –

Returns:

The sqlite3 Cursor object.

Return type:

sqlite3.Cursor

export(filename: str | None = None) bytes[source]

Export the database into the filesystem.

Parameters:

filename (str, optional) – The filename of the database. Defaults to None.

Returns:

Output file in bytes.

Return type:

bytes

class wmwpy.classes.Imagelist(file: str | bytes | File | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', HD: bool = False, TabHD: bool = False, save_images: bool = False)[source]

Bases: GameObject

class Format[source]

Bases: object

IMAGELIST = 0
PAGES = 1
class Page(element: ElementBase, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', HD: bool = False, TabHD: bool = False, save_images: bool = False)[source]

Bases: GameObject

class Image(atlas: Image, properties: dict, textureBasePath='/Textures', filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', save_image: bool = False)[source]

Bases: GameObject

property filename: str

Image filepath in the Filesystem

Returns:

Full filepath in the Filesystem

Return type:

str

getImage() Image[source]

Get image from atlas.

Returns:

PIL Image.

Return type:

PIL.Image.Image

getXML(tag='Image')[source]

Get xml for image.

Returns:

lxml element

Return type:

lxml.etree.Element

property image

The resulting PIL Image.

Returns:

PIL Image.

Return type:

PIL.Image.Image

property name: str

The name of the image

Returns:

image name

Return type:

str

property offset: tuple[int, int]

The image offset

Returns:

(x,y)

Return type:

tuple[int,int]

(I have no idea what this is for)

property rect: tuple[int, int, int, int]

The rectangle of this image inside the atlas

Returns:

(x,y,width,height)

Return type:

tuple[int,int,int,int]

removeFile()[source]

Remove file from filesystem.

saveFile(replace: bool = False)[source]

Save image to filesystem.

Parameters:

replace (bool, optional) – Whether to replace any existing file. Defaults to False.

show(*args, **kwargs)[source]

Calls the PIL.Image.Image.show() method.

Description copied from the PIL library

Displays this image. This method is mainly intended for debugging purposes.

This method calls PIL.ImageShow.show internally. You can use PIL.ImageShow.register to override its default behavior.

The image is first saved to a temporary file. By default, it will be in PNG format.

On Unix, the image is then opened using the display, eog or xv utility, depending on which one can be found.

On macOS, the image is opened with the native Preview application.

On Windows, the image is opened with the standard PNG display utility.

param title:

Optional title to use for the image window, where possible.. Defaults to None.

type title:

str | None, optional

property size: tuple[int, int]

The size of the image.

Returns:

(width,height)

Return type:

tuple[int,int]

add(name: str, image: Image, properties: dict = {}, replace=False) Image[source]

Add image to imagelist.

Parameters:
  • name (str) – Name of image file used in-game.

  • image (PIL.Image.Image) – Image to use.

  • properties (dict, optional) – Additional properties for image. Defaults to {}.

  • replace (bool, optional) – Whether to replace existing image if there is a conflict. Defaults to False.

Raises:

NameError – Image already exists.

Returns:

Resulting imagelist image.

Return type:

Imagelist.Page.Image

exportAtlas(filename=None, gap: tuple = (1, 1), auto_fit=False, format: str = 'webp')[source]

Export the atlas image into the Filesystem. This function recreates the imagelist, so you need to also export the xml using getXML().

Parameters:
  • gap (tuple, optional) – Gap between each image. Defaults to (1,1).

  • filename (str, optional) – Filename of image. Defaults to file property.

  • auto_fit (bool, optional) – Auto minimize the atlas image size while keeping all the sprites in the image. Defaults to False.

  • format (str, optional) – Format to save image as. Defaults to ‘webp’.

Returns:

PIL Image.

Return type:

PIL.Image.Image

property file: str

The path to the atlas file to use in this ImageList

Returns:

Path to atlas file.

Return type:

str

get(name: str) Image[source]

Get an image from the imagelist

Parameters:

name (str) – Name of image.

Returns:

Imagelist Image.

Return type:

Imagelist.Page.Image

getAtlas()[source]

Get atlas image.

getImages(save_images=False)[source]

Get images from xml. :param save_images: Save images in filesystem. Note: this may take more time to load the imagelist. Defaults to False. :type save_images: bool, optional

getXML(filename=None, format: int = 1)[source]

Generates the xml for the page / imagelist.

Parameters:
  • filename (str, optional) – Name of image. Defaults to file property.

  • format (int, optional) – Format of file. 0 for Imagelist, 1 for Page. Defaults to 1.

Returns:

lxml Element.

Return type:

lxml.etree.Element

property id

Page id

Returns:

The id

Return type:

str

property imgSize: tuple[int, int]

The size of the image in the properties. Does not have to reflect the size of the atlas.

Returns:

(width,height)

Return type:

tuple[int,int]

read(save_images: bool = False)[source]

Read xml.

Parameters:

save_images (bool, optional) – Save images in filesystem. Note: this may take more time to load the imagelist. Defaults to False.

removeImageFiles()[source]

Remove all image files from filesystem.

property textureBasePath: str

The base Textures path, or the place where the files are extracted to.

Returns:

The textureBasePath

Return type:

str

update(gap: tuple[int, int] = (1, 1), auto_fit=False)[source]

Update the atlas image.

Parameters:
  • gap (tuple[int,int], optional) – The gap between images. Defaults to (1,1).

  • auto_fit (bool, optional) – Auto minimize the atlas image size while keeping all the sprites in the image. Defaults to False.

TEMPLATE = b'<?xml version="1.0"?>\n    <ImageList imgSize="512 512" file="" textureBasePath="/Textures/">\n    </ImageList>\n    '
add(name: str, image: Image, properties: dict = {}, page: int | str = 0, replace=False)[source]

Add image to imagelist.

Parameters:
  • name (str) – Name of image file used in-game.

  • image (PIL.Image.Image) – Image to use.

  • properties (dict, optional) – Additional properties for image. Defaults to {}.

  • replace (bool, optional) – Whether to replace existing image if there is a conflict. Defaults to False.

Raises:

NameError – Image already exists.

Returns:

Resulting imagelist image.

Return type:

Imagelist.Page.Image

combinePages()[source]

Combine all the pages in this Imagelist into 1 Page

export(path: str | None = None, exportImage: bool = True, format: str = 'webp', removeImageFiles: bool = True)[source]

Export the xml of the imagelist.

Parameters:
  • path (str, optional) – Path to the file in the filesystem to write to. If None, it will not save to a file, only report the output. Defaults to None.

  • exportImage (bool, optional) – Whether to also export the atlas image(s). If there are multiple pages, it’ll append _split_# to the end of the filenames. Defaults to False.

  • imageFormat (str, optional) – What format to export the images as. Defaults to ‘webp’.

  • removeImageFiles (bool, optional) – Remove image files from filesystem. Defaults to False.

Raises:

TypeError – Path is an existing folder.

Returns:

The xml output as bytes.

Return type:

bytes

get(name: str)[source]

Get image from imagelist.

Parameters:

name (str) – Name of image.

Returns:

Imagelist Image.

Return type:

Imagelist.Page.Image

getPage(id: int | str = 0) Page[source]

Get the page with this id / index.

Parameters:

id (int | str, optional) – The id or index of the page. Defaults to 0.

Raises:

TypeError – id must be int or str

Returns:

The page that has the id or index.

Return type:

Imagelist.Page

pages: list[wmwpy.classes.imagelist.Imagelist.Page]
read(save_images: bool = False)[source]

Read the imagelist xml.

Parameters:

save_images (bool, optional) – Save images in filesystem. Note: this may take more time to load the imagelist. Defaults to False.

removeImageFiles()[source]

Remove all image files in imagelist from filesystem.

update(gap: tuple[int, int] = (1, 1), auto_fit=False)[source]

Update the atlas image.

Parameters:
  • gap (tuple[int,int], optional) – The gap between images. Defaults to (1,1).

  • auto_fit (bool, optional) – Auto minimize the atlas image size while keeping all the sprites in the image. Defaults to False.

xml: ElementBase
class wmwpy.classes.Layout(file: str | bytes | File | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/')[source]

Bases: GameObject

class wmwpy.classes.Level(xml: str | bytes | File | None = None, image: str | bytes | File | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', load_callback: Callable[[int, str, int], Any] | None = None, ignore_errors: bool = False, HD: bool = False, TabHD: bool = False, object_pack: ObjectPack | None = None)[source]

Bases: GameObject

The Level object.

HD

Using HD graphics

Type:

bool

TabHD

Using TabHD graphics.

Type:

bool

object_pack

The ObjectPack that is being used for all the objects.

Type:

ObjectPack

objects

List of Objects currently in this level.

Type:

list[Object]

properties (dict[str,str]

) All the Level properties.

challenges

List of WMW2 challenges in this level.

Type:

list[Level.Challenge]

room

The room element in WMW levels. I have no idea what this does, but it still should be kept, even though it doesn’t actually do anything.

Type:

tuple[float,float]

class Challenge(xml: ElementBase | None = None, id: str = '', requirements: dict[str, dict[str, str]] = {})[source]

Bases: object

getXML()[source]

Get the XML for the challenge.

Returns:

lxml etree Element.

Return type:

lxml.etree.Element

readXML()[source]

Read the XML of the challenge. If the XML wasn’t set, it’ll just return None

IMAGE_FORMAT = 'PNG'
IMAGE_TEMPLATE = <PIL.Image.Image image mode=P size=90x127>
property PhotoImage: PhotoImage

Tkinter PhotoImage of the Level image

Returns:

Tkinter PhotoImage

Return type:

ImageTk.PhotoImage

XML_TEMPLATE = b'<?xml version="1.0"?>\n    <Objects>\n    </Objects>\n    '
addObject(filename: str | Object, properties: dict = {}, pos: tuple[float, float] = (0, 0), name: str = 'Obj')[source]

Add object to level.

Parameters:
  • filename (str | Object) – Filename for object. If it’s a wmwpy.classes.Object class, then it will use that instead.

  • properties (dict, optional) – Object properties. Defaults to {}.

  • pos (tuple[x,y], optional) – Position of object in level. Defaults to (0,0).

  • name (str, optional) – Name of object. May get renamed if object with name already exists. Defaults to ‘Obj’.

Returns:

wmwpy Object.

Return type:

Object

challenges: list[wmwpy.classes.level.Level.Challenge]
export(filename: str | None = None, exportObjects: bool = False, saveImage: bool = True) bytes[source]

Export level

Parameters:
  • filename (str, optional) – Path to level. Defaults to Level.filename.

  • exportObjects (bool, optional) – Whether to export objects. Defaults to False.

Raises:

TypeError – Path is not a file.

Returns:

XML file.

Return type:

bytes

getObject(name: str)[source]

Get object by name

Parameters:

name (str) – Object name.

getObjectById(id: int) Object[source]

Get an Object by it’s id

Parameters:

id (int) – Object id to find

Returns:

wmwpy Object

Return type:

Object

property image: Image

Scaled up Level image

Returns:

PIL Image

Return type:

PIL.Image.Image

objects: list[wmwpy.classes.object.Object]
properties: dict[str, str]
read(load_callback: Callable[[int, str, int], Any] | None = None, ignore_errors: bool = False)[source]

Read level XML

property scale: int

Level size scale

property size: tuple[int, int]

Level image size

Returns:

(width,height)

Return type:

tuple[int,int]

class wmwpy.classes.Location(file: File | str | bytes, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/')[source]

Bases: GameObject

Location object for location xml files in WMW2.

backgrounds

List of backgrounds.

Type:

list[dict[str,str]]

levels

List of levels.

Type:

list[dict[str,str]]

widgets

List of widgets.

Type:

list[dict[str,str]]

sprites

List of sprites (if any).

Type:

list[dict[str,str]]

armatures

List of Armatures.

Type:

list[dict[str,str]]

waterPaths

List of WaterPaths.

Type:

list[dict[str,str]]

atlases

List of Atlases.

Type:

list[dict[str,str]]

expertAtlases

List of ExpertAtlases.

Type:

list[dict[str,str]]

transitionPiece

List of TransitionPieces.

Type:

list[dict[str,str]]

expertModeAssets

List of ExpertModeAssets.

Type:

list[dict[str,str]]

audios

List of Audios.

Type:

list[dict[str,str]]

read()[source]

Read the XML file.

class wmwpy.classes.Object(file: str | bytes | File, filesystem: Filesystem | Folder = None, gamepath: str = None, assets: str = '/assets', baseassets: str = '/', properties: dict = {}, pos: tuple | str = (0, 0), name: str = 'Obj', scale: int = 50, HD: bool = False, TabHD: bool = False, object_pack: ObjectPack = None)[source]

Bases: GameObject

wmwpy Object.

HD

Using HD images.

Type:

bool

TabHD

Using TabHD images.

Type:

bool

sprites

List of sprites.

Type:

list[Sprite]

shapes

List of Shapes.

Type:

list[Shape]

UVs

List of UVs (on the balloon object).

Type:

list[tuple[int,int]]

VertIndices

List of VertIndices (on the balloon object).

Type:

list[int]

defaultProperties

Dictionary of the object default properties (the ones in the object .hs files).

Type:

dict[str,str]

properties

Dictionary of the object properties (the ones in the level xml).

Type:

dict[str,str]

name

The object name.

Type:

str

id

The object id.

Type:

int

frame

The current animation frame.

Type:

int

object_pack

The game Object Pack.

Type:

ObjectPack

scale

The image scale.

Type:

float

property PhotoImage: PhotoImage

Tkinter PhotoImage of the Object image

Returns:

Tkinter PhotoImage

Return type:

ImageTk.PhotoImage

property SAFE_MODE: bool

Safe mode allows the properties to be modified without carrying onto the level xml.

Returns:

The current state.

Return type:

bool

property Type
property background: Image

The background image of this Object

Returns:

PIL Image

Return type:

PIL.Image.Image

property background_PhotoImage: PhotoImage

Tkinter PhotoImage of this Object

Returns:

Tkinter PhotoImage

Return type:

ImageTk.PhotoImage

copy() Object[source]

Creates a copy of this object (aka, get the object again).

Returns:

New Object.

Return type:

Object

export(path: str | None = None) bytes[source]

Export object XML

Parameters:

path (str, optional) – Filename for object. Defaults to Object.filename.

Raises:

TypeError – Path is not a file

Returns:

XML file.

Return type:

bytes

property filename: str | None

Object filename based on the Filename property

property foreground: Image

The foreground of the Object image

Returns:

PIL Image

Return type:

PIL.Image.Image

property foreground_PhotoImage: PhotoImage

Foreground Tkinter PhotoImage

Returns:

Tkinter PhotoImage

Return type:

ImageTk.PhotoImage

property frame: int

The current animation frame.

Returns:

Current frame.

Return type:

int

getAnimation(duration: int = 0, fps: float = 0) dict[Literal['fps', 'frame_duration', 'frames'], float | int | list[PIL.Image.Image]][source]

Get the animation of this object

Parameters:
  • duration (int, optional) – Duration of animation in seconds. If 0, it will try to create a perfect loop. Defaults to 0.

  • fps (float, optional) – The fps of the animation. If 0, it will try to detect the fps that works for all the sprites. Defaults to 0.

Raises:

TypeError – ‘fps must be an int or float’

getLevelXML(filename: str | None = None) ElementBase[source]

Gets XML to be used in levels.

Parameters:

filename (str, optional) – Object filename. Defaults to Object.filename.

Returns:

lxml Element

Return type:

etree.Element

getOffset() tuple[float, float][source]

Get the center offset for the Object image

Returns:

(x,y)

Return type:

tuple[float,float]

getProperties()[source]

Get the object properties.

Returns:

The properties dictionary.

Return type:

dict[str,str]

property image: Image

Full Object image, with both the background and foreground.

Returns:

PIL Image

Return type:

PIL.Image.Image

property offset: tuple[float, float]

The center offset of the Object image

Returns:

(x,y)

Return type:

tuple[float,float]

readXML()[source]

Read object XML

rotateImage(image: Image) Image[source]

Rotate an image the amount of degrees as the Object Angle property

Parameters:

image (PIL.Image.Image) – Image to rotate

Returns:

Rotated PIL Image

Return type:

PIL.Image.Image

rotatePoint(point: tuple = (0, 0), angle: float | None = None) tuple[float, float][source]

Rotate a point around (0,0)

Parameters:
  • point (tuple, optional) – Point to rotate. Defaults to (0,0).

  • angle (float, optional) – Angle to rotate. Defaults to Object Angle property.

Returns:

(x,y)

Return type:

tuple[float,float]

saveGIF(filename=None, duration: int = 0, fps: float = 0)[source]

Save object as a gif.

Parameters:
  • filename (str, optional) – The filename to save this object gif as. Defaults to None.

  • duration (int, optional) – The duration of the gif in seconds. If it’s 0, it automatically finds a perfect loop. Defaults to 0.

  • fps (float, optional) – The frames per second of the animation. If it’s 0, it is automatically calculated. Defaults to 0.

Returns:

The resulting PIL Image object.

Return type:

PIL.Image.Image

property scale: int

Object image scale

setProperty(property: str | dict, value: str = '')[source]

Set object property.

Parameters:
  • property (str | dict) – Property name to set. If value is dict, it will combine the properties in the dict with the current properties.

  • value (str, optional) – Property value. Defaults to ‘’.

property type: str | None

The Object type, based off the Type property.

updateProperties()[source]

Update properties. Deletes any properties that are the same as defaultProperties, unless specified by the object type in the ObjectPack.

class wmwpy.classes.Sprite(file: str | bytes | File | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', properties: dict = {}, scale: float = 50, HD: bool = False, TabHD: bool = False)[source]

Bases: GameObject

wmwpy Sprite.

HD

Using HD images.

Type:

bool

TabHD

Using TabHD images.

Type:

bool

properties

Sprite properties.

Type:

dict[str,str]

animations

List of animations.

Type:

list[Sprite.Animation]

scale

The image scale.

Type:

float

class Animation(xml: str | ElementBase | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', HD: bool = False, TabHD: bool = False)[source]

Bases: GameObject

Animation object for wmwpy Sprite.

HD

Using HD images.

Type:

bool

TabHD

Using TabHD images.

Type:

bool

properties

The animation properties.

Type:

dict[str,str]

frames

List of frames.

Type:

list[Sprite.Animation.Frame]

frame

The current animation frame.

Type:

int

class Frame(properties: dict = {}, atlas: Imagelist | None = None, textureBasePath: str | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/')[source]

Bases: GameObject

The Frame for Animations.

atlas

The atlas for this Frame.

Type:

Imagelist

textureBasePath

The textureBasePath for this Frame.

Type:

str

properties

The frame properties.

Type:

dict[str,str]

property SAFE_MODE: bool

A “safe mode” where you can modify the properties without them being added to the output xml.

Returns:

The current state.

Return type:

bool

property angleDeg: float

The frame rotation angle.

Returns:

Angle in degrees.

Return type:

float

getImage()[source]

Get the image. The image is stored in Frame._image.

getXML() ElementBase[source]

Get the XML for the Frame

Returns:

XML of this Frame

Return type:

etree.Element

property image: Image

Image of this Image

Returns:

PIL Image

Return type:

PIL.Image.Image

property name: str

The name of this frame.

Returns:

The name of this frame.

Return type:

str

property offset: tuple[float, float]

The frame offset.

Returns:

(x,y)

Return type:

tuple[float,float]

property repeat: int

The amount of times to repeat this frame in the animation.

Returns:

The amount of times to repeat.

Return type:

int

property scale: tuple[float, float]

The frame scale.

Returns:

(x,y)

Return type:

tuple[float, float]

show(*args, **kwargs)[source]

Calls the PIL.Image.Image.show() method.

Description copied from the PIL library

Displays this image. This method is mainly intended for debugging purposes.

This method calls PIL.ImageShow.show internally. You can use PIL.ImageShow.register to override its default behavior.

The image is first saved to a temporary file. By default, it will be in PNG format.

On Unix, the image is then opened using the display, eog or xv utility, depending on which one can be found.

On macOS, the image is opened with the native Preview application.

On Windows, the image is opened with the standard PNG display utility.

param title:

Optional title to use for the image window, where possible.. Defaults to None.

type title:

str | None, optional

property texture: Texture

The frame Texture instead of atlas.

Returns:

The Texture object.

Return type:

Texture

updateProperties()[source]

Update Image properties

property PhotoImage: PhotoImage

Tkinter PhotoImage for the Animation

property SAFE_MODE: bool

A “safe mode” where you can modify the properties without them being added to the output xml.

Returns:

The current state.

Return type:

bool

TEMPLATE = '<Animation>\n</Animation>\n'
property atlas: Imagelist
property atlasPath: str

The path to the atlas.

Returns:

The path to the atlas file.

Return type:

str

property fps: float

The Animation fps.

Returns:

The Animation fps.

Return type:

float

property frame: int

Current animation frame.

Returns:

Current animation frame index.

Return type:

int

frames: list[wmwpy.classes.sprite.Sprite.Animation.Frame]
getAnimation(duration: int = 0, fps: float = 0) dict[Literal['fps', 'frame_duration', 'frames'], float | int | list[PIL.Image.Image]][source]

Get the animation of this object

Parameters:
  • duration (int, optional) – Duration of animation in seconds. If 0, it will try to create a perfect loop. Defaults to 0.

  • fps (float, optional) – The fps of the animation. If 0, it will try to detect the fps that works for all the sprites. Defaults to 0.

Raises:

TypeError – ‘fps must be an int or float’

getAttributes()[source]

Get all the attributes of this Animation

getFrames() list['Sprite.Animation.Frame'][source]

Get a list of all the Animation ``Frame``s

Returns:

List of all the Frames in this Animation.

Return type:

list[Sprite.Animation.Frame]

getXML()[source]

Get the XML of this Animation

Returns:

etree Element

Return type:

etree.Element

property image: Image

Current Animation image

Returns:

PIL Image

Return type:

PIL.Image.Image

property loopCount: int

The loopCount for this Animation.

Returns:

The loopCount.

Return type:

int

property name: str

Name of this animation.

Returns:

The name of this animation.

Return type:

str

property playbackMode: str

The playback mode.

Returns:

The current playback mode.

Return type:

str

readXML()[source]

Read the xml for this Animation

saveGIF(filename=None, duration: int = 0, fps: float = 0) Image[source]

Save animation as a gif.

Parameters:
  • filename (str, optional) – The filename to save this animation gif as. Defaults to None.

  • duration (int, optional) – The duration of the gif in seconds. If it’s 0, it automatically finds a perfect loop. Defaults to 0.

  • fps (float, optional) – The frames per second of the animation. If it’s 0, it is automatically calculated. Defaults to 0.

Returns:

The resulting PIL Image object.

Return type:

PIL.Image.Image

property texture: Texture

The texture for this animation. Sometimes used instead of an atlas.

Returns:

The Texture.

Return type:

Texture

property textureBasePath: str

The textureBasePath where all textures are stored.

Returns:

textureBasePath.

Return type:

str

updateProperties()[source]

Update the Sprite properties

xml: ElementBase
property SAFE_MODE: bool

A “safe mode” where you can modify the properties without them being added to the output xml.

Returns:

The current state.

Return type:

bool

TEMPLATE = b'<?xml version="1.0"?>\n<Sprite>\n</Sprite>\n'
property angle: float

Sprite rotation angle

Returns:

Angle as degrees

Return type:

float

property animation: Animation

Returns the current animation

Returns:

A Sprite.Animation class

Return type:

Sprite.Animation

animations: list[wmwpy.classes.sprite.Sprite.Animation]
export(path: str | None = None) bytes[source]

Export the Sprite XML file

Parameters:

path (str, optional) – Path to export into the filesystem. Defaults to the original filename.

Raises:

TypeError – Path is not a file.

Returns:

Contents of saved file.

Return type:

bytes

property filename: str

Sprite filename

property fps: float
property frame: int

The current animation frame.

Returns:

Current animation frame index.

Return type:

int

property frames: list['Sprite.Animation.Frame']

Returns the current animation frames.

Returns:

A list of frames.

Return type:

list[Sprite.Animation.Frame]

getAnimation(duration: int = 0, fps: float = 0) dict[Literal['fps', 'frame_duration', 'frames'], float | int | list[PIL.Image.Image]][source]

Get the animation of this object

Parameters:
  • duration (int, optional) – Duration of animation in seconds. If 0, it will try to create a perfect loop. Defaults to 0.

  • fps (float, optional) – The fps of the animation. If 0, it will try to detect the fps that works for all the sprites. Defaults to 0.

Raises:

TypeError – ‘fps must be an int or float’

property gridSize: tuple[float, float]

The gridSize (size) of this Sprite

Returns:

(width,height)

Return type:

tuple[float,float]

property image: Image

Image of sprite

Returns:

PIL Image

Return type:

PIL.Image.Image

property isBackground

Whether this Sprite is a background

property pos: tuple[float, float]

Position of Sprite relative to the center of the Object

Returns:

(x,y)

Return type:

tuple[float,float]

readXML()[source]

Read Sprite XML

saveGIF(filename: str | None = None, duration: int = 0, fps: float = 0)[source]

Save current animation as a gif.

Parameters:
  • filename (str, optional) – The filename to save this animation gif as. Defaults to None.

  • duration (int, optional) – The duration of the gif in seconds. If it’s 0, it automatically finds a perfect loop. Defaults to 0.

  • fps (float, optional) – The frames per second of the animation. If it’s 0, it is automatically calculated. Defaults to 0.

Returns:

The resulting PIL Image object.

Return type:

PIL.Image.Image

setAnimation(animation: str | int)[source]

Set the current animation for the Sprite

Parameters:

animation (str | int) – Animation name or index.

property visible: bool

Whether this Sprite is visible or not

xml: ElementBase
class wmwpy.classes.TextureSettings(file: str | bytes | File | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/')[source]

Bases: GameObject

class Setting(xml: ElementBase | None = None, name: str = '', properties: dict[str, str] = {})[source]

Bases: object

property colorspace: str
getXML()[source]
property name: str
property premultiplyAlpha: bool
readXML()[source]
property wrapU: str
property wrapV: str
add(name: str, properties: dict[str, str] | 'TextureSettings.Setting' = {})[source]
get(name: str) Setting[source]
read()[source]
class wmwpy.classes.Widget(xml: ElementBase | None = None, filesystem: Filesystem | Folder | None = None, gamepath: str | None = None, assets: str = '/assets', baseassets: str = '/', screenSize: tuple = (900, 720))[source]

Bases: GameObject

getValues()[source]
setForceAspect(aspect=(1, 1))[source]
property type