37 lines
1.4 KiB
Rust
37 lines
1.4 KiB
Rust
use serde::{Deserialize, Serialize};
|
||
use crate::glyph::Glyph;
|
||
|
||
/// A portal that teleports the player to a named entry point on another board.
|
||
///
|
||
/// Portals are loaded from `[[portals]]` entries in `.toml` map files and
|
||
/// stored on [`Board`]. When the player steps onto a portal's cell, the engine
|
||
/// calls [`crate::game::GameState::enter_board`] with the `target_map` and
|
||
/// `target_entry`, placing the player at the matching named portal on the
|
||
/// destination board.
|
||
///
|
||
/// In map files, portals are conventionally placed using digit characters
|
||
/// (`'1'`–`'9'`) as palette keys — parallel to the uppercase-letter convention
|
||
/// for objects. A portal's `name` is board-unique: it is also used as the
|
||
/// `target_entry` value on the other end of the connection.
|
||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||
#[serde(rename_all = "lowercase")]
|
||
pub struct Portal {
|
||
pub x: usize,
|
||
pub y: usize,
|
||
/// Board-unique name for this portal, also used as `target_entry` by portals
|
||
/// on other boards that want to arrive here.
|
||
pub name: String,
|
||
/// Key of the target board in `World::boards`.
|
||
pub target_board: String,
|
||
/// Name of the arrival portal on the target board.
|
||
pub target_name: String,
|
||
#[serde(skip_serializing_if = "Option::is_none")]
|
||
pub glyph: Option<Glyph>
|
||
}
|
||
|
||
impl Portal {
|
||
pub fn location(&self) -> (usize, usize) {
|
||
(self.x, self.y)
|
||
}
|
||
}
|