pub fn into_inner(self) -> Box<dyn PieceTrait> { self.0 }
}
+impl IPiece {
+ #[throws(IE)]
+ pub fn show_or_instead<'p>(&self, ioccults: &'p IOccults,
+ y: Option<ShowUnocculted>)
+ -> Either<ShowUnocculted, &'p dyn OccultedPieceTrait> {
+ match y {
+ Some(y) => Left(y),
+ None => Right({
+ let occilk = self.occilk.as_ref()
+ .ok_or_else(|| internal_logic_error(format!(
+ "occulted non-occultable {:?}", self)))?
+ .borrow();
+ let occ_data = ioccults.ilks.get(occilk)
+ .ok_or_else(|| internal_logic_error(format!(
+ "occulted ilk vanished {:?} {:?}", self, occilk)))?;
+ occ_data.p_occ.as_ref()
+ }),
+ }
+ }
+}
+
impl GPiece {
pub fn fully_visible_to_everyone(&self) -> Option<ShowUnocculted> {
match self.occult.passive {
impl<P,Z> PriOccultedGeneral<P,Z> {
#[throws(IE)]
- fn instead<'p>(&self, ioccults: &'p IOccults, p: &'p IPiece)
+ pub fn instead<'p>(&self, ioccults: &'p IOccults, p: &'p IPiece)
-> Either<ShowUnocculted, &'p dyn OccultedPieceTrait>
{
+ p.show_or_instead(ioccults, self.fully_visible())?
+ }
+
+ pub fn fully_visible(&self) -> Option<ShowUnocculted> {
use PriOG::*;
match self {
- Visible(v) => Left(*v),
- Occulted | Displaced(..) => {
- Right({
- let occilk = p.occilk.as_ref()
- .ok_or_else(|| internal_logic_error(format!(
- "occulted non-occultable {:?}", p)))?
- .borrow();
- let occ_data = ioccults.ilks.get(occilk)
- .ok_or_else(|| internal_logic_error(format!(
- "occulted ilk vanished {:?} {:?}", p, occilk)))?;
- occ_data.p_occ.as_ref()
- })
- },
+ Visible(v) => Some(*v),
+ Occulted | Displaced(..) => None,
}
}