#tile #tilemap #shape #generator

ute

ute - (U)biquitous (T)ile (E)ngine - 用于匹配和操作带标签边的 n 边多边形的库(在 Rust 中)

1 个不稳定版本

0.0.2 2021 年 6 月 17 日

#19#tilemap

Apache-2.0

11KB
55

UTE ( yoot )

ute - 用于匹配和操作带标签边的 n 边多边形的引擎(在 Rust 中)

导航

[你在这里]

本页提供了简要的使用概述。有关详细示例和常见问题解答,请阅读 wiki

使用 ute

示例

功能 参考

使用 ute

包含到项目中

[顶部]

  • 将此仓库*添加到您的 Cargo.toml
[dependencies]

# ... other deps are probably here ...

ute = {git = "https://github.com/parkcitymedia/ute", branch="main"}

*cargo 默认搜索 "master" 分支,因此可能不需要指定分支。

示例

使用手工或生成的瓦片

假设瓦片路径 "tile.json" 已创建/存在

  • 将 map json 转换为瓦片(serde)

[顶部]

// likely your main.rs:
use ute::{Tile, identify_tile};
use serde_json::{from_str};
use std::fs::read_to_string;

#[tokio::main] // requires tokio = {features = ["full"]}
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    
    // where does the tile live?
    let raw_tile_path: &str = "tile.json";
    
    // read the tile info into a String (re-borrow
    // into &str for serde_json compatibility)
    let tile_r: String = read_to_string(raw_tile_path).unwrap();
    let tile_r: &str = &tile_r;

    // use serde_json::from_str() to
    // map the json string to a pantsemm::Tile
    // note: this tile is mutable - while they don't
    // need to be, this is good for when
    // you want to change tile field values later
    let mut tile: Tile = from_str(tile_r)?;
    
    // generate a unique tile-data-based tile name
    // with pantsemm's pantsemm::identify_tile()
    // (returns a Tile!!! common use: mutation)
    tile = identify_tile(&mut tile)?;

    // print the tile_id out after generating it!
    println!("my new tile id: {:#?}", tile.tile_id);

    Ok(())
}

单个瓦片输入

[顶部]

tiles/tile_example.json中可以找到一个手写/生成的六边形的示例数据输入。以下是一个现在可以查看的四边形/正方形的示例:quad_example.json

{
    "tile_id": "",
    "tile_center": "5",
    "tile_edges": [
        {
            "tile_edge": {
                "is_open": true,
                "name": "top_edge",
                "edge_tag": [
                    {
                        "tag_position": "0",
                        "tag_value": "r"
                    },
                    {
                        "tag_position": "1",
                        "tag_value": "q"
                    },
                    {
                        "tag_position": "2",
                        "tag_value": "p"
                    }
                ]
            }
        },
        {
            "tile_edge": {
                "is_open": true,
                "name": "right_edge",
                "edge_tag": [
                    {
                        "tag_position": "0",
                        "tag_value": "o"
                    },
                    {
                        "tag_position": "1",
                        "tag_value": "n"
                    },
                    {
                        "tag_position": "2",
                        "tag_value": "m"
                    }
                ]
            }
        },
        {
            "tile_edge": {
                "is_open": true,
                "name": "bottom_edge",
                "edge_tag": [
                    {
                        "tag_position": "0",
                        "tag_value": "l"
                    },
                    {
                        "tag_position": "1",
                        "tag_value": "k"
                    },
                    {
                        "tag_position": "2",
                        "tag_value": "j"
                    }
                ]
            }
        },
        {
            "tile_edge": {
                "is_open": true,
                "name": "left_edge",
                "edge_tag": [
                    {
                        "tag_position": "0",
                        "tag_value": "c"
                    },
                    {
                        "tag_position": "1",
                        "tag_value": "b"
                    },
                    {
                        "tag_position": "2",
                        "tag_value": "a"
                    }
                ]
            }
        }
    ]
}

功能

[顶部]

参考

[顶部]

依赖项

~0.4–1MB
~22K SLoC