custom_tile/
custom_tile.rs

1/// Draws a custom tile that contains a vertical phase revenue label.
2use n18hex::{Delta, Direction, Hex, HexColour::*, HexFace::*, HexPosition};
3use n18tile::{Label, Tile, Track};
4
5#[test]
6fn custom_tile() {
7    // NOTE: when run as a test, the working directory is the n18tile root,
8    // not the workspace root.
9    let output_dir = "../../examples/output";
10    draw_custom_tile(output_dir)
11}
12
13fn main() {
14    let output_dir = "./examples/output";
15    draw_custom_tile(output_dir)
16}
17
18fn draw_custom_tile(output_dir: &str) {
19    let output_file = "n18tile_custom_tile_1.png";
20    let output_path = std::path::Path::new(output_dir).join(output_file);
21    let hex = Hex::default();
22    let tile = Tile::new(
23        Red,
24        "Custom1",
25        vec![Track::straight(UpperRight), Track::gentle_l(LowerLeft)],
26        vec![],
27        &hex,
28    )
29    .with_offboard_faces([UpperRight, LowerRight])
30    .label(Label::MapLocation("Custom".to_string()), Top.to_centre(0.1))
31    .label(
32        Label::PhaseRevenueVert(vec![
33            (Yellow, 10, false),
34            (Green, 20, true),
35            (Brown, 30, false),
36            (Grey, 40, false),
37        ]),
38        HexPosition::Centre(Some(Delta::InDir(Direction::W, 0.35))),
39    )
40    .hide_tile_name();
41    println!("Writing {} ...", output_path.display());
42    tile.save_png(&hex, output_path).unwrap();
43}