tiled_json_rs/wangs.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5use crate::{parsers::parse_color, Color};
6use serde::Deserialize;
7
8/// Data set for `Wang` tiles
9///
10/// Wang tiles are similar in concept to Terrains. They are, however, more
11/// focused on filling larger areas without repetition. One defines the edge
12/// and corner colors of tiles in a tileset. This information can then be used
13/// when filling, or brushing to allow for smooth, non-repetitive transitions
14/// between tiles. In most cases this tiling is random, and based on color
15/// probability.
16#[derive(Deserialize, Debug, PartialEq, Clone)]
17pub struct WangSet {
18 #[serde(rename(deserialize = "cornercolors"))]
19 pub corner_colors: Vec<WangColor>,
20 #[serde(rename(deserialize = "edgecolors"))]
21 pub edge_colors: Vec<WangColor>,
22 pub name: String,
23 /// Local ID of tile representing the Wang set
24 pub tile: u32,
25 #[serde(rename(deserialize = "wangtiles"))]
26 pub wang_tiles: Vec<WangTile>,
27}
28
29#[derive(Deserialize, Debug, PartialEq, Clone)]
30pub struct WangColor {
31 #[serde(deserialize_with = "parse_color")]
32 pub color: Color,
33 pub name: String,
34 /// Probability used when randomizing
35 pub probability: f32,
36 /// Local ID of tile representing the Wang color
37 pub tile: u32,
38}
39
40#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
41pub struct WangTile {
42 /// Tile is flipped diagonally
43 #[serde(rename(deserialize = "dflip"))]
44 pub d_flip: bool,
45 /// Tile is flipped horizontally
46 #[serde(rename(deserialize = "hflip"))]
47 pub h_flip: bool,
48 /// Tile is flipped vertically
49 #[serde(rename(deserialize = "vflip"))]
50 pub v_flip: bool,
51 /// Local ID of tile
52 #[serde(rename(deserialize = "tileid"))]
53 pub tile_id: u32,
54 /// Array of Wang color indexes
55 #[serde(rename(deserialize = "wangid"))]
56 pub wang_id: Vec<u8>,
57}