Files
kiln/kiln-core/src/portal.rs
T

37 lines
1.4 KiB
Rust
Raw Normal View History

2026-07-24 21:52:05 -05:00
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")]
2026-07-25 12:48:11 -05:00
pub glyph: Option<Glyph>
2026-07-24 21:52:05 -05:00
}
impl Portal {
pub fn location(&self) -> (usize, usize) {
(self.x, self.y)
}
2026-07-25 12:48:11 -05:00
}