FrenchCurve.Sprite.Registry (FrenchCurve v0.1.3)

Copy Markdown View Source

Remembers which sprite ids have been uploaded, so a render loop uploads each one once.

A plain immutable value, not a process: thread it through your render state and replace it with the one ensure/3 hands back.

{registry, bytes} = FrenchCurve.Sprite.Registry.ensure(registry, sprite, :kitty)
IO.write(bytes <> FrenchCurve.Sprite.place(sprite, :kitty))

The registry tracks ids, not terminals. Start a fresh one whenever the terminal's image store is emptied, or it will assume uploads that no longer exist.

Summary

Functions

Returns {registry, bytes}, uploading sprite if this registry has not seen its id.

Returns an empty registry.

Types

t()

@type t() :: %FrenchCurve.Sprite.Registry{uploaded: MapSet.t(pos_integer())}

Functions

ensure(registry, sprite, protocol)

@spec ensure(t(), FrenchCurve.Sprite.t(), atom()) :: {t(), binary()}

Returns {registry, bytes}, uploading sprite if this registry has not seen its id.

bytes is the upload sequence the first time a given id is passed under :kitty, and "" on every later call and for every other protocol. The returned registry records the id and must be used in place of the one passed in.

new()

@spec new() :: t()

Returns an empty registry.