Skip to content

Sprite Utils

Popax21 edited this page Feb 8, 2023 · 4 revisions

SpriteAnimationDataProcessor

An IAsyncDataProcessor<Sprite, string, Sprite.Animation> which wraps an IAsyncDataProcessor<Sprite, string, SpriteAnimationData>. It gets an animation's original data, and creates a new animation using the processed data (if modified) in a texture scope through a callback. This can be used if one wishes to process animation frames as TextureData instances instead of raw MTextures.

SpriteColorMatrixProcessor

An IDataProcessor<Sprite, string, SpriteAnimationData> which applies a color matrix to all pixels of the animation. Can be used in combination with recolor matrices (which can be calculated using ColorUtils) to easily recolor a sprite.

SpriteOverlayProcessor

An IAsyncDataProcessor<Sprite, string, SpriteAnimationData> which either overlays a single texture, or another animation over all frames of the animation.

SpriteMultiplexer

An IDataProcessor<Sprite, string, Sprite.Animation> which uses a DataScopeMultiplexer<Sprite> to select which sprite's animations should be utilized. Can be used to switch between different sprites at runtime.

SpriteUtils

Contains various miscellaneous helper methods which can be used to access and modify sprites.

ProxySprite

A trivial CustomSprite which proxies another sprite. This is the default class which is instantiated by CustomSprite.CreateCopy. Code which wants to correctly detect and handle proxy sprites should check if the sprite (animation) implements IProxySprite(Animation).

InvalidatableSprite

An abstract subclass of CustomSprite which contains some common helper code used to correctly deal with custom sprites whose validity is tied to a scope key.

Animations of these sprites can then invoke the InvalidatableSprite.Animation.CheckValidity method to check if the animation's data is still valid, and obtain a so called validity token if it isn't. This token can then be traded back using the .MarkValid method to mark the animation, and the caller is notified if the animation was successfully marked as valid. This mechanism is required to correctly deal with another invalidation which might occur while the sprite is already processing its data, which otherwise might cause race conditions where the animation is considered valid even though it shouldn't be.

This is the base class of both DerivedSprite and MixerSprite.

DerivedSprite

A custom sprite which applies an IAsyncDataProcessor<Sprite, string, SpriteAnimationData> to an original sprite to derive its own animations. Useful for e.g. recoloring vanilla sprites.

MixerSprite

A custom sprite which applies an IAsyncDataProcessor<Sprite, string, Sprite.Animation> to obtain the animations it should use. This can be used to e.g. "mix" different sprite's animations, or in combination with an SpriteMultiplexer switch between the used sprite at runtime.