#[cfg(feature = "macros")]
mod macros_enabled {
#[allow(unused)] use crate::{
Action, View,
core::{GameContext, GameTags, PageState, Response},
elements,
elements::ChoiceVariant,
run::Simulation,
view::{Line, Object, RenderData, Span},
};
#[macro_export]
macro_rules! s {
($e:expr) => {
$crate::view::Span::from($e)
};
($($e:expr),+ $(,)?) => {
$crate::view::Span::from(
[ $( $e.to_string() ),+ ].join("")
)
};
}
#[macro_export]
macro_rules! l {
( $( $e:expr ),+ $(,)? ) => {
$crate::view::Line::from_spans(vec![$($crate::view::Span::from($e)),+])
};
}
#[macro_export]
macro_rules! link {
($e:expr, $f:path) => {
$crate::view::Span::from($e)
.as_link()
.with_action($crate::Action::Next($crate::core::PageHandle::new(
stringify!($f).into(),
$f,
)))
};
($e:expr) => {
$crate::view::Span::from($e).as_link()
};
}
#[macro_export]
macro_rules! tun {
($e:expr, $f:path) => {
$crate::view::Span::from($e)
.as_link()
.with_action($crate::Action::Tunnel($crate::core::PageHandle::new(
stringify!($f).into(),
$f,
)))
};
($e:expr) => {
$crate::view::Span::from($e)
.as_link()
.with_action($crate::Action::Exit)
};
}
#[macro_export]
macro_rules! LINK {
($f:path) => {
return $crate::core::Response::Switch($crate::core::PageHandle::new(
stringify!($f).into(),
$f,
));
};
}
#[macro_export]
macro_rules! BACK {
($n:expr) => {
return $crate::core::Response::Back($n);
};
() => {
return $crate::core::Response::Back(1);
};
}
#[macro_export]
macro_rules! TUN {
($f:path) => {
return $crate::core::Response::EnterTunnel($crate::core::PageHandle::new(
stringify!($f).into(),
$f,
));
};
() => {
return $crate::core::Response::Exit
};
}
#[macro_export]
macro_rules! END {
() => {
return $crate::core::Response::End;
};
}
pub use ifengine_macros::dparagraph as dp;
pub use ifengine_macros::mchoice as choices;
pub use ifengine_macros::mparagraph as mp;
pub use ifengine_macros::paragraph as p;
pub use ifengine_macros::paragraphs as ps;
pub use ifengine_macros::text;
pub use ifengine_macros::texts as ts;
pub use ifengine_macros::*;
}
use crate::view::Line;
#[cfg(feature = "macros")]
pub use macros_enabled::*;
#[derive(Debug)]
pub enum ChoiceVariant {
Once(Line),
Hidden,
Always(Line),
}
impl<T: Into<Line>> From<T> for ChoiceVariant {
fn from(value: T) -> Self {
ChoiceVariant::Once(value.into())
}
}
impl<T: Into<Line>> From<Option<T>> for ChoiceVariant {
fn from(value: Option<T>) -> Self {
if let Some(value) = value {
ChoiceVariant::Always(value.into())
} else {
ChoiceVariant::Hidden
}
}
}
impl ChoiceVariant {
pub fn as_line(self, seen: bool) -> Option<Line> {
match self {
ChoiceVariant::Hidden => None,
ChoiceVariant::Once(l) => {
if seen {
None
} else {
Some(l)
}
}
ChoiceVariant::Always(l) => Some(l),
}
}
}