Skip to main content

MapScene

Struct MapScene 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§origin: Pos

The 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: MapEdges

The 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: MapLook

How 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: u64

The 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>

Source

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.

Source

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.

Source

pub fn contains(&self, pos: Pos) -> bool

Whether pos is a visible tile.

Source

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.

Source

pub fn tile(&self, pos: Pos) -> Option<&TileView>

The tile at map position pos, if visible.

Source

pub fn tile_mut(&mut self, pos: Pos) -> Option<&mut TileView>

Mutable tile.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn tinted(&self, kind: impl Into<RangeName>) -> Vec<Pos>

The visible tiles in the range kind, row by row, each once.

Source

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.

Source

pub fn terrain_at(&self, pos: Pos) -> Option<TerrainId>

The terrain shown on pos, if it is a visible map tile.

Source

pub fn cursor_tile(&self) -> Option<Pos>

The tile the cursor is on, if it is shown.

Source§

impl<U: MapUnit> MapScene<U>

Source

pub fn push_unit(&mut self, unit: U)

Adds unit if it is on a visible tile.

Source

pub fn unit(&self, id: U::Id) -> Option<&U>

The unit id, if it is shown.

Source

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).

Source

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.

Trait Implementations§

Source§

impl<U: Clone> Clone for MapScene<U>

Source§

fn clone(&self) -> MapScene<U>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<U: Debug> Debug for MapScene<U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<U: PartialEq> PartialEq for MapScene<U>

Source§

fn eq(&self, other: &MapScene<U>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<U: PartialEq> StructuralPartialEq for MapScene<U>

Auto Trait Implementations§

§

impl<U> Freeze for MapScene<U>

§

impl<U> RefUnwindSafe for MapScene<U>
where U: RefUnwindSafe,

§

impl<U> Send for MapScene<U>
where U: Send,

§

impl<U> Sync for MapScene<U>
where U: Sync,

§

impl<U> Unpin for MapScene<U>
where U: Unpin,

§

impl<U> UnsafeUnpin for MapScene<U>

§

impl<U> UnwindSafe for MapScene<U>
where U: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.