Skip to main content

TilesetBuilder

Struct TilesetBuilder 

Source
pub struct TilesetBuilder { /* private fields */ }
Expand description

Builder for TilesetOptions.

Construct via TilesetOptions::builder.

columns defaults to image_width / tile_width, so you usually don’t need to set it explicitly. codepage defaults to Codepage::Cp437.

§Examples

Standard CP437 tileset:

use retroglyph_window::tileset::TilesetOptions;

let png: Vec<u8> = std::fs::read("assets/cp437_16x16.png").unwrap();
let opts = TilesetOptions::builder(png)
    .tile_size(16, 16) // codepage defaults to Cp437
    .build()
    .unwrap();

Private-use sprite sheet addressed by index, centred in whatever box a span reserves:

use retroglyph_window::tileset::{Codepage, SpriteAlign, TilesetOptions};

let png: Vec<u8> = std::fs::read("assets/sprites.png").unwrap();
let opts = TilesetOptions::builder(png)
    .tile_size(32, 32)
    .codepage(Codepage::Identity)  // tile 0 = '\0', tile 1 = '\x01', …
    .align(SpriteAlign::Center)
    .build()
    .unwrap();

How many cells a sprite occupies is a per-write decision, not a tileset-wide one: declare it with Surface::put_span at the draw call.

Unicode private-use area sprite sheet:

use retroglyph_window::tileset::TilesetOptions;

let png: Vec<u8> = std::fs::read("assets/monsters.png").unwrap();
let opts = TilesetOptions::builder(png)
    .tile_size(16, 16)
    .start_codepoint('\u{E000}') // maps to Unicode PUA starting at U+E000
    .build()
    .unwrap();

Implementations§

Source§

impl TilesetBuilder

Source

pub const fn tile_size(self, width: u16, height: u16) -> Self

Sets the pixel dimensions of each tile.

Source

pub const fn columns(self, cols: u16) -> Self

Sets the number of tiles per row in the sprite sheet.

Useful for sheets with padding. If not set, derived from image width.

Source

pub fn codepage(self, codepage: Codepage) -> Self

Sets the codepoint mapping.

Source

pub fn start_codepoint(self, start: char) -> Self

Sets the codepoint of the first tile; subsequent tiles increment by 1.

Shorthand for codepage(Codepage::Unicode { start }).

Source

pub const fn align(self, align: SpriteAlign) -> Self

Sets where each sprite sits inside the multi-cell box a span reserves for it.

Defaults to SpriteAlign::TopLeft. Has no visible effect on a sprite whose art fills its box exactly; see SpriteAlign.

Source

pub const fn color(self, color: SheetColor) -> Self

Declares what this sheet’s pixels mean, and so whether the cell’s foreground color colors them.

Defaults to SheetColor::Art: composited verbatim. See SheetColor.

Source

pub const fn mask(self) -> Self

Shorthand for color(SheetColor::Mask): this sheet is white-on- transparent artwork to be colored by each cell’s foreground.

Source

pub const fn transparent_color(self, r: u8, g: u8, b: u8) -> Self

Pixels matching (r, g, b) are made fully transparent (alpha = 0).

Use this for spritesheets that use a solid colour background instead of an alpha channel.

Source

pub fn build(self) -> Result<TilesetOptions, TilesetError>

Validates and builds TilesetOptions.

§Errors

Returns TilesetError::ZeroTileSize if tile dimensions are 0, or TilesetError::EmptyCodepage if Custom codepage is empty.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,