Map

Struct Map 

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

A Wolf RPG Editor map (.mps) file.

Contains all information needed for rendering a level, from the single tiles to the events set to happen.

§Examples

use wolfrpg_map_parser::Map;
use std::fs;

match fs::read("filepath.mps") {
    Ok(bytes) => {
        let map: Map = Map::parse(&bytes);
        // Data manipulation ...
    }
    Err(_) => {
        // Error handling ...
    }
}

Implementations§

Source§

impl Map

Source

pub fn parse(bytes: &[u8]) -> Self

Parse raw bytes into a Map struct.

This is the main driver that should be used when loading a .mps file. Using other methods is highly discouraged, unless you know what you are doing and need that extra bit of speed.

§Panics

This function will panic if the given bytes do not represent a valid map structure.

This might be caused by corrupt files, incompatible format updates and library bugs. In each of these cases, feel free to report an issue on GitHub.

§Examples
use wolfrpg_map_parser::Map;
use std::fs;

match fs::read("filepath.mps") {
    Ok(bytes) => {
        let map: Map = Map::parse(&bytes);
        // Data manipulation ...
    }
    Err(_) => {
        // Error handling ...
    }
}
Source

pub fn tileset(&self) -> u32

The ID of the set of pictures used for each tile.

Source

pub fn tileset_mut(&mut self) -> &mut u32

Mutable reference accessor for Map::tileset.

Source

pub fn width(&self) -> u32

The width of the map, in tiles.

Source

pub fn width_mut(&mut self) -> &mut u32

Mutable reference accessor for Map::width.

Source

pub fn height(&self) -> u32

The height of the map, in tiles.

Source

pub fn height_mut(&mut self) -> &mut u32

Mutable reference accessor for Map::height.

Source

pub fn layer1(&self) -> &Vec<u32>

The bottom-most layer of tiles.

Each layer is painted above the lower ones.

Source

pub fn layer1_mut(&mut self) -> &mut Vec<u32>

Mutable reference accessor for Map::layer1.

Source

pub fn layer2(&self) -> &Vec<u32>

The middle layer of tiles.

Each layer is painted above the lower ones.

Source

pub fn layer2_mut(&mut self) -> &mut Vec<u32>

Mutable reference accessor for Map::layer2.

Source

pub fn layer3(&self) -> &Vec<u32>

The top-most layer of tiles.

Each layer is painted above the lower ones.

Source

pub fn layer3_mut(&mut self) -> &mut Vec<u32>

Mutable reference accessor for Map::layer3.

Source

pub fn events(&self) -> &Vec<Event>

A collection of all the events set on this map.

Events are painted above each other based on the following priority:

  1. If Page::options::above_hero is true, then the event has the highest priority.
  2. If Page::options::above_hero is false and Page::options::slip_through is false, then the event has the second-highest priority.
  3. if Page::options::above_hero is false and Page::options::slip_through is true, then the event has the lowest-priority.

When events have the same priority, they are displayed in order of Event::id.

Source

pub fn events_mut(&mut self) -> &mut Vec<Event>

Mutable reference accessor for Map::events.

Trait Implementations§

Source§

impl Clone for Map

Source§

fn clone(&self) -> Map

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl PartialEq for Map

Source§

fn eq(&self, other: &Map) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Map

Auto Trait Implementations§

§

impl Freeze for Map

§

impl RefUnwindSafe for Map

§

impl Send for Map

§

impl Sync for Map

§

impl Unpin for Map

§

impl UnwindSafe for Map

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.