|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
* See [its documentation](AnyTile) for more information on the discovery process.
|
|
|
|
|
*/
|
|
|
|
|
use super::*;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use enum_dispatch::enum_dispatch;
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
@ -184,6 +185,42 @@ pub trait Tile: std::clone::Clone + std::fmt::Debug + Serialize + for<'d> Deseri
|
|
|
|
|
fn draw_simple(&self, ctx: DrawContext<'_>) -> TextChar {
|
|
|
|
|
TextChar::default()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns the "schema" of the tile, allowing editors to provide human interfaces for
|
|
|
|
|
/// modifying the tile.
|
|
|
|
|
fn schema(&self) -> TileSchema {
|
|
|
|
|
TileSchema::tuple()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The description of the fields of a [`Tile`]
|
|
|
|
|
pub enum TileSchema {
|
|
|
|
|
Tuple(Vec<TileSchema>),
|
|
|
|
|
Map(HashMap<String, TileSchema>),
|
|
|
|
|
Value(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TileSchema {
|
|
|
|
|
pub fn tuple() -> Self {
|
|
|
|
|
Self::Tuple(Vec::new())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn map() -> Self {
|
|
|
|
|
Self::Map(HashMap::new())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn value<S: ToString>(name: S) -> Self {
|
|
|
|
|
Self::Value(name.to_string())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn add<S: ToString>(mut self, name: S, value: TileSchema) -> Self {
|
|
|
|
|
match self {
|
|
|
|
|
Self::Map(ref mut map) => map.insert(name.to_string(), value),
|
|
|
|
|
_ => panic!("Invalid TileSchema builder: cannot add() to a non-Map"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub mod prelude {
|
|
|
|
@ -192,6 +229,7 @@ pub mod prelude {
|
|
|
|
|
pub use crate::text::*;
|
|
|
|
|
pub use crate::tile::{AnyTile, FullTile};
|
|
|
|
|
pub use crate::utils::State;
|
|
|
|
|
pub use super::TileSchema;
|
|
|
|
|
|
|
|
|
|
pub use serde::{Deserialize, Serialize};
|
|
|
|
|
}
|
|
|
|
|