pub struct Tile {
pub colour: HexColour,
pub name: String,
/* private fields */
}Expand description
A tile contains some number of track segments and cities.
Fields§
§colour: HexColour§name: StringImplementations§
Source§impl Tile
impl Tile
Sourcepub fn new<S: Into<String>>(
colour: HexColour,
name: S,
tracks: Vec<Track>,
cities: Vec<City>,
hex: &Hex,
) -> Self
pub fn new<S: Into<String>>( colour: HexColour, name: S, tracks: Vec<Track>, cities: Vec<City>, hex: &Hex, ) -> Self
Creates a new tile and determines the connectivity between track segments, revenue centres, and hex faces.
Note that hex should be the default hexagon,
to ensure that track connectivity is valid and consistent.
By making this an argument, a single Hex can be used to construct
all required tiles, rather than creating a new Hex for each tile.
Examples found in repository?
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}Sourcepub fn with_offboard_faces<T>(self, faces: T) -> Selfwhere
T: IntoIterator<Item = HexFace>,
pub fn with_offboard_faces<T>(self, faces: T) -> Selfwhere
T: IntoIterator<Item = HexFace>,
Identifies the tile as an off-board tile that has faces adjacent to
on-board tiles.
Examples found in repository?
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}Sourcepub fn offboard_faces(&self) -> Option<Vec<HexFace>>
pub fn offboard_faces(&self) -> Option<Vec<HexFace>>
Returns the edges adjacent to on-board tiles, if this tile is an
off-board tile, otherwise returns None.
Sourcepub fn hide_tile_name(self) -> Self
pub fn hide_tile_name(self) -> Self
Do not display the tile name when drawing the tile.
Examples found in repository?
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}Sourcepub fn is_tile_name_visible(&self) -> bool
pub fn is_tile_name_visible(&self) -> bool
Returns whether the tile name is displayed when drawing the tile.
pub fn connections(&self, from: &Connection) -> Option<&[Connection]>
Sourcepub fn all_connections_from<T>(&self, start: T) -> BTreeSet<Connection>where
T: Into<Connection>,
pub fn all_connections_from<T>(&self, start: T) -> BTreeSet<Connection>where
T: Into<Connection>,
Returns all connections that can be reached from start.
Sourcepub fn connected_faces<T>(&self, start: T) -> BTreeSet<HexFace>where
T: Into<Connection>,
pub fn connected_faces<T>(&self, start: T) -> BTreeSet<HexFace>where
T: Into<Connection>,
Returns the hexagon faces that are connected to start.
Sourcepub fn connected_dits<T>(&self, start: T) -> BTreeSet<usize>where
T: Into<Connection>,
pub fn connected_dits<T>(&self, start: T) -> BTreeSet<usize>where
T: Into<Connection>,
Returns the index of each dit that is connected to start.
Sourcepub fn connected_cities<T>(&self, start: T) -> BTreeSet<usize>where
T: Into<Connection>,
pub fn connected_cities<T>(&self, start: T) -> BTreeSet<usize>where
T: Into<Connection>,
Returns the index of each city that is connected to start.
Sourcepub fn connected_faces_are<T>(&self, start: T, dests: &[HexFace]) -> boolwhere
T: Into<Connection>,
pub fn connected_faces_are<T>(&self, start: T, dests: &[HexFace]) -> boolwhere
T: Into<Connection>,
Returns true if start is connected to each hexagon face in dests,
and is not connected to any hexagon face not included in dests.
Sourcepub fn no_connected_faces<T>(&self, start: T) -> boolwhere
T: Into<Connection>,
pub fn no_connected_faces<T>(&self, start: T) -> boolwhere
T: Into<Connection>,
Returns true if start is not connected to any other hexagon face.
Sourcepub fn connected_dits_are<T>(
&self,
start: T,
dits: &[usize],
) -> Option<Vec<usize>>where
T: Into<Connection>,
pub fn connected_dits_are<T>(
&self,
start: T,
dits: &[usize],
) -> Option<Vec<usize>>where
T: Into<Connection>,
Returns the index of each dit connected to start, if start is only
connected to each dit in dits (identified by their revenue).
Otherwise, returns None.
Sourcepub fn connected_cities_are<T>(
&self,
start: T,
cities: &[(usize, usize)],
) -> Option<Vec<usize>>where
T: Into<Connection>,
pub fn connected_cities_are<T>(
&self,
start: T,
cities: &[(usize, usize)],
) -> Option<Vec<usize>>where
T: Into<Connection>,
Returns the index of each city connected to start, if start is
only connected to each city in cities (identified by their revenue
and number of token spaces, respectively).
Otherwise, returns None.
Sourcepub fn label<P>(self, label: Label, pos: P) -> Selfwhere
P: Into<HexPosition>,
pub fn label<P>(self, label: Label, pos: P) -> Selfwhere
P: Into<HexPosition>,
Examples found in repository?
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}pub fn tracks(&self) -> &[Track]
pub fn dits(&self) -> &[Dit]
pub fn cities(&self) -> &[City]
pub fn labels(&self) -> &[LabelAndPos] ⓘ
Sourcepub fn city(&self, space: &TokenSpace) -> Option<&City>
pub fn city(&self, space: &TokenSpace) -> Option<&City>
Returns the city that corresponds to the provided token location.
pub fn revenues(&self) -> &[usize]
Sourcepub fn only_draw_offboard_track(&self) -> bool
pub fn only_draw_offboard_track(&self) -> bool
Returns true if this tile is an off-board tile for which special
off-board track segments should be drawn, instead of drawing the
regular track segments, dits, and cities.
Sourcepub fn define_offboard_track_inner_path(
&self,
ctx: &Context,
hex: &Hex,
face: &HexFace,
) -> bool
pub fn define_offboard_track_inner_path( &self, ctx: &Context, hex: &Hex, face: &HexFace, ) -> bool
Defines the inner (foreground) layer of the off-board track segment
for the specified tile face, if such a segment should be drawn on
this face, and returns true.
If no such segment should be drawn, this has no effect and returns
false.
Sourcepub fn draw_offboard_segment(
&self,
ctx: &Context,
hex: &Hex,
face: &HexFace,
) -> bool
pub fn draw_offboard_segment( &self, ctx: &Context, hex: &Hex, face: &HexFace, ) -> bool
Draws the off-board track segment for the specified tile face, if
such a segment should be drawn on this face, and returns true.
If no such segment should be drawn, this has no effect and returns
false.
pub fn draw(&self, ctx: &Context, hex: &Hex)
pub fn token_spaces(&self) -> Vec<TokenSpace>
pub fn city_token_spaces(&self, city_ix: usize) -> Vec<TokenSpace>
pub fn token_space_count(&self) -> usize
pub fn dit_count(&self) -> usize
pub fn define_token_space( &self, space: &TokenSpace, hex: &Hex, ctx: &Context, ) -> bool
Sourcepub fn can_upgrade_to(&self, other: &Tile) -> bool
pub fn can_upgrade_to(&self, other: &Tile) -> bool
Check whether a tile can be upgraded to another tile.
Sourcepub fn save_png<P: AsRef<Path>>(
&self,
hex: &Hex,
path: P,
) -> Result<(), Box<dyn Error>>
pub fn save_png<P: AsRef<Path>>( &self, hex: &Hex, path: P, ) -> Result<(), Box<dyn Error>>
Saves the tile to a PNG file.
Examples found in repository?
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}Sourcepub fn save_svg<P: AsRef<Path>>(
&self,
hex: &Hex,
path: P,
) -> Result<(), Box<dyn Error>>
pub fn save_svg<P: AsRef<Path>>( &self, hex: &Hex, path: P, ) -> Result<(), Box<dyn Error>>
Saves the tile to an SVG file.
Sourcepub fn save_pdf<P: AsRef<Path>>(
&self,
hex: &Hex,
path: P,
) -> Result<(), Box<dyn Error>>
pub fn save_pdf<P: AsRef<Path>>( &self, hex: &Hex, path: P, ) -> Result<(), Box<dyn Error>>
Saves the tile to a PDF file.
Sourcepub fn write_png<W: Write>(
&self,
hex: &Hex,
stream: &mut W,
) -> Result<(), Box<dyn Error>>
pub fn write_png<W: Write>( &self, hex: &Hex, stream: &mut W, ) -> Result<(), Box<dyn Error>>
Writes the tile as a PNG image to the provided stream.