#[non_exhaustive]pub struct MapScene<U> {
pub origin: Pos,
pub size: (i32, i32),
pub more: MapEdges,
pub tiles: Vec<TileView>,
pub ranges: Vec<RangeLayer>,
pub rim: Vec<Option<TerrainId>>,
pub look: MapLook,
pub units: Vec<U>,
pub cursor: Option<CursorView>,
pub path: Vec<Pos>,
pub threat: Option<ThreatView>,
pub clock_ms: u64,
}Expand description
The visible part of a grid map, with units of the game’s kind U.
Build it with MapScene::new and assign the rest: a struct literal
doesn’t compile outside this crate, so a new field never breaks a game
(ADR-0039).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.origin: PosThe map tile at the view’s top-left (negative, or past the map, when the map is smaller than the view).
size: (i32, i32)Visible tiles, across × down.
more: MapEdgesThe sides of the view the map goes on past: for a game’s marks at
those edges. None unless set (MapEdges::of_view).
tiles: Vec<TileView>The visible tiles, row by row: size.0 × size.1 of them.
ranges: Vec<RangeLayer>The ranges shown, in the order laid on: on a tile in two, the second is laid over the first.
rim: Vec<Option<TerrainId>>The terrain of the ring of tiles just outside the view (the row
above it, then the two ends of each of its rows, then the row
below), for a skin whose picture of a tile depends on its
neighbours. None = off the map, or not given. Read it with
terrain_near.
look: MapLookHow the map looks, as far as its file says: which set of pictures a skin that has pictures paints its terrain with, and which light it shades them by (the light’s name: the skin says how it looks).
units: Vec<U>The units on visible tiles, in the game’s order.
cursor: Option<CursorView>The cursor, if it is shown and on a visible tile.
path: Vec<Pos>The selected unit’s path, its own tile first; empty = none. Its tiles may lie outside the view.
threat: Option<ThreatView>Those that could attack a tile, if the game shows them; None =
nothing to show.
clock_ms: u64The screen’s animation clock, in milliseconds: what a skin or a unit painter moves its marks by. It only ever goes forward.
Implementations§
Source§impl<U> MapScene<U>
impl<U> MapScene<U>
Sourcepub fn new(origin: Pos, size: (i32, i32)) -> Self
pub fn new(origin: Pos, size: (i32, i32)) -> Self
A view of size tiles from origin with nothing on it: every tile
off the map. A negative size counts as zero.
Sourcepub fn offset(&self, pos: Pos) -> Option<(i32, i32)>
pub fn offset(&self, pos: Pos) -> Option<(i32, i32)>
Where pos is in the view, as tiles right of and below
origin, or None if it isn’t visible.
Sourcepub fn tile_at(&self, dx: i32, dy: i32) -> Option<&TileView>
pub fn tile_at(&self, dx: i32, dy: i32) -> Option<&TileView>
The tile dx right of and dy below the origin, if in the view.
Sourcepub fn terrain_near(&self, dx: i32, dy: i32) -> Option<TerrainId>
pub fn terrain_near(&self, dx: i32, dy: i32) -> Option<TerrainId>
The terrain of the tile dx right of and dy below the origin: a
tile of the view, or of the ring just outside it. None off the
map, further out, or where the ring wasn’t given.
Sourcepub fn set_terrain(&mut self, terrain: impl Fn(Pos) -> Option<TerrainId>)
pub fn set_terrain(&mut self, terrain: impl Fn(Pos) -> Option<TerrainId>)
Sets the terrain of every tile of the view, and of the ring just
outside it, to what terrain gives for its map position.
Sourcepub fn tint(
&mut self,
tiles: impl IntoIterator<Item = Pos>,
kind: impl Into<RangeName>,
)
pub fn tint( &mut self, tiles: impl IntoIterator<Item = Pos>, kind: impl Into<RangeName>, )
Lays the range kind on each of tiles that is visible: a new
layer over those laid before, if any of them is.
Sourcepub fn tints(&self) -> Tints
pub fn tints(&self) -> Tints
The ranges every visible tile is in, in the order laid on (a tile listed twice in a layer is in it twice).
Sourcepub fn tinted(&self, kind: impl Into<RangeName>) -> Vec<Pos>
pub fn tinted(&self, kind: impl Into<RangeName>) -> Vec<Pos>
The visible tiles in the range kind, row by row, each once.
Sourcepub fn tints_at(&self, pos: Pos) -> Vec<RangeName>
pub fn tints_at(&self, pos: Pos) -> Vec<RangeName>
The ranges pos is in, in the order laid on; none if it isn’t
visible.
Sourcepub fn terrain_at(&self, pos: Pos) -> Option<TerrainId>
pub fn terrain_at(&self, pos: Pos) -> Option<TerrainId>
The terrain shown on pos, if it is a visible map tile.
Sourcepub fn cursor_tile(&self) -> Option<Pos>
pub fn cursor_tile(&self) -> Option<Pos>
The tile the cursor is on, if it is shown.
Source§impl<U: MapUnit> MapScene<U>
impl<U: MapUnit> MapScene<U>
Sourcepub fn unit_at(&self, pos: Pos) -> Option<&U>
pub fn unit_at(&self, pos: Pos) -> Option<&U>
The unit shown on pos, if any (the last one, drawn on top, if two
share it).
Sourcepub fn to_text(&self, terrains: &dyn Terrains) -> String
pub fn to_text(&self, terrains: &dyn Terrains) -> String
The scene as text, for tests and bug reports, with the terrains’
names from terrains. The same scene always gives the same text.
The clock isn’t in it (nothing happens by it), nor the ring of
terrain round the view (it is the map’s, one tile further out). A
look other than a map’s usual one ends the first line: look indoor; so does a light other than the usual: light dusk. The
sides the map goes on past follow it in a line of their own, only
when there are some: more right down.
origin (-10,-11) size 35x30
-11: -*35
0: -*10 water*2 grass+m*3 sand+mm grass! grass>water -*18
units 1
#4 (7,3)
cursor (3,5) corners 1.00
path (3,5) (4,5)One line per row of tiles, headed by its map row: terrain names
(- = off the map, ?n for an id the game lacks), + and a letter
per range on the tile in the order laid on (each range’s
mark), and *n for n such tiles in a row. !
marks a tile flashing after its terrain changed, and > is
followed by the terrain it would turn into. Each unit’s line is its
own (MapUnit::text). The cursor’s number is its brightness. A
last line, threat (5,3) from (6,3) (9,1), is there only when a
tile is threatened: the tile, then where each threat stands.