[][src]Struct wfc_tiled::TilePattern

pub struct TilePattern {
    pub grid: Grid<u32>,
    pub overlapping_patterns: OverlappingPatterns<u32>,
}

Extracts a pattern from a tilemap and lets you run Wave Function Collapse on it.

This struct can be initialized from a .csv file, a vector, or a Grid.

It will automatically extract overapping patterns of the given size (in tiles), and respecting the orientation setting.

For example, if you don't want to allow your tiles to be rotated, use Orientation::Original

Afterwards call run_collapse() in order to generate a new tilemap based on the input.

WFC is not guaranteed to succeed, even with the correct input. For this reason there is a retry_times parameter indicating the number of attemps that will be done. If it still fails, the function will return an error.

Examples

let input_path = "example\\input.csv";
let tilesheet_path = "example\\tset.png";
let attempts = 1000;
let pattern_size = 2;
let output_size = Size::new(32, 32);
// Extract patterns from input
let pattern = TilePattern::from_csv(input_path, 
    std::num::NonZeroU32::new(pattern_size).unwrap(), 
    &[Orientation::Original])
    .expect("Error while creating pattern");
// Run Wave Function Collapse
let grid = pattern.run_collapse(output_size, 
    attempts, 
    WrapXY, 
    ForbidNothing, 
    &mut rand::thread_rng())
    .expect("Error in WFC");
// Save as CSV
grid_to_csv(&grid, "out.csv")?;
// Save as Tiled .tmx file
let tset = TileSet {
    image_path: tilesheet_path,
    image_size: Size::new(256, 1450),
    columns: 8,
    tile_count: 360,
    tile_size: Size::new(32, 32)
};
grid_to_tiled(&grid, "out.tmx", tset)?;

Fields

grid: Grid<u32>overlapping_patterns: OverlappingPatterns<u32>

Methods

impl TilePattern[src]

pub fn new(
    grid: Grid<u32>,
    pattern_size: NonZeroU32,
    orientation: &[Orientation]
) -> TilePattern
[src]

pub fn from_vec(
    map: Vec<u32>,
    size: Size,
    pattern_size: NonZeroU32,
    orientation: &[Orientation]
) -> TilePattern
[src]

pub fn from_csv<P: AsRef<Path>>(
    path: P,
    pattern_size: NonZeroU32,
    orientation: &[Orientation]
) -> Result<TilePattern, Box<dyn Error>>
[src]

pub fn run_collapse<W: Wrap, F: ForbidPattern, R: Rng>(
    &self,
    output_size: Size,
    retry_times: usize,
    wrap: W,
    forbid: F,
    rng: &mut R
) -> Result<Grid<u32>, PropagateError>
[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> SetParameter for T