let _: Void = match (self.opname.as_str(), self.wrc) {
("flip", wrc@ WRC::UpdateSvg) => {
- let nfaces = ipc.p.nfaces(y);
+ let nfaces = ipc.show(y).nfaces();
let logents = log_did_to_piece(
ioccults, &gs.occults, player, gpl, piece, gpc, ipc,
"flipped"
};
}
- ipc.p.ui_operation(a, &self.opname, self.wrc, y)?
+ ipc.show(y).ui_operation(a, &self.opname, self.wrc)?
}
}
}
let &GPiece { pos, face, .. } = gpc;
if let Some(ipc) = ig.ipieces.get(piece);
let unocc = gpc.fully_visible_to_everyone();
- let visible = if let Some(_) = unocc {
+ let visible = if let Some(y) = unocc {
// todo: something more sophisticated would be nice
let pri = PieceRenderInstructions::new_visible(
// visible id is internal one here
VisiblePieceId(piece.data())
);
- let bbox = ipc.p.bbox_approx()?;
+ let bbox = ipc.show(y).bbox_approx()?;
let desc_html = pri.describe(ioccults, gpc, ipc);
Some(MgmtGamePieceVisibleInfo {
pos, face, desc_html, bbox
None
};
let itemname = if let Some(unocc) = unocc {
- ipc.p.itemname(unocc).to_string()
+ ipc.show(unocc).itemname().to_string()
} else {
"occulted-item".to_string()
};
piece)?
);
}
- ipc.p.delete_hook(&gpc, gs);
+ ipc.p.into_inner().delete_hook(&gpc, gs);
}
if let Some(occilk) = ipc.occilk { ig.ioccults.ilks.dispose(occilk); }
(U{ pcs: vec![(piece, PieceUpdateOp::Delete())],
let mut updates = Vec::with_capacity(count_len);
let mut pos = pos.unwrap_or(DEFAULT_POS_START);
let mut z = gs.max_z.clone_mut();
- let not_occ = ShowUnocculted::new_visible();
for piece_i in count {
let PieceSpecLoaded { p, occultable } = info.load(piece_i as usize)?;
let ilks = &mut ig.ioccults.ilks;
ilks.insert(ilkname, OccultIlkData { p_occ })
});
let face = face.unwrap_or_default();
- if p.nfaces(not_occ) <= face.into() {
+ if p.nfaces() <= face.into() {
throw!(SpecError::FaceNotFound);
}
let gpc = GPiece {
pub type ItemForOutput = (String, ItemEnquiryData);
-const UNOCC: ShowUnocculted = ShowUnocculted::new_visible();
-
#[throws(AE)]
fn preview(items: Vec<ItemForOutput>) {
const BORDER: f64 = 1.;
self.size[0] < 20.0
}
fn face_cols(&self) -> usize {
- usize::from(self.p.nfaces(UNOCC))
+ usize::from(self.p.nfaces())
* if self.want_several() { SEVERAL } else { 1 }
}
}
let loaded = spec.clone().load().context("load")?;
let p = loaded.p; // xxx show occulted version too
let mut uos = vec![];
- p.add_ui_operations(&mut uos, &GPiece::dummy(), UNOCC)
+ p.add_ui_operations(&mut uos, &GPiece::dummy())
.context("add uos")?;
let uos = uos.into_iter().map(|uo| uo.opname).collect::<Vec<_>>();
let spec = spec.clone();
println!(r#"<th align="left"><kbd>{}</kbd></th>"#,
Html::from_txt(&spec.item).0);
println!(r#"<th align="left">{}</th>"#,
- p.describe_html(&GPiece::dummy(), UNOCC)?.0);
+ p.describe_html(&GPiece::dummy())?.0);
let only1 = s.face_cols() == 1;
for facecol in 0..(if only1 { 1 } else { max_facecols }) {
_ => panic!(),
});
println!(r#">"#);
- if face < (p.nfaces(UNOCC) as usize) {
+ if face < (p.nfaces() as usize) {
let viewport =
[bbox[0].clone(), size.clone()]
.iter().cloned()
}
let mut html = Html("".into());
let gpc = GPiece { face: face.into(), ..GPiece::dummy() };
- p.svg_piece(&mut html, &gpc, default(), UNOCC)?;
+ p.svg_piece(&mut html, &gpc, default())?;
println!("{}</svg>", html.0);
}
println!("</td>");
/// by convention, occult face is nfaces-1
// xxx this is no good, we need a central definition of the occult
// face to avoid weird behaviour with buggy gamespecs
- fn nfaces(&self, y: ShowUnocculted) -> RawFaceId;
+ fn nfaces(&self) -> RawFaceId;
#[throws(InternalError)]
fn add_ui_operations(&self, _upd: &mut Vec<UoDescription>,
- _gpc: &GPiece, _y: ShowUnocculted) { }
+ _gpc: &GPiece) { }
fn ui_operation(&self, _a: ApiPieceOpArgs<'_>,
- _opname: &str, _wrc: WhatResponseToClientOp,
- _y: ShowUnocculted)
+ _opname: &str, _wrc: WhatResponseToClientOp)
-> Result<UpdateFromOpComplex, ApiPieceOpError> {
throw!(OE::BadOperation)
}
// #[throws] doesn't work here - fehler #todo
fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
- id: VisiblePieceId, y: ShowUnocculted) -> Result<(),IE>;
+ id: VisiblePieceId) -> Result<(),IE>;
- fn describe_html(&self, gpc: &GPiece, y: ShowUnocculted) -> Result<Html,IE>;
+ fn describe_html(&self, gpc: &GPiece) -> Result<Html,IE>;
fn delete_hook(&self, _p: &GPiece, _gs: &mut GameState)
-> ExecuteGameChangeUpdates {
ExecuteGameChangeUpdates{ pcs: vec![], log: vec![], raw: None }
}
- fn itemname(&self, _y: ShowUnocculted) -> &str;
+ fn itemname(&self) -> &str;
}
#[typetag::serde]
#[typetag::serde]
impl PieceTrait for Hand {
- fn nfaces(&self, _: ShowUnocculted) -> RawFaceId { 1 }
+ fn nfaces(&self) -> RawFaceId { 1 }
#[throws(IE)]
- fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
- _vpid: VisiblePieceId, _: ShowUnocculted) {
+ fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _vpid: VisiblePieceId) {
self.shape.svg_piece_raw(f, gpc.face, &mut |f: &mut String| {
if_chain!{
if let Some(xdata) = gpc.xdata.get::<HandState>()?;
}
#[throws(IE)]
- fn describe_html(&self, gpc: &GPiece, _: ShowUnocculted) -> Html {
+ fn describe_html(&self, gpc: &GPiece) -> Html {
let xdata = gpc.xdata.get()?;
self.describe_html_inner(xdata)
}
delegate!{
to self.shape {
- fn itemname(&self, y: ShowUnocculted) -> &str;
+ fn itemname(&self) -> &str;
}
}
#[throws(InternalError)]
- fn add_ui_operations(&self, upd: &mut Vec<UoDescription>,
- gpc: &GPiece, _: ShowUnocculted) {
+ fn add_ui_operations(&self, upd: &mut Vec<UoDescription>, gpc: &GPiece) {
upd.push(if_chain! {
if let Some(xdata) = gpc.xdata.get::<HandState>()?;
if let Some(_owner) = &xdata.owner;
#[throws(ApiPieceOpError)]
fn ui_operation(&self, a: ApiPieceOpArgs<'_>,
- opname: &str, wrc: WhatResponseToClientOp,
- _: ShowUnocculted)
+ opname: &str, wrc: WhatResponseToClientOp)
-> UpdateFromOpComplex {
let ApiPieceOpArgs { gs,player,piece,ipieces,ioccults,to_permute,.. } = a;
let gen = &mut gs.gen;
#[derive(Debug,Serialize,Deserialize)]
#[serde(transparent)]
pub struct IPieceTraitObj(Box<dyn PieceTrait>);
-deref_to_field!{IPieceTraitObj, Box<dyn PieceTrait>, 0} // xxx
#[derive(Clone,Debug,Default,Serialize,Deserialize)]
pub struct GameOccults {
pub fn show(&self, _: ShowUnocculted) -> &Box<dyn PieceTrait> {
&self.0
}
+
+ pub fn into_inner(self) -> Box<dyn PieceTrait> { self.0 }
}
impl GPiece {
let ogpc = gpieces.get(opiece).ok_or_else(bad)?;
let ounocc = ogpc.fully_visible_to_everyone()
.ok_or_else(||internal_error_bydebug(&(occulteds, &ogpc)))?;
- Ok::<_,IE>(oipc.show(ounocc).describe_html(ogpc, ounocc)?)
+ Ok::<_,IE>(oipc.show(ounocc).describe_html(ogpc)?)
};
let most_obscure = most_obscure.unwrap_or(&OccK::Visible); // no players!
pub fn describe_fallible(&self, ioccults: &IOccults,
gpc: &GPiece, ipc: &IPiece) -> Html {
match self.instead(ioccults, ipc)? {
- Left(y) => ipc.show(y).describe_html(gpc, y)?,
+ Left(y) => ipc.show(y).describe_html(gpc)?,
Right(i) => i.describe_html()?,
}
}
match instead {
Left(y) => {
- ipc.p.svg_piece(&mut defs, gpc, pri.vpid, y)?;
+ ipc.show(y).svg_piece(&mut defs, gpc, pri.vpid)?;
},
Right(i) => {
i.svg(&mut defs, pri.vpid)?;
type WRC = WhatResponseToClientOp;
let mut out = vec![];
- if ipc.p.nfaces(y) > 1 {
+ if ipc.show(y).nfaces() > 1 {
out.push(UoDescription {
wrc: WRC::UpdateSvg,
kind: UoKind::Global,
desc: Html::lit("flip"),
})
}
- ipc.p.add_ui_operations(&mut out, gpc, y)?;
+ ipc.show(y).add_ui_operations(&mut out, gpc)?;
out
}
}
#[typetag::serde]
impl PieceTrait for SimpleShape {
#[throws(IE)]
- fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
- _vpid: VisiblePieceId, _: ShowUnocculted) {
+ fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _vpid: VisiblePieceId) {
self.svg_piece_raw(f, gpc.face, &mut |_|Ok(()))?;
}
#[throws(IE)]
- fn describe_html(&self, gpc: &GPiece, _: ShowUnocculted) -> Html {
+ fn describe_html(&self, gpc: &GPiece) -> Html {
Html(if_chain! {
if let face = gpc.face;
if let Some(colour) = self.colours.get(face);
else { format!("a {}", self.desc.0) }
})
}
- fn nfaces(&self, _: ShowUnocculted) -> RawFaceId {
+ fn nfaces(&self) -> RawFaceId {
self.count_faces().try_into().unwrap()
}
- fn itemname(&self, y: ShowUnocculted) -> &str { self.itemname(y) }
+ fn itemname(&self) -> &str { self.itemname() }
}
impl<Desc, Outl:'static> GenericSimpleShape<Desc, Outl>
pub fn count_faces(&self) -> usize {
max(self.colours.len(), self.edges.len())
}
- pub fn itemname(&self, _: ShowUnocculted) -> &str { &self.itemname }
+ pub fn itemname(&self) -> &str { &self.itemname }
#[throws(SpecError)]
pub fn new(desc: Desc, outline: Outl,
#[typetag::serde(name="Lib")]
impl PieceTrait for Item {
- fn nfaces(&self, _: ShowUnocculted) -> RawFaceId {
+ fn nfaces(&self) -> RawFaceId {
self.faces.len().try_into().unwrap()
}
#[throws(IE)]
- fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
- _vpid: VisiblePieceId, _: ShowUnocculted) {
+ fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _vpid: VisiblePieceId) {
let face = &self.faces[gpc.face];
let svgd = &self.svgs[face.svg];
face.xform.write_svgd(f, svgd)?;
}
#[throws(IE)]
- fn describe_html(&self, gpc: &GPiece, _: ShowUnocculted) -> Html {
+ fn describe_html(&self, gpc: &GPiece) -> Html {
self.descs[ self.faces[gpc.face].desc ].clone()
}
- fn itemname(&self, _: ShowUnocculted) -> &str { &self.itemname }
+ fn itemname(&self) -> &str { &self.itemname }
}
static SHAPELIBS: RwLock<Option<Registry>> = const_rwlock(None);
let pat = glob::Pattern::new(pat).map_err(|pe| ME::BadGlob {
pat: pat.to_string(), msg: pe.msg.to_string() })?;
let mut out = vec![];
- let unocc_ok = ShowUnocculted::new_visible();
for (k,v) in &self.items {
if !pat.matches(&k) { continue }
let loaded = match self.load1(v, &k) {
let ier = ItemEnquiryData {
itemname: k.clone(),
f0bbox,
- f0desc: loaded.p.describe_html(&GPiece::dummy(), unocc_ok)?,
+ f0desc: loaded.p.describe_html(&GPiece::dummy())?,
};
out.push(ier);
}