Skip to main content

MetatileDef

Struct MetatileDef 

Source
pub struct MetatileDef {
    pub size: (u8, u8),
    pub tiles: Vec<MetatileCell>,
    pub collision: Vec<CollisionCell>,
    pub trigger: Option<TriggerDef>,
    pub animation_group: Option<u8>,
    pub z_offset: i8,
}
Expand description

A metatile — a logical unit comprised of N×N tiles.

This is the JRPG engine generalization of Game Boy’s “block” concept (4×4 tiles = 16 bytes). Variable-size support enables use with other tile-based games (2×2, 3×3, …).

Fields§

§size: (u8, u8)

Width and height in tiles, e.g. (4, 4) for GB blocks.

§tiles: Vec<MetatileCell>

The tiles that make up this metatile, stored in row-major order. Must contain exactly size.0 * size.1 entries.

§collision: Vec<CollisionCell>

Per-cell collision, same dimensions as size. If collision.len() differs from tile_count(), the engine should treat the whole metatile uniformly (e.g. all cells inherit the first collision entry).

§trigger: Option<TriggerDef>

Optional trigger script that fires when the player interacts with or steps on this metatile.

§animation_group: Option<u8>

Optional animation group index — tiles inside the metatile animate in lockstep if they share the same group.

§z_offset: i8

Vertical render offset (pixels). Positive values render the metatile lower on screen, useful for layered maps or floating platforms. Default is 0.

Implementations§

Source§

impl MetatileDef

Source

pub fn new(size: (u8, u8)) -> Self

Creates an empty metatile of the given size.

All tiles default to tile ID 0 with no flips; all collision cells are Passable. trigger, animation_group and z_offset are initialised to their defaults.

§Panics

Panics if either dimension is 0.

Source

pub fn tile_count(&self) -> usize

Returns the total number of tiles in this metatile (size.0 * size.1).

Source

pub fn from_gb_block(block_data: &[u8]) -> Self

Converts a 16-byte Game Boy .bst block into a 4×4 MetatileDef.

Each byte in block_data is a raw tile ID. Entries are placed in row-major order (top-left to bottom-right). All collision cells default to Passable.

§Panics

Panics if block_data does not contain exactly 16 bytes.

Trait Implementations§

Source§

impl Clone for MetatileDef

Source§

fn clone(&self) -> MetatileDef

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MetatileDef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.